FAT12文件数据区域偏移

时间:2018-07-31 09:06:49

标签: file filesystems fat

我用以下方法创建了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 +(NumerOfFAT * 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

在“根目录”表中,搜索 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  |................|

阅读该转储文件,我发现 hello.txt 从起始处的偏移量为17920字节或扇区35。

我想念什么?

1 个答案:

答案 0 :(得分:0)

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

数据节中文件群集的偏移量应为:DataSectionOffset +((cluster-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!...|