6 #define FAT_DIR_ENTRY_SIZE 32
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 \
23 #define FAT_ATTR_VALID (FAT_ATTR_READ_ONLY \
26 | FAT_ATTR_DIRECTORY \
29 enum fat_type
{ FAT12
, FAT16
, FAT32
};
32 * The fat file system structures
39 uint8_t bxSecPerClust
;
40 uint16_t bxResSectors
;
42 uint16_t bxRootDirEnts
;
46 uint16_t sectors_per_track
;
48 uint32_t num_hidden_sectors
;
49 uint32_t bsHugeSectors
;
59 } __attribute__ ((packed
)) fat12_16
;
62 uint32_t bxFATsecs_32
;
63 uint16_t extended_flags
;
65 uint32_t root_cluster
;
67 uint16_t backup_boot_sector
;
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
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 */
101 } __attribute__ ((packed
));
103 struct fat_dir_entry
{
107 uint8_t c_time_tenth
;
111 uint16_t first_cluster_high
;
114 uint16_t first_cluster_low
;
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
{
128 uint16_t first_cluster
;
130 } __attribute__ ((packed
));
132 static inline struct fat_sb_info
*FAT_SB(struct fs_info
*fs
)
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 */