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