Course list: http://www.c-jump.com/bcc/

The FAT File System


  1. FAT Overview
  2. FAT Example
  3. Boot Sector, FAT, Root Directory, and Files
  4. FAT File System Layout
  5. FAT12 FAT16 FAT32 Layouts Compared
  6. FAT Clusters and Sectors
  7. FAT, Slack, and Unallocated Space
  8. Where is the First FAT Cluster?
  9. Boot Sector
  10. FAT Boot Sector, bytes 0-35 (FAT12/16 and FAT32)
  11. FAT Boot Sector (FAT12/16)
  12. FAT12 Boot Sector
  13. Boot Sector Interpretation
  14. Capacity of this Medium
  15. Sector Assignments
  16. Root Directory
  17. Root Directory Entries
  18. Root Directory Entry Format (SFN)
  19. Root Directory Example
  20. Sample Root Directory Entry
  21. Another Sample Root Directory Entry
  22. FATs Compared
  23. FAT12 File Allocation Table
  24. Interpreting FAT12
  25. FAT12 Contents
  26. Formatting a Floppy
  27. Formatted Floppy Data Structures
  28. Allocating A New File
  29. Deleting A File
  30. For More Information...

1. FAT Overview



2. FAT Example



3. Boot Sector, FAT, Root Directory, and Files


  • File tyui.jpg:

    • occupies clusters 2, 3, and 4.

    • The file size is 1,400 bytes, it occupies 1,536 bytes (3 clusters) on the disk, and cluster 4 includes 136 bytes of slack space.

  • File mes.doc:

    • occupies clusters 5 and 6.

    • The file size is 980 bytes, it occupies 1,024 bytes (2 clusters), and has 44 bytes of slack space in cluster 6.

  • Clusters 7, 8, and 9 are unallocated.

  •   Boot Sector, FAT, Root Directory, and Files


4. FAT File System Layout



5. FAT12 FAT16 FAT32 Layouts Compared



6. FAT Clusters and Sectors



7. FAT, Slack, and Unallocated Space


  • Clusters 3, 6, and 8 are allocated; clusters 2, 4, 5, 7, and 9 are unallocated

  • Clusters 6 and 8 are only partially filled; the unused portion is slack space

  • File gary.txt:

    • logical size is 1,034 bytes

    • physical size is 2,048 bytes (slack = 1,014 B)

  • File hello.jpg:

    • logical size is 3,973 bytes

    • physical size is 4,096 bytes (slack = 123 B)

    FAT, Slack, and Unallocated Space

8. Where is the First FAT Cluster?


  • The first cluster is Cluster 2

  • Actual location of cluster 2 is different in FAT12/16 and FAT32

  • Assume cluster size = 2,048 B (4 sectors)

  • Assume that data area starts at sector 1224

  • First sectors of data area are reserved for the Root Directory

    • Size is established at boot time

  • Cluster 2 starts after Root Directory

  • Root directory is set at 32 sectors

    • Occupies sectors 1,224-1,255

  • FAT12/16 Cluster Example:

      FAT12/16 Cluster Example

  • Cluster 2 starts at sector 1,256

  • Cluster 3 starts at sector 1,260

  • Cluster 4 at 1,264...


9. Boot Sector



10. FAT Boot Sector, bytes 0-35 (FAT12/16 and FAT32)



11. FAT Boot Sector (FAT12/16)



12. FAT12 Boot Sector



13. Boot Sector Interpretation



14. Capacity of this Medium



15. Sector Assignments



16. Root Directory



17. Root Directory Entries



18. Root Directory Entry Format (SFN)



19. Root Directory Example



20. Sample Root Directory Entry



21. Another Sample Root Directory Entry



22. FATs Compared



23. FAT12 File Allocation Table


  • FAT table entries are packed so that two cluster entries occupy three bytes with the following general format:

        yz Zx XY
    

    where

    • xyz is the one pointer entry and

    • XYZ is the second pointer entry.

  • E.g., bytes 242-244:

        2d e0 02
    

    refer to clusters 0x02d (45) and 0x02e (46)

  • Primary FAT starts at sector 1, byte 0x200 (shown here)

  • The starting cluster in the directory is also a pointer into the FATs linking to the next cluster in the file

  • Primary FAT sector 1:

      FAT12 Primary FAT sector 1


24. Interpreting FAT12



25. FAT12 Contents



26. Formatting a Floppy



27. Formatted Floppy Data Structures


  • Floppy Data Structures before formatting, uninitialized:

      Floppy Data Structures before formatting

  • Floppy Data Structures after formatting, initialized root directory:

      Floppy Data Structures after formatting


28. Allocating A New File


  1. Find first free entry in directory and write file name

  2. Search FAT for unallocated cluster; set to EOF (0xFFF)

  3. Write that cluster's address into directory entry

  4. If another cluster is needed,

    (Repeat this step as necessary.)

     


29. Deleting A File


  1. Find directory entry for file to delete

  2. Using starting cluster value in the root directory, set all FAT entries in file's cluster chain to zero

  3. Deallocate directory entry by overwriting first byte of the entry with 0xE5 (å)

     


30. For More Information...