【问题标题】:FAT12 file data region offsetFAT12 文件数据区域偏移量
【发布时间】: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


    【解决方案1】:

    数据段的偏移量正确:ReservedSectors + (NumerOfFATs * 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!...|
    

    【讨论】:

      猜你喜欢
      • 2011-08-04
      • 2010-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-02
      • 2015-10-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多