File FAT12文件数据区域偏移量

File FAT12文件数据区域偏移量,file,filesystems,fat,File,Filesystems,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 在文件系统的概览中,数据区域位于:ReservedSectors+(NumberOfF

我用以下内容创建了一个胖图像:

[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
在文件系统的概览中,数据区域位于:ReservedSectors+(NumberOfFats*SectorsPerFAT)+(NumberOfRootEntries*32)/BytesPerSector)

软盘.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
在根目录表中,我搜索hello.txt文件,并返回第一个集群位于0x03:

现在我计算前面的公式,并给出以下扇区偏移量:

1 + (2 * 9) + ((224 * 32) / 512) = 33
字节数应为33*512=16896。这应该是数据区域的开始。要定位hello.txt文件的数据,我应该添加Cluster*SectorsPerCluster=6的偏移量

该文件的数据应位于扇区39或距起始位置19968字节处。但当我用hextump检查该扇区时,什么也没有返回:

[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处


我遗漏了什么?

数据部分的偏移量是正确的:ReservedSectors+(NumberOfFats*SectorsPerFAT)+(NumberOfRootEntries*32)/BytesPerSector)

数据段中文件集群的偏移量应为:DataSectionOffset+((集群-2)*SectorsPerCluster)。使用这个新公式,现在文件hello.txt的数据为33+((3-2)*2)=35

偏移量为17920的字节数:

[user@localhost]$ hexdump -C -s 17920 floppy.img
00004600  48 65 6c 6c 6f 2c 20 57  6f 72 6c 64 21 0a 00 00  |Hello, World!...|
[user@localhost]$ hexdump -C -s 17920 floppy.img
00004600  48 65 6c 6c 6f 2c 20 57  6f 72 6c 64 21 0a 00 00  |Hello, World!...|