2019/11/25

mkfs.fat 4.1 -- reseved sector = 1

ref:fat filesystem
Name             Offset
---------------------------
JmpBoot       :  0
OEMName       :  3
Bytes Per Sec : 11
Sec Per Clust : 13
Reserv Sec Cnt: 14
Num FATs      : 16
所以 Reserved Sector Count 在第 14 byte:

Number of sectors in reserved area. This field must not be 0 because there is the boot sector itself contains this BPB in the reserved area. To avoid compatibility problems, it should be 1 on FAT12/16 volume. This is because some old FAT drivers ignore this field and assume that the size of reserved area is 1. On the FAT32 volume, it is typically 32. Microsoft's OS properly supports any value of 1 or larger.
fat16copy.py,開image 檔的部份:
   f = open(path, "r+b")

    self.f = f

    f.seek(0xb)
    bytes_per_sector = read_le_short(f)
    print(bytes_per_sector);
    sectors_per_cluster = read_byte(f)
    print(sectors_per_cluster);

    self.bytes_per_cluster = bytes_per_sector * sectors_per_cluster

    reserved_sectors = read_le_short(f)
    print(reserved_sectors);
    assert reserved_sectors == 1, \
        "Can only handle FAT with 1 reserved sector"

reserved_sector 是 ..0x0b+2(short)+1(byte) = 0x0e, 沒錯。

用 hd 配合mkfs.fat 看看..
~$ mkfs.fat 500M
mkfs.fat 4.1 (2017-01-24)
charles-chang@zoeymkII:~$ hd -n 16 500M 
00000000  eb 3c 90 6d 6b 66 73 2e  66 61 74 00 02 10 10 00  |.<.mkfs.fat.....|
00000010
charles-chang@zoeymkII:~$ mkfs.fat -a -R1 500M
mkfs.fat 4.1 (2017-01-24)
charles-chang@zoeymkII:~$ hd -n 16 500M 
00000000  eb 3c 90 6d 6b 66 73 2e  66 61 74 00 02 10 01 00  |.<.mkfs.fat.....|
00000010
所以mkfs.fat 4.1 版,加上參攝 -a -R1 這兩個 option:
  • -a : disable alian
  • -R1 : reserved sector = 1
可以讓 4.1 版也正確做出 reserved_sector=1 的 FAT image

用 fat16copy.py 測試 OK

沒有留言:

張貼留言