和磁盘相处,经常遇到以下结构体,记录一下;
以下结构体源自linux-5.1内核:
1. 引导扇区 struct fat_boot_sector
struct fat_boot_sector {
__u8 ignored[3]; /* Boot strap short or near jump 引导程序短跳或近跳 */
__u8 system_id[8]; /* Name - can be used to special case partition manager volumes 名称——可以用于特殊情况下分区管理器的卷*/
__u8 sector_size[2]; /* bytes per logical sector 每个逻辑扇区字节数 */
__u8 sec_per_clus; /* sectors/cluster 扇区/簇 */
__le16 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 媒体码 */
__le16 fat_length; /* sectors/FAT 扇区/分配表 长度*/
__le16 secs_track; /* sectors per track 每磁轨扇区数 */
__le16 heads; /* number of heads 头数量 */
__le32 hidden; /* hidden sectors (unused) 隐藏扇区 */
__le32 total_sect; /* number of sectors (if sectors == 0) 总扇区数量 */
union {
struct {
/* Extended BPB Fields for FAT16 为FAT16扩展了BPB字段 */
__u8 drive_number; /* Physical drive number 物理驱动编号*/
__u8 state; /* undocumented, but used for mount state. 没有记录,但用于(嵌入式)*/
__u8 signature; /* extended boot signature 延长启动签名*/
__u8 vol_id[4]; /* volume ID 卷ID*/
__u8 vol_label[MSDOS_NAME]; /* volume label 卷表*/
__u8 fs_type[8]; /* file system type 文件系统类型*/
/* other fields are not added here */
} fat16;
struct {
/* only used by FAT32 仅仅用于FAT32 */
__le32 length; /* sectors/FAT 扇区/簇 长度 */
__le16 flags; /* bit 8: fat mirroring, 簇镜像
low 4: active fat 活跃簇 */
__u8 version[2]; /* major, minor filesystem version version[0]:主 version[1]:次文件系统版本 */
__le32 root_cluster; /* first cluster in root directory 在根目录第一个簇 */
__le16 info_sector; /* filesystem info sector 文件系统信息扇区 */
__le16 backup_boot; /* backup boot sector 备份引导扇区 */
__le16 reserved2[6]; /* Unused */
/* Extended BPB Fields for FAT32 为FAT32扩展了BPB字段*/
__u8 drive_number; /* Physical drive number */
__u8 state; /* undocumented, but used for mount state. */
__u8 signature; /* extended boot signature */
__u8 vol_id[4]; /* volume ID */
__u8 vol_label[MSDOS_NAME]; /* volume label */
__u8 fs_type[8]; /* file system type */
/* other fields are not added here */
} fat32;
};
};
2.引导文件信息 struct fat_boot_fsinfo
struct fat_boot_fsinfo {
__le32 signature1; /* 0x41615252L signature:署名,签名,信号*/
__le32 reserved1[120]; /* Nothing as far as I can tell 据我所知没有 */
__le32 signature2; /* 0x61417272L */
__le32 free_clusters; /* Free cluster count. -1 if unknown 空闲簇数量 */
__le32 next_cluster; /* Most recently allocated cluster 最近分配的簇 */
__le32 reserved2[4];
};
3.文件管理模块目录条目 struct msdos_dir_entry
struct msdos_dir_entry {
__u8 name[MSDOS_NAME];/* name and extension 名称和扩展 */
__u8 attr; /* attribute bits 属性位 */
__u8 lcase; /* Case for base and extension 基础和扩展的案例 */
__u8 ctime_cs; /* Creation time, centiseconds (0-199) 创建时间、厘秒 */
__le16 ctime; /* Creation time 创建时间 */
__le16 cdate; /* Creation date 创建日期 */
__le16 adate; /* Last access date 最后访问日期 */
__le16 starthi; /* High 16 bits of cluster in FAT32 FAT32簇高16位*/
__le16 time,date,start;/* time, date and first cluster 时间、日期和第一个扇区*/
__le32 size; /* file size (in bytes) 文件大小 */
};
4. 文件管理模块目录槽
/* Up to 13 characters of the name 名称长度不超过13个字符 */
struct msdos_dir_slot {
__u8 id; /* sequence number for slot 槽序列号 */
__u8 name0_4[10]; /* first 5 characters in name 名称的前5个字符 */
__u8 attr; /* attribute byte 属性类型 */
__u8 reserved; /* always 0 */
__u8 alias_checksum; /* checksum for 8.3 alias 8.3别名校验和 */
__u8 name5_10[12]; /* 6 more characters in name 姓名中多6个字符 */
__le16 start; /* starting cluster number, 0 in long slots 起始簇编号,长槽为0*/
__u8 name11_12[4]; /* last 2 characters in name 名称的最后2个字符 */
};