lab9 Filesystem
  • Introduction
  • Important Commands
    • File Permissions
    • Disk Duplication
    • Create FAT Filesystems
    • Check and Repair FAT filesystem
    • Mount
    • Demo
    • Viewing with Hex Editor
      • Endian-ness in FAT32
  • Linux File System Calls
  • Directory Related Calls in C Language
  • Overview of FAT32
  • Accessing FAT using C
    • C Header of FAT
      • Header: Boot Sector
      • Header: Dir Entry
      • Read the header
    • 8+3 File Name
    • Traversing Cluster
    • Finding Next Cluster
    • Reference
Powered by GitBook
On this page

Was this helpful?

  1. Accessing FAT using C

Finding Next Cluster

After reading the current cluster, how can we advance to the next cluster?

Answer: by checking the FAT table. With the current cluster number, we can get the next cluster in FAT, or a EOF.

How can we know the terminating condition? There are three conditions in total. If we encounter these during search, that means it reaches the end.

  1. End of File

    EOF

    (0x0ffffff8)

  2. Damaged (Bad Cluster Mark) (0x0ffffff7)

  3. Unallocated (0x0)

uint32_t next_cluster(FILE *fp, off_t fat_offset, uint32_t current_cluster) {
    uint32_t next_cluster_number = 0;
    fseek(fp, fat_offset + current_cluster * sizeof next_cluster_number,
          SEEK_SET);
    size_t ret = fread(&next_cluster_number, 1, sizeof next_cluster_number, fp);
    return next_cluster_number;
}
PreviousTraversing ClusterNextReference

Last updated 5 years ago

Was this helpful?