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