5 #define max(x, y) (((x) > (y)) ? (x) : (y))
6 #define min(x, y) (((x) > (y)) ? (y) : (x))
8 #define FAT32_BOOT_SEC 0
10 #define BPB_BYTES_PER_SEC 0x0B
11 #define BPB_SEC_PER_CLUSTER 0x0D
12 #define BPB_RSVD_SEC_CNT 0x0E
13 #define BPB_FAT_NUM 0x10
14 #define BPB_HIDD_SEC 0x1C
15 #define BPB_TOTL_SEC 0x20
16 #define BPB_SEC_PER_FAT 0x24
17 #define BPB_ROOT_CLUSTER 0x2c
42 #define ATTR_READ_WRITE 0x00
43 #define ATTR_READ_ONLY 0x01
44 #define ATTR_HIDDEN 0x02
45 #define ATTR_SYSTEM 0x04
46 #define ATTR_VOLUME_ID 0x08
47 #define ATTR_DIRECTORY 0x10
48 #define ATTR_ARCHIVE 0x20
49 #define ATTR_LONG_FILE_NAME 0x0F
51 #define ATTR_LINK 0x40
52 #define ATTR_CHARACTER_DEVICE 0x80
54 #define SHORT_FIR_NAME 8
55 #define SHORT_EXT_NAME 3
56 #define MAX_SHORT_NAME 11
57 #define MAX_NAME_LEN 256
58 #define MAX_PATH_LEN 512
77 #define LONG_NAME1_LEN 5
78 #define LONG_NAME2_LEN 6
79 #define LONG_NAME3_LEN 2
80 #define LONG_NAME_LEN (LONG_NAME1_LEN + LONG_NAME2_LEN + LONG_NAME3_LEN)
81 #define LAST_LONG_ENTRY 0x40
82 #define LONG_ENTRY_SEQ 0x1f
95 short_name_entry_t
sn;
112 static inline uint32_t fat_cluster2sec(uint32_t cluster) {
119 static inline uint32_t fat_sec2cluster(uint32_t sec) {
124 return ((uint32_t)p->
sn.fst_clus_hi << 16) + p->
sn.fst_clus_lo;
127 static inline void fat32_fcluster2dentry(
dentry_t *p,
uint32 cluster) {
128 p->
sn.fst_clus_hi = (cluster >> 16) & ((1lu << 16) - 1);
129 p->
sn.fst_clus_lo = cluster & ((1lu << 16) - 1);
132 #define FAT_MASK 0x0fffffffu
133 #define FAT_MAX 0x0ffffff8u
134 #define FAT_BAD 0x0ffffff7u
135 #define FAT_ENTRY_SIZE 4
140 static inline uint32_t fat_cluster2fatsec(uint32_t cluster) {
144 static inline uint32_t fat_cluster2fatoff(uint32_t cluster) {
168 static inline char unicode2char(uint16_t unich) {
169 return (unich >= 65 && unich <= 90) ? unich - 65 +
'A' : (unich >= 48 && unich <= 57) ? unich - 48 +
'0' : (unich >= 97 && unich <= 122) ? unich - 97 +
'a' : (unich == 95) ?
'_' : (unich == 46) ?
'.' : (unich == 0x20) ?
' ' : (unich == 45) ?
'-' : 0;
171 static inline uint16_t char2unicode(
char ch) {
172 return (ch >=
'A' && ch <=
'Z') ? 65 + ch -
'A' : (ch >=
'a' && ch <=
'z') ? 97 + ch -
'a' : (ch >=
'0' && ch <=
'9') ? 48 + ch -
'0' : (ch ==
'_') ? 95 : (ch ==
'.') ? 46 : (ch ==
' ') ? 0x20 : (ch ==
'-') ? 45 : 0;
#define LONG_NAME3_LEN
Definition: fat32.h:79
struct short_name_entry __attribute__((packed, aligned(4))) short_name_entry_t
#define LONG_NAME1_LEN
Definition: fat32.h:77
#define SHORT_EXT_NAME
Definition: fat32.h:55
#define SHORT_FIR_NAME
Definition: fat32.h:54
dir_info_t cur_dir
Definition: fat32.h:105
struct dir_info dir_info_t
dir_info_t root_dir
Definition: fs.c:20
#define MAX_PATH_LEN
Definition: fat32.h:58
fat32_t fat
Definition: fs.c:19
#define LONG_NAME2_LEN
Definition: fat32.h:78
uint32_t size
Definition: fat32.h:101
char name[MAX_PATH_LEN]
Definition: fat32.h:102
uint32_t first_cluster
Definition: fat32.h:100
uint32_t data_sec_cnt
Definition: fat32.h:31
uint32_t root_cluster
Definition: fat32.h:28
uint32_t next_free_cluster
Definition: fat32.h:36
uint32_t hidd_sec
Definition: fat32.h:25
uint32_t sec_per_fat
Definition: fat32.h:27
uint32_t entry_per_sec
Definition: fat32.h:34
uint32_t first_data_sec
Definition: fat32.h:30
uint32_t bytes_per_cluster
Definition: fat32.h:33
uint8_t sec_per_cluster
Definition: fat32.h:22
uint8_t fat_num
Definition: fat32.h:24
uint16_t rsvd_sec_cnt
Definition: fat32.h:23
uint32_t next_free_fat_sec
Definition: fat32.h:37
uint32_t free_clusters
Definition: fat32.h:35
uint16_t bytes_per_sec
Definition: fat32.h:21
uint32_t data_cluster_cnt
Definition: fat32.h:32
uint32_t totl_sec
Definition: fat32.h:26
uint16_t rsvd
Definition: fat32.h:90
uint8_t type
Definition: fat32.h:87
uint16_t name2[LONG_NAME2_LEN]
Definition: fat32.h:89
uint16_t name1[LONG_NAME1_LEN]
Definition: fat32.h:85
uint16_t name3[LONG_NAME3_LEN]
Definition: fat32.h:91
uint8_t order
Definition: fat32.h:84
uint8_t checksum
Definition: fat32.h:88
uint8_t attr
Definition: fat32.h:86
uint16_t fst_clus_hi
Definition: fat32.h:70
char name2[SHORT_EXT_NAME]
Definition: fat32.h:63
uint16_t lst_wrt_time
Definition: fat32.h:71
uint8_t attr
Definition: fat32.h:64
uint16_t crt_time
Definition: fat32.h:67
uint8_t crt_time_tenth
Definition: fat32.h:66
uint16_t crt_date
Definition: fat32.h:68
uint32_t file_size
Definition: fat32.h:74
uint16_t fst_clus_lo
Definition: fat32.h:73
uint8_t nt_res
Definition: fat32.h:65
uint16_t lst_acce_date
Definition: fat32.h:69
char name1[SHORT_FIR_NAME]
Definition: fat32.h:62
uint16_t lst_wrt_date
Definition: fat32.h:72
unsigned int uint32
Definition: types.h:37
short_name_entry_t sn
Definition: fat32.h:95
long_name_entry_t ln
Definition: fat32.h:96