mkdosfs 引导扇区 结构体分析

mkdosfs 引导扇区 结构体分析

///mkdosfs
#define BOOTCODE_SIZE  448
#define BOOTCODE_FAT32_SIZE 420

/* __attribute__ ((packed)) is used on all structures to make gcc ignore any
 * alignments */

struct msdos_volume_info{
    __u8 drive_number;  /* BIOS drive number */
    __u8 RESERVED;  /* Unused */
    __u8 ext_boot_sign;  /* 0x29 if fields below exist (DOS 3.3+) */
    __u8 volume_id[4];  /* Volume ID number */
    __u8 volume_label[11]; /* Volume label */
    __u8 fs_type[8];  /* Typically FAT12 or FAT16 */
} __attribute__ ((packed));    //26bytes


struct msdos_boot_sector {
    __u8 boot_jump[3];  /* Boot strap short or near jump */              //union之前36bytes
    __u8 system_id[8];  /* Name - can be used to special case
       partition manager volumes */
    __u8 sector_size[2]; /* bytes per logical sector */
    __u8 cluster_size;  /* sectors/cluster */
    __u16 reserved;  /* reserved sectors */
    __u8 fats;   /* number of FATs */
    __u8 dir_entries[2]; /* root directory entries */
    __u8 sectors[2];  /* number of sectors */
    __u8 media;   /* media code (unused) */
    __u16 fat_length;  /* sectors/FAT */
    __u16 secs_track;  /* sectors per track */
    __u16 heads;  /* number of heads */
    __u32 hidden;  /* hidden sectors (unused) */
    __u32 total_sect;  /* number of sectors (if sectors == 0) */
    union {
 struct {
     struct msdos_volume_info vi;    //26bytes
     __u8 boot_code[BOOTCODE_SIZE];       //36 + 26 + 448 = 510
 } __attribute__ ((packed)) _oldfat;
 struct {
     __u32 fat32_length; /* sectors/FAT */          //msdos_volume_info之前28bytes
     __u16 flags; /* bit 8: fat mirroring, low 4: active fat */
     __u8 version[2]; /* major, minor filesystem version */
     __u32 root_cluster; /* first cluster in root directory */
     __u16 info_sector; /* filesystem info sector */
     __u16 backup_boot; /* backup boot sector */
     __u16 reserved2[6]; /* Unused */
     struct msdos_volume_info vi;        //26bytes
     __u8 boot_code[BOOTCODE_FAT32_SIZE];   //36 + 28 + 26 + 420 = 510
 } __attribute__ ((packed)) _fat32;
    } __attribute__ ((packed)) fstype;    //fstype分_oldfat和_fat32,旧的文件系统和新格式化的fat32
    __u16 boot_sign;                    //2bytes   //0xAA55  小端
} __attribute__ ((packed));

 

如图:

你可能感兴趣的:(linux,struct,存储,磁盘,mkdosfs)