1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#ifndef _FAT_H_
28#define _FAT_H_
29
30#include <asm/byteorder.h>
31
32#define CONFIG_SUPPORT_VFAT
33
34#define VFAT_MAXLEN_BYTES 256
35#define VFAT_MAXSEQ 9
36#define PREFETCH_BLOCKS 2
37
38#define MAX_CLUSTSIZE 65536
39#define DIRENTSPERBLOCK (mydata->sect_size / sizeof(dir_entry))
40#define DIRENTSPERCLUST ((mydata->clust_size * mydata->sect_size) / \
41 sizeof(dir_entry))
42
43#define FATBUFBLOCKS 6
44#define FATBUFSIZE (mydata->sect_size * FATBUFBLOCKS)
45#define FAT12BUFSIZE ((FATBUFSIZE*2)/3)
46#define FAT16BUFSIZE (FATBUFSIZE/2)
47#define FAT32BUFSIZE (FATBUFSIZE/4)
48
49
50
51#define FAT12_SIGN "FAT12 "
52#define FAT16_SIGN "FAT16 "
53#define FAT32_SIGN "FAT32 "
54#define SIGNLEN 8
55
56
57#define ATTR_RO 1
58#define ATTR_HIDDEN 2
59#define ATTR_SYS 4
60#define ATTR_VOLUME 8
61#define ATTR_DIR 16
62#define ATTR_ARCH 32
63
64#define ATTR_VFAT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
65
66#define DELETED_FLAG ((char)0xe5)
67#define aRING 0x05
68
69
70
71
72
73#define LAST_LONG_ENTRY_MASK 0x40
74
75
76#define LS_NO 0
77#define LS_YES 1
78#define LS_DIR 1
79#define LS_ROOT 2
80
81#define ISDIRDELIM(c) ((c) == '/' || (c) == '\\')
82
83#define FSTYPE_NONE (-1)
84
85#if defined(__linux__) && defined(__KERNEL__)
86#define FAT2CPU16 le16_to_cpu
87#define FAT2CPU32 le32_to_cpu
88#else
89#if __LITTLE_ENDIAN
90#define FAT2CPU16(x) (x)
91#define FAT2CPU32(x) (x)
92#else
93#define FAT2CPU16(x) ((((x) & 0x00ff) << 8) | (((x) & 0xff00) >> 8))
94#define FAT2CPU32(x) ((((x) & 0x000000ff) << 24) | \
95 (((x) & 0x0000ff00) << 8) | \
96 (((x) & 0x00ff0000) >> 8) | \
97 (((x) & 0xff000000) >> 24))
98#endif
99#endif
100
101#define TOLOWER(c) if((c) >= 'A' && (c) <= 'Z'){(c)+=('a' - 'A');}
102#define TOUPPER(c) if ((c) >= 'a' && (c) <= 'z') \
103 (c) -= ('a' - 'A');
104#define START(dent) (FAT2CPU16((dent)->start) \
105 + (mydata->fatsize != 32 ? 0 : \
106 (FAT2CPU16((dent)->starthi) << 16)))
107#define CHECK_CLUST(x, fatsize) ((x) <= 1 || \
108 (x) >= ((fatsize) != 32 ? 0xfff0 : 0xffffff0))
109
110typedef struct boot_sector {
111 __u8 ignored[3];
112 char system_id[8];
113 __u8 sector_size[2];
114 __u8 cluster_size;
115 __u16 reserved;
116 __u8 fats;
117 __u8 dir_entries[2];
118 __u8 sectors[2];
119 __u8 media;
120 __u16 fat_length;
121 __u16 secs_track;
122 __u16 heads;
123 __u32 hidden;
124 __u32 total_sect;
125
126
127 __u32 fat32_length;
128 __u16 flags;
129 __u8 version[2];
130 __u32 root_cluster;
131 __u16 info_sector;
132 __u16 backup_boot;
133 __u16 reserved2[6];
134} boot_sector;
135
136typedef struct volume_info
137{
138 __u8 drive_number;
139 __u8 reserved;
140 __u8 ext_boot_sign;
141 __u8 volume_id[4];
142 char volume_label[11];
143 char fs_type[8];
144
145
146} volume_info;
147
148typedef struct dir_entry {
149 char name[8],ext[3];
150 __u8 attr;
151 __u8 lcase;
152 __u8 ctime_ms;
153 __u16 ctime;
154 __u16 cdate;
155 __u16 adate;
156 __u16 starthi;
157 __u16 time,date,start;
158 __u32 size;
159} dir_entry;
160
161typedef struct dir_slot {
162 __u8 id;
163 __u8 name0_4[10];
164 __u8 attr;
165 __u8 reserved;
166 __u8 alias_checksum;
167 __u8 name5_10[12];
168 __u16 start;
169 __u8 name11_12[4];
170} dir_slot;
171
172
173
174
175
176
177
178typedef struct {
179 __u8 *fatbuf;
180 int fatsize;
181 __u16 fatlength;
182 __u16 fat_sect;
183 __u16 rootdir_sect;
184 __u16 sect_size;
185 __u16 clust_size;
186 short data_begin;
187 int fatbufnum;
188} fsdata;
189
190typedef int (file_detectfs_func)(void);
191typedef int (file_ls_func)(const char *dir);
192typedef long (file_read_func)(const char *filename, void *buffer,
193 unsigned long maxsize);
194
195struct filesystem {
196 file_detectfs_func *detect;
197 file_ls_func *ls;
198 file_read_func *read;
199 const char name[12];
200};
201
202
203file_detectfs_func file_fat_detectfs;
204file_ls_func file_fat_ls;
205file_read_func file_fat_read;
206
207
208int file_cd(const char *path);
209int file_fat_detectfs(void);
210int file_fat_ls(const char *dir);
211long file_fat_read(const char *filename, void *buffer, unsigned long maxsize);
212const char *file_getfsname(int idx);
213int fat_register_device(block_dev_desc_t *dev_desc, int part_no);
214
215int file_fat_write(const char *filename, void *buffer, unsigned long maxsize);
216#endif
217