Adding upstream version 4.01+dfsg.
[syslinux-debian/hramrach.git] / core / fs / fat / fat_fs.h
blob7ea3db85c271e0740b6b5613d3a484ae71b17eb7
1 #ifndef FAT_FS_H
2 #define FAT_FS_H
4 #include <stdint.h>
6 #define FAT_DIR_ENTRY_SIZE 32
7 #define DIRENT_SHIFT 5
9 #define FAT_ATTR_READ_ONLY 0x01
10 #define FAT_ATTR_HIDDEN 0x02
11 #define FAT_ATTR_SYSTEM 0x04
12 #define FAT_ATTR_VOLUME_ID 0x08
13 #define FAT_ATTR_DIRECTORY 0x10
14 #define FAT_ATTR_ARCHIVE 0x20
16 #define FAT_MAXFILE 256
18 #define FAT_ATTR_LONG_NAME (FAT_ATTR_READ_ONLY \
19 | FAT_ATTR_HIDDEN \
20 | FAT_ATTR_SYSTEM \
21 | FAT_ATTR_VOLUME_ID)
23 #define FAT_ATTR_VALID (FAT_ATTR_READ_ONLY \
24 | FAT_ATTR_HIDDEN \
25 | FAT_ATTR_SYSTEM \
26 | FAT_ATTR_DIRECTORY \
27 | FAT_ATTR_ARCHIVE)
29 enum fat_type{ FAT12, FAT16, FAT32 };
32 * The fat file system structures
35 struct fat_bpb {
36 uint8_t jmp_boot[3];
37 uint8_t oem_name[8];
38 uint16_t sector_size;
39 uint8_t bxSecPerClust;
40 uint16_t bxResSectors;
41 uint8_t bxFATs;
42 uint16_t bxRootDirEnts;
43 uint16_t bxSectors;
44 uint8_t media;
45 uint16_t bxFATsecs;
46 uint16_t sectors_per_track;
47 uint16_t num_heads;
48 uint32_t num_hidden_sectors;
49 uint32_t bsHugeSectors;
51 union {
52 struct {
53 uint8_t num_ph_drive;
54 uint8_t reserved;
55 uint8_t boot_sig;
56 uint32_t num_serial;
57 uint8_t label[11];
58 uint8_t fstype[8];
59 } __attribute__ ((packed)) fat12_16;
61 struct {
62 uint32_t bxFATsecs_32;
63 uint16_t extended_flags;
64 uint16_t fs_version;
65 uint32_t root_cluster;
66 uint16_t fs_info;
67 uint16_t backup_boot_sector;
68 uint8_t reserved[12];
69 uint8_t num_ph_drive;
70 uint8_t reserved1;
71 uint8_t boot_sig;
72 uint32_t num_serial;
73 uint8_t label[11];
74 uint8_t fstype[8];
75 } __attribute__ ((packed)) fat32;
77 } __attribute__ ((packed));
79 uint8_t pad[422]; /* padding to 512 Bytes (one sector) */
81 } __attribute__ ((packed));
84 * The fat file system info in memory
86 struct fat_sb_info {
87 sector_t fat; /* The FAT region */
88 sector_t root; /* The root dir region */
89 sector_t data; /* The data region */
91 uint32_t clusters; /* Total number of clusters */
92 uint32_t root_cluster; /* Cluster number for (FAT32) root dir */
93 int root_size; /* The root dir size in sectors */
95 int clust_shift; /* based on sectors */
96 int clust_byte_shift; /* based on bytes */
97 int clust_mask; /* sectors per cluster mask */
98 int clust_size;
100 int fat_type;
101 } __attribute__ ((packed));
103 struct fat_dir_entry {
104 char name[11];
105 uint8_t attr;
106 uint8_t lcase;
107 uint8_t c_time_tenth;
108 uint16_t c_time;
109 uint16_t c_date;
110 uint16_t a_date;
111 uint16_t first_cluster_high;
112 uint16_t w_time;
113 uint16_t w_date;
114 uint16_t first_cluster_low;
115 uint32_t file_size;
116 } __attribute__ ((packed));
118 #define LCASE_BASE 8 /* basename is lower case */
119 #define LCASE_EXT 16 /* extension is lower case */
121 struct fat_long_name_entry {
122 uint8_t id;
123 uint16_t name1[5];
124 uint8_t attr;
125 uint8_t reserved;
126 uint8_t checksum;
127 uint16_t name2[6];
128 uint16_t first_cluster;
129 uint16_t name3[2];
130 } __attribute__ ((packed));
132 static inline struct fat_sb_info *FAT_SB(struct fs_info *fs)
134 return fs->fs_info;
138 * Count the root dir size in sectors
140 static inline int root_dir_size(struct fs_info *fs, struct fat_bpb *fat)
142 return (fat->bxRootDirEnts + SECTOR_SIZE(fs)/32 - 1)
143 >> (SECTOR_SHIFT(fs) - 5);
147 * FAT private inode information
149 struct fat_pvt_inode {
150 uint32_t start_cluster; /* Starting cluster address */
151 sector_t start; /* Starting sector */
152 sector_t offset; /* Current sector offset */
153 sector_t here; /* Sector corresponding to offset */
156 #define PVT(i) ((struct fat_pvt_inode *)((i)->pvt))
158 #endif /* fat_fs.h */