【发布时间】:2019-01-07 14:58:23
【问题描述】:
我创建了一个 FAT 映像:
[user@localhost]$ dd if=/dev/zero of=floppy.img bs=1024 count=2880
[user@localhost]$ mkdosf -F 12 floppy.img
然后我挂载镜像并添加一个新文件:
[user@localhost]$ echo "Hello, World!" >> /mnt/hello.txt
在Wikipedia文件系统概览上,数据区域位于:ReservedSectors + (NumerOfFATs * SectorsPerFAT) + ((NumberOfRootEntries * 32) / BytesPerSector)
floppy.img的引导扇区如下:
jmp : 0xeb 0x3c
nop : 0x90
OEM : mkfs.fat
Bytes per sectors : 512
Sectors per cluster : 2
Reserved sectors : 1
FAT copies : 2
Root directory entries : 224
Small sectors : 5760
Media type : 0xf0
Sectors per FAT : 9
Sectors per track
Heads : 2
Hidden sectors : 0
Large sectors : 0
Drive number : 0
Signature : 41
Serial number : 1845425665
Volume label : NO NAME
FS type : FS type : FAT12
Executable : 0xaa55
在 Root 目录表中,我搜索 hello.txt 文件,并返回第一个集群位于 0x03:
entry 1: HELLO.TXT cluster : 0x03
现在我计算前面的公式并给出以下扇区偏移量:
1 + (2 * 9) + ((224 * 32) / 512) = 33
字节数应该是 33 * 512 = 16896。这应该是数据区域的开始。为了定位 hello.txt 文件的数据,我应该添加 Cluster * SectorsPerCluster = 6 的偏移量。
文件的数据应该位于扇区 39 或从开始处开始的 19968 字节处。但是当我用 hexdump 检查那个扇区时什么都没有返回:
[user@localhost]$ hexdump -C -s 19968 floppy.img
00004e00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
阅读 hedump,我发现 hello.txt 位于偏移 17920 字节或从开始处开始的第 35 个扇区。
我错过了什么?
【问题讨论】:
标签: file filesystems fat