FAT16 文件系统

发 布 时 间 : 2008-11-17 来 源 : 未知 作 者 : 匿名 浏 览 :

 

 

The boot sector

A boot sector can be found in the first sector of every logical disk. On a floppy disk, the logical disk takes up all of the physical disk and the boot sector lives in the first physical sector. On a hard disk, a boot sector lives at the start of each partition.

An example boot sec

0000 EB 3E 90 4D 53 57 49 4E-34 2E 30 00 02 20 01 00 .>.MSWIN4.0.. ..
0010 02 40 03 00 00 F8 FF 00-3F 00 40 00 3F 00 00 00 .@......?.@.?...
0020 41 DE 1F 00 80 00 29 37-4B 84 32 46 55 4A 49 54 A…..)7K.2FUJIT
0030 53 55 31 32 32 34 46 41-54 31 36 20 20 20 F1 7D SU1224FAT16 .}
0040 FA 33 C9 8E D1 BC FC 7B-16 07 BD 78 00 C5 76 00 .3…..{…x..v.
0050 1E 56 16 55 BF 22 05 89-7E 00 89 4E 02 B1 0B FC .V.U."..~..N….
0060 F3 A4 06 1F BD 00 7C C6-45 FE 0F 8B 46 18 88 45 ……|.E…F..E
0070 F9 FB 38 66 24 7C 04 CD-13 72 3C 8A 46 10 98 F7 ..8f$|…r<.F…
0080 66 16 03 46 1C 13 56 1E-03 46 0E 13 D1 50 52 89 f..F..V..F…PR.
0090 46 FC 89 56 FE B8 20 00-8B 76 11 F7 E6 8B 5E 0B F..V.. ..v….^.
00A0 03 C3 48 F7 F3 01 46 FC-11 4E FE 5A 58 BB 00 07 ..H…F..N.ZX…
00B0 8B FB B1 01 E8 94 00 72-47 38 2D 74 19 B1 0B 56 …….rG8-t…V
00C0 8B 76 3E F3 A6 5E 74 4A-4E 74 0B 03 F9 83 C7 15 .v>..^tJNt……
00D0 3B FB 72 E5 EB D7 2B C9-B8 D8 7D 87 46 3E 3C D8 ;.r… …}.F><.
00E0 75 99 BE 80 7D AC 98 03-F0 AC 84 C0 74 17 3C FF u…}…….t.<.
00F0 74 09 B4 0E BB 07 00 CD-10 EB EE BE 83 7D EB E5 t…………}..
0100 BE 81 7D EB E0 33 C0 CD-16 5E 1F 8F 04 8F 44 02 ..}..3…^….D.
0110 CD 19 BE 82 7D 8B 7D 0F-83 FF 02 72 C8 8B C7 48 ….}.}….r…H
0120 48 8A 4E 0D F7 E1 03 46-FC 13 56 FE BB 00 07 53 H.N….F..V….S
0130 B1 04 E8 16 00 5B 72 C8-81 3F 4D 5A 75 A7 81 BF …..[r..?Mzu…
0140 00 02 42 4A 75 9F EA 00-02 70 00 50 52 51 91 92 ..Bju….p.PRQ..
0150 33 D2 F7 76 18 91 F7 76-18 42 87 CA F7 76 1A 8A 3..v…v.B…v..
0160 F2 8A 56 24 8A E8 D0 CC-D0 CC 0A CC B8 01 02 CD ..V$............
0170 13 59 5A 58 72 09 40 75-01 42 03 5E 0B E2 CC C3 .YZXr.@u.B.^….
0180 03 18 01 27 0D 0A 49 6E-76 61 6C 69 64 20 73 79 …'..Invalid sy
0190 73 74 65 6D 20 64 69 73-6B FF 0D 0A 44 69 73 6B stem disk…Disk
01A0 20 49 2F 4F 20 65 72 72-6F 72 FF 0D 0A 52 65 70 I/O error…Rep
01B0 6C 61 63 65 20 74 68 65-20 64 69 73 6B 2C 20 61 lace the disk, a
01C0 6E 64 20 74 68 65 6E 20-70 72 65 73 73 20 61 6E nd then press an
01D0 79 20 6B 65 79 0D 0A 00-49 4F 20 20 20 20 20 20 y key…IO
01E0 53 59 53 4D 53 44 4F 53-20 20 20 53 59 53 80 01 SYSMSDOS SYS..
01F0 00 57 49 4E 42 4F 4F 54-20 53 59 53 00 00 55 AA .WINBOOT SYS..U.

Structure of the boot sector

offset size meaning
00 3 jumpinstruction
03 8 system name
0b 33 BIOS parameter block
3e c0 bootstrap code
fe 2 sector signature

Structure of the BIOS paramter block (BPB)

offset length meaning
00 0x2 logical bytes per sector
02 0x1 sectors per cluster
03 0x2 number of reserved sectors starting from 0
05 0x1 number of FATs
06 0x2 number of root dir entries
08 0x2 total sectors. 0 if ofs 15h used
0a 0x1 media descriptor
0b 0x2 number of sectors per FAT
0d 0x2 number of logical sectors per track
0f 0x2 number of logical heads
11 0x4 number of hidden sectors
15 0x4 total sectors
19 0x1 physical drive number
1a 0x1 reserved
1b 0x1 signature byte for extended boot record
1c 0x4 serial number
20 0xb label
2b 0x8 FAT type

Values for the example boot sector

offset length meaning
00 0x2 logical bytes per sector
02 0x1 sectors per cluster
03 0x2 number of reserved sectors starting from 0
05 0x1 number of FATs
06 0x2 number of root dir entries
08 0x2 total sectors. 0 if ofs 15h used
0a 0x1 media descriptor
0b 0x2 number of sectors per FAT
0d 0x2 number of logical sectors per track
0f 0x2 number of logical heads
11 0x4 number of hidden sectors
15 0x4 total sectors
19 0x1 physical drive number
1a 0x1 reserved
1b 0x1 signature byte for extended boot record
1c 0x4 serial number
20 0xb label
2b 0x8 FAT type

Check the C source code to define the FAT boot sector.


Structure of a FAT disk

disk address length contents
0 1 MBR
1 PhysSectPerTrck - 1 Undefined
PhysSectPerTrck 1 Boot sector
PhysSectPerTrck 1 NumFATs*NumSectPerFAT FATs
BookKeep-SectRootDir SectRootDir Root directory
BookKeep LogcDiskSize-BookKeep Data space

SectRootDir = RootDirSize / 16
BookKeep = PhysSectPerTrck 1 NumFATs * NumSectPerFAT SectRootDir

FAT


The FAT is an array of up to 65,536 16-bit unsigned integers. The first 2 and last 16 entries in the FAT are reserved. All other elements are of type: index into the FAT array. Each of the non-reserved FAT entries correspond to a cluster on the disk.

FAT index Meaning as index Meaning as value
0x0000 reserved cluster is available
0x0001 reserved undefined
0x0002-0xffef data cluster next cluster in chain is at this index
0xfff0-0xfff6 reserved undefined
0xfff7 reserved bad cluster
0xfff8-0xffff reserved end of the current cluster chain

FAT entries 0x0000 and 0x0001 contain other information, usually 0xfff8 and 0xffff respectively.
The fragment below is from the start of a FAT
FFF8 FFFF 0000 0004 FFFF 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000
The fragment above shows a file using clusters 0x0003 & 0x0004.

Folders
A folder is a data structure stored on the disk. The root folder is stored before the data area. Other folders are stored in the data area in the same way as files; These folders may grow in size, shrink in size and be stored non-contiguously in the same way as files. The structure of all folders is as an array of folder entries. The end of the folder is marked by a folder entry starting with a 00h byte.

Folder entry structure

offset length contents
0x00 0x8 name
0x08 0x3 extension
0x0b 0x1 flags
0x0c 0xa reserved
0x16 0x2 time
0x18 0x2 date
0x1a 0x2 first cluter
0x1c 0x4 size

The date field is in DOS date format, and the time field is in DOS time.


 

 



上一篇:内存的基本知识,嵌入开发入门 下一篇:FAT16文件系统格式说明