fatdetect.h 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. /* Standalone FAT boot-sector + MBR detection, independent of the read/write
  2. * fat.c. Used by the `storage` command to identify filesystems on any device. */
  3. #ifndef FATDETECT_H
  4. #define FATDETECT_H
  5. typedef enum { FAT_NONE, FAT12, FAT16, FAT32 } fat_type_t;
  6. typedef struct {
  7. fat_type_t type;
  8. unsigned int bytes_per_sector;
  9. unsigned int sectors_per_cluster;
  10. unsigned int total_sectors; /* filesystem total sectors */
  11. unsigned int cluster_count;
  12. char label[12]; /* trimmed 8.3 volume label + NUL */
  13. } fat_info_t;
  14. /* Parse a 512-byte boot sector. Returns 0 and fills info, or -1. */
  15. int fat_detect(const unsigned char *boot, fat_info_t *info);
  16. typedef struct {
  17. unsigned char index; /* 0..3 (original partition slot) */
  18. unsigned char type; /* 0 = empty */
  19. unsigned int start_lba;
  20. unsigned int sectors;
  21. int is_fat; /* 1 if type is a FAT partition type */
  22. } mbr_part_t;
  23. /* Parse an MBR (512 bytes). Returns number of non-empty partitions (0..4). */
  24. int mbr_parse(const unsigned char *mbr, mbr_part_t parts[4]);
  25. int mbr_is_fat_type(unsigned char type);
  26. #endif