1 #ifndef _LINUX_MSDOS_FS_H
2 #define _LINUX_MSDOS_FS_H
3
4
5
6
7 #include <linux/fs.h>
8 #include <linux/stat.h>
9 #include <linux/fd.h>
10
11 #define MSDOS_ROOT_INO 1
12 #define SECTOR_SIZE 512
13 #define SECTOR_BITS 9
14 #define MSDOS_DPB (MSDOS_DPS)
15 #define MSDOS_DPB_BITS 4
16 #define MSDOS_DPS (SECTOR_SIZE/sizeof(struct msdos_dir_entry))
17 #define MSDOS_DPS_BITS 4
18 #define MSDOS_DIR_BITS 5
19
20 #define MSDOS_SUPER_MAGIC 0x4d44
21
22 #define FAT_CACHE 8
23
24 #define MSDOS_MAX_EXTRA 3
25
26
27 #define ATTR_RO 1
28 #define ATTR_HIDDEN 2
29 #define ATTR_SYS 4
30 #define ATTR_VOLUME 8
31 #define ATTR_DIR 16
32 #define ATTR_ARCH 32
33
34 #define ATTR_NONE 0
35 #define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
36
37 #define ATTR_EXT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
38
39
40 #define ATTR_DIR_READ_BOTH 512
41
42
43
44 #define ATTR_DIR_READ_SHORT 1024
45
46 #define CASE_LOWER_BASE 8
47 #define CASE_LOWER_EXT 16
48
49 #define SCAN_ANY 0
50 #define SCAN_HID 1
51 #define SCAN_NOTHID 2
52 #define SCAN_NOTANY 3
53
54 #define DELETED_FLAG 0xe5
55 #define IS_FREE(n) (!*(n) || *(const unsigned char *) (n) == DELETED_FLAG || \
56 *(const unsigned char *) (n) == FD_FILL_BYTE)
57
58 #define MSDOS_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)
59
60
61 #define MSDOS_SB(s) (&((s)->u.msdos_sb))
62 #define MSDOS_I(i) (&((i)->u.msdos_i))
63
64 #define MSDOS_NAME 11
65 #define MSDOS_LONGNAME 256
66 #define MSDOS_SLOTS 21
67 #define MSDOS_DOT ". "
68 #define MSDOS_DOTDOT ".. "
69
70 #define MSDOS_FAT12 4078
71
72
73
74
75 #define FAT_BINARY_FL 0x00000001
76
77
78
79
80 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, long)
81 #define VFAT_IOCTL_READDIR_SHORT _IOW('r', 2, long)
82
83
84
85
86
87
88
89
90 #define CF_LE_W(v) (v)
91 #define CF_LE_L(v) (v)
92 #define CT_LE_W(v) (v)
93 #define CT_LE_L(v) (v)
94
95
96 struct msdos_boot_sector {
97 __s8 ignored[3];
98 __s8 system_id[8];
99
100 __u8 sector_size[2];
101 __u8 cluster_size;
102 __u16 reserved;
103 __u8 fats;
104 __u8 dir_entries[2];
105 __u8 sectors[2];
106 __u8 media;
107 __u16 fat_length;
108 __u16 secs_track;
109 __u16 heads;
110 __u32 hidden;
111 __u32 total_sect;
112 };
113
114 struct msdos_dir_entry {
115 __s8 name[8],ext[3];
116 __u8 attr;
117 __u8 lcase;
118 __u8 ctime_ms;
119 __u16 ctime;
120 __u16 cdate;
121 __u16 adate;
122 __u8 unused[2];
123 __u16 time,date,start;
124 __u32 size;
125 };
126
127
128 struct msdos_dir_slot {
129 __u8 id;
130 __u8 name0_4[10];
131 __u8 attr;
132 __u8 reserved;
133 __u8 alias_checksum;
134 __u8 name5_10[12];
135 __u8 start[2];
136 __u8 name11_12[4];
137 };
138
139 struct slot_info {
140 int is_long;
141 int long_slots;
142 int total_slots;
143 loff_t longname_offset;
144 loff_t shortname_offset;
145 int ino;
146 };
147
148
149 #define MSDOS_CAN_BMAP(mib) (!(((mib)->cluster_size & 1) || \
150 ((mib)->data_start & 1)))
151
152
153 #define MSDOS_MKMODE(a,m) (m & (a & ATTR_RO ? S_IRUGO|S_IXUGO : S_IRWXUGO))
154
155
156 #define MSDOS_MKATTR(m) ((m & S_IWUGO) ? ATTR_NONE : ATTR_RO)
157
158
159 #ifdef __KERNEL__
160
161 typedef int (*fat_filldir_t)(filldir_t filldir, void *, const char *,
162 int, int, off_t, off_t, int, ino_t);
163
164 struct fat_cache {
165 kdev_t device;
166 int ino;
167 int file_cluster;
168 int disk_cluster;
169 struct fat_cache *next;
170 };
171
172
173 extern int is_binary(char conversion,char *extension);
174 extern void lock_fat(struct super_block *sb);
175 extern void unlock_fat(struct super_block *sb);
176 extern int fat_add_cluster(struct inode *inode);
177 extern int date_dos2unix(__u16 time, __u16 date);
178 extern void fat_fs_panic(struct super_block *s,const char *msg);
179 extern void fat_lock_creation(void);
180 extern void fat_unlock_creation(void);
181 extern void fat_date_unix2dos(int unix_date,__u16 *time, __u16 *date);
182 extern int fat_get_entry(struct inode *dir,loff_t *pos,struct buffer_head **bh,
183 struct msdos_dir_entry **de);
184 extern int fat_scan(struct inode *dir,const char *name,struct buffer_head **res_bh,
185 struct msdos_dir_entry **res_de,int *ino,char scantype);
186 extern int fat_parent_ino(struct inode *dir,int locked);
187 extern int fat_subdirs(struct inode *dir);
188
189
190 extern int fat_access(struct super_block *sb,int nr,int new_value);
191 extern int fat_smap(struct inode *inode,int sector);
192 extern int fat_free(struct inode *inode,int skip);
193 void fat_cache_inval_inode(struct inode *inode);
194 void fat_cache_inval_dev(kdev_t device);
195 extern void cache_init(void);
196 void cache_lookup(struct inode *inode,int cluster,int *f_clu,int *d_clu);
197 void cache_add(struct inode *inode,int f_clu,int d_clu);
198 int get_cluster(struct inode *inode,int cluster);
199
200
201 extern int fat_bmap(struct inode *inode,int block);
202 extern int fat_notify_change(struct inode *,struct iattr *);
203 extern void fat_put_inode(struct inode *inode);
204 extern void fat_put_super(struct super_block *sb);
205 extern void fat_read_inode(struct inode *inode, struct inode_operations *dir_ops);
206 extern struct super_block *fat_read_super(struct super_block *s, void *data, int silent);
207 extern void msdos_put_super(struct super_block *sb);
208 extern void fat_statfs(struct super_block *sb,struct statfs *buf, int);
209 extern void fat_write_inode(struct inode *inode);
210
211
212 extern struct file_operations fat_dir_operations;
213 extern int fat_readdirx(struct inode *inode, struct file *filp, void *dirent,
214 fat_filldir_t fat_filldir, filldir_t filldir,
215 int shortnames, int longnames, int both);
216 extern int fat_readdir(struct inode *inode, struct file *filp,
217 void *dirent, filldir_t);
218 extern int fat_dir_ioctl(struct inode * inode, struct file * filp,
219 unsigned int cmd, unsigned long arg);
220
221
222 extern struct inode_operations fat_file_inode_operations;
223 extern struct inode_operations fat_file_inode_operations_1024;
224 extern int fat_file_read(struct inode *, struct file *, char *, int);
225 extern int fat_file_write(struct inode *, struct file *, const char *, int);
226 extern void fat_truncate(struct inode *inode);
227
228
229 extern int fat_mmap(struct inode *, struct file *, struct vm_area_struct *);
230
231
232
233 extern int init_vfat_fs(void);
234
235
236
237 extern int init_msdos_fs(void);
238 extern struct file_system_type msdos_fs_type;
239
240
241 extern struct super_block *msdos_read_super(struct super_block *sb,void *data, int silent);
242
243
244 extern void msdos_read_inode(struct inode *inode);
245 extern int msdos_lookup(struct inode *dir,const char *name,int len,
246 struct inode **result);
247 extern int msdos_create(struct inode *dir,const char *name,int len,int mode,
248 struct inode **result);
249 extern int msdos_rmdir(struct inode *dir,const char *name,int len);
250 extern int msdos_mkdir(struct inode *dir,const char *name,int len,int mode);
251 extern int msdos_unlink(struct inode *dir,const char *name,int len);
252 extern int msdos_unlink_umsdos(struct inode *dir,const char *name,int len);
253 extern int msdos_rename(struct inode *old_dir,const char *old_name,int old_len,
254 struct inode *new_dir,const char *new_name,int new_len);
255
256
257 extern int init_fat_fs(void);
258
259 #endif
260
261 #endif