File: /usr/src/linux/include/linux/msdos_fs.h
1 #ifndef _LINUX_MSDOS_FS_H
2 #define _LINUX_MSDOS_FS_H
3
4 /*
5 * The MS-DOS filesystem constants/structures
6 */
7 #include <linux/fs.h>
8 #include <linux/stat.h>
9 #include <linux/fd.h>
10
11 #include <asm/byteorder.h>
12
13 #define MSDOS_ROOT_INO 1 /* == MINIX_ROOT_INO */
14 #define SECTOR_SIZE 512 /* sector size (bytes) */
15 #define SECTOR_BITS 9 /* log2(SECTOR_SIZE) */
16 #define MSDOS_DPB (MSDOS_DPS) /* dir entries per block */
17 #define MSDOS_DPB_BITS 4 /* log2(MSDOS_DPB) */
18 #define MSDOS_DPS (SECTOR_SIZE/sizeof(struct msdos_dir_entry))
19 #define MSDOS_DPS_BITS 4 /* log2(MSDOS_DPS) */
20 #define MSDOS_DIR_BITS 5 /* log2(sizeof(struct msdos_dir_entry)) */
21
22 #define MSDOS_SUPER_MAGIC 0x4d44 /* MD */
23
24 #define FAT_CACHE 8 /* FAT cache size */
25
26 #define MSDOS_MAX_EXTRA 3 /* tolerate up to that number of clusters which are
27 inaccessible because the FAT is too short */
28
29 #define ATTR_RO 1 /* read-only */
30 #define ATTR_HIDDEN 2 /* hidden */
31 #define ATTR_SYS 4 /* system */
32 #define ATTR_VOLUME 8 /* volume label */
33 #define ATTR_DIR 16 /* directory */
34 #define ATTR_ARCH 32 /* archived */
35
36 #define ATTR_NONE 0 /* no attribute bits */
37 #define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
38 /* attribute bits that are copied "as is" */
39 #define ATTR_EXT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
40 /* bits that are used by the Windows 95/Windows NT extended FAT */
41
42 #define ATTR_DIR_READ_BOTH 512 /* read both short and long names from the
43 * vfat filesystem. This is used by Samba
44 * to export the vfat filesystem with correct
45 * shortnames. */
46 #define ATTR_DIR_READ_SHORT 1024
47
48 #define CASE_LOWER_BASE 8 /* base is lower case */
49 #define CASE_LOWER_EXT 16 /* extension is lower case */
50
51 #define SCAN_ANY 0 /* either hidden or not */
52 #define SCAN_HID 1 /* only hidden */
53 #define SCAN_NOTHID 2 /* only not hidden */
54 #define SCAN_NOTANY 3 /* test name, then use SCAN_HID or SCAN_NOTHID */
55
56 #define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
57 #define IS_FREE(n) (!*(n) || *(const unsigned char *) (n) == DELETED_FLAG)
58
59 #define MSDOS_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)
60 /* valid file mode bits */
61
62 #define MSDOS_SB(s) (&((s)->u.msdos_sb))
63 #define MSDOS_I(i) (&((i)->u.msdos_i))
64
65 #define MSDOS_NAME 11 /* maximum name length */
66 #define MSDOS_LONGNAME 256 /* maximum name length */
67 #define MSDOS_SLOTS 21 /* max # of slots needed for short and long names */
68 #define MSDOS_DOT ". " /* ".", padded to MSDOS_NAME chars */
69 #define MSDOS_DOTDOT ".. " /* "..", padded to MSDOS_NAME chars */
70
71 #define MSDOS_FAT12 4084 /* maximum number of clusters in a 12 bit FAT */
72
73 #define EOF_FAT12 0xFF8 /* standard EOF */
74 #define EOF_FAT16 0xFFF8
75 #define EOF_FAT32 0xFFFFFF8
76 #define EOF_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? EOF_FAT32 : \
77 MSDOS_SB(s)->fat_bits == 16 ? EOF_FAT16 : EOF_FAT12)
78
79 #define FAT_FSINFO_SIG1 0x41615252
80 #define FAT_FSINFO_SIG2 0x61417272
81 #define IS_FSINFO(x) (CF_LE_L((x)->signature1) == FAT_FSINFO_SIG1 \
82 && CF_LE_L((x)->signature2) == FAT_FSINFO_SIG2)
83
84 /*
85 * Inode flags
86 */
87 #define FAT_BINARY_FL 0x00000001 /* File contains binary data */
88
89 /*
90 * ioctl commands
91 */
92 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
93 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])
94
95 /*
96 * Conversion from and to little-endian byte order. (no-op on i386/i486)
97 *
98 * Naming: Ca_b_c, where a: F = from, T = to, b: LE = little-endian,
99 * BE = big-endian, c: W = word (16 bits), L = longword (32 bits)
100 */
101
102 #define CF_LE_W(v) le16_to_cpu(v)
103 #define CF_LE_L(v) le32_to_cpu(v)
104 #define CT_LE_W(v) cpu_to_le16(v)
105 #define CT_LE_L(v) cpu_to_le32(v)
106
107 struct fat_boot_sector {
108 __s8 ignored[3]; /* Boot strap short or near jump */
109 __s8 system_id[8]; /* Name - can be used to special case
110 partition manager volumes */
111 __u8 sector_size[2]; /* bytes per logical sector */
112 __u8 cluster_size; /* sectors/cluster */
113 __u16 reserved; /* reserved sectors */
114 __u8 fats; /* number of FATs */
115 __u8 dir_entries[2]; /* root directory entries */
116 __u8 sectors[2]; /* number of sectors */
117 __u8 media; /* media code (unused) */
118 __u16 fat_length; /* sectors/FAT */
119 __u16 secs_track; /* sectors per track */
120 __u16 heads; /* number of heads */
121 __u32 hidden; /* hidden sectors (unused) */
122 __u32 total_sect; /* number of sectors (if sectors == 0) */
123
124 /* The following fields are only used by FAT32 */
125 __u32 fat32_length; /* sectors/FAT */
126 __u16 flags; /* bit 8: fat mirroring, low 4: active fat */
127 __u8 version[2]; /* major, minor filesystem version */
128 __u32 root_cluster; /* first cluster in root directory */
129 __u16 info_sector; /* filesystem info sector */
130 __u16 backup_boot; /* backup boot sector */
131 __u16 reserved2[6]; /* Unused */
132 };
133
134 struct fat_boot_fsinfo {
135 __u32 signature1; /* 0x61417272L */
136 __u32 reserved1[120]; /* Nothing as far as I can tell */
137 __u32 signature2; /* 0x61417272L */
138 __u32 free_clusters; /* Free cluster count. -1 if unknown */
139 __u32 next_cluster; /* Most recently allocated cluster.
140 * Unused under Linux. */
141 __u32 reserved2[4];
142 };
143
144 struct msdos_dir_entry {
145 __s8 name[8],ext[3]; /* name and extension */
146 __u8 attr; /* attribute bits */
147 __u8 lcase; /* Case for base and extension */
148 __u8 ctime_ms; /* Creation time, milliseconds */
149 __u16 ctime; /* Creation time */
150 __u16 cdate; /* Creation date */
151 __u16 adate; /* Last access date */
152 __u16 starthi; /* High 16 bits of cluster in FAT32 */
153 __u16 time,date,start;/* time, date and first cluster */
154 __u32 size; /* file size (in bytes) */
155 };
156
157 /* Up to 13 characters of the name */
158 struct msdos_dir_slot {
159 __u8 id; /* sequence number for slot */
160 __u8 name0_4[10]; /* first 5 characters in name */
161 __u8 attr; /* attribute byte */
162 __u8 reserved; /* always 0 */
163 __u8 alias_checksum; /* checksum for 8.3 alias */
164 __u8 name5_10[12]; /* 6 more characters in name */
165 __u16 start; /* starting cluster number, 0 in long slots */
166 __u8 name11_12[4]; /* last 2 characters in name */
167 };
168
169 struct vfat_slot_info {
170 int is_long; /* was the found entry long */
171 int long_slots; /* number of long slots in filename */
172 int total_slots; /* total slots (long and short) */
173 loff_t longname_offset; /* dir offset for longname start */
174 loff_t shortname_offset; /* dir offset for shortname start */
175 int ino; /* ino for the file */
176 };
177
178 /* Determine whether this FS has kB-aligned data. */
179 #define MSDOS_CAN_BMAP(mib) (!(((mib)->cluster_size & 1) || \
180 ((mib)->data_start & 1)))
181
182 /* Convert attribute bits and a mask to the UNIX mode. */
183 #define MSDOS_MKMODE(a,m) (m & (a & ATTR_RO ? S_IRUGO|S_IXUGO : S_IRWXUGO))
184
185 /* Convert the UNIX mode to MS-DOS attribute bits. */
186 #define MSDOS_MKATTR(m) ((m & S_IWUGO) ? ATTR_NONE : ATTR_RO)
187
188
189 #ifdef __KERNEL__
190
191 struct fat_cache {
192 kdev_t device; /* device number. 0 means unused. */
193 int start_cluster; /* first cluster of the chain. */
194 int file_cluster; /* cluster number in the file. */
195 int disk_cluster; /* cluster number on disk. */
196 struct fat_cache *next; /* next cache entry */
197 };
198
199 /* misc.c */
200 extern int fat_is_binary(char conversion,char *extension);
201 extern void lock_fat(struct super_block *sb);
202 extern void unlock_fat(struct super_block *sb);
203 extern int fat_add_cluster(struct inode *inode);
204 extern struct buffer_head *fat_extend_dir(struct inode *inode);
205 extern int date_dos2unix(__u16 time, __u16 date);
206 extern void fat_fs_panic(struct super_block *s,const char *msg);
207 extern void fat_lock_creation(void);
208 extern void fat_unlock_creation(void);
209 extern void fat_date_unix2dos(int unix_date,__u16 *time, __u16 *date);
210 extern int fat__get_entry(struct inode *dir,loff_t *pos,struct buffer_head **bh,
211 struct msdos_dir_entry **de,int *ino);
212 static __inline__ int fat_get_entry(struct inode *dir,loff_t *pos,
213 struct buffer_head **bh,struct msdos_dir_entry **de,int *ino)
214 {
215 /* Fast stuff first */
216 if (*bh && *de &&
217 (*de - (struct msdos_dir_entry *)(*bh)->b_data) < MSDOS_SB(dir->i_sb)->dir_per_block - 1) {
218 *pos += sizeof(struct msdos_dir_entry);
219 (*de)++;
220 (*ino)++;
221 return 0;
222 }
223 return fat__get_entry(dir,pos,bh,de,ino);
224 }
225 extern int fat_scan(struct inode *dir,const char *name,struct buffer_head **res_bh,
226 struct msdos_dir_entry **res_de,int *ino);
227 extern int fat_parent_ino(struct inode *dir,int locked);
228 extern int fat_subdirs(struct inode *dir);
229 void fat_clusters_flush(struct super_block *sb);
230
231 /* fat.c */
232 extern int fat_access(struct super_block *sb,int nr,int new_value);
233 extern int fat_free(struct inode *inode,int skip);
234 void fat_cache_inval_inode(struct inode *inode);
235 void fat_cache_inval_dev(kdev_t device);
236 extern void fat_cache_init(void);
237 void fat_cache_lookup(struct inode *inode,int cluster,int *f_clu,int *d_clu);
238 void fat_cache_add(struct inode *inode,int f_clu,int d_clu);
239 int fat_get_cluster(struct inode *inode,int cluster);
240
241 /* inode.c */
242 extern void fat_hash_init(void);
243 extern int fat_bmap(struct inode *inode,int block);
244 extern int fat_get_block(struct inode *, long, struct buffer_head *, int);
245 extern int fat_notify_change(struct dentry *, struct iattr *);
246 extern void fat_clear_inode(struct inode *inode);
247 extern void fat_delete_inode(struct inode *inode);
248 extern void fat_put_super(struct super_block *sb);
249 extern void fat_attach(struct inode *inode, int ino);
250 extern void fat_detach(struct inode *inode);
251 extern struct inode *fat_iget(struct super_block*,int);
252 extern struct inode *fat_build_inode(struct super_block*,struct msdos_dir_entry*,int,int*);
253 extern struct super_block *fat_read_super(struct super_block *s, void *data, int silent, struct inode_operations *dir_ops);
254 extern void msdos_put_super(struct super_block *sb);
255 extern int fat_statfs(struct super_block *sb,struct statfs *buf);
256 extern void fat_write_inode(struct inode *inode, int);
257
258 /* dir.c */
259 extern struct file_operations fat_dir_operations;
260 extern int fat_search_long(struct inode *dir, const char *name, int len,
261 int anycase, loff_t *spos, loff_t *lpos);
262 extern int fat_readdir(struct file *filp,
263 void *dirent, filldir_t);
264 extern int fat_dir_ioctl(struct inode * inode, struct file * filp,
265 unsigned int cmd, unsigned long arg);
266 int fat_add_entries(struct inode *dir,int slots, struct buffer_head **bh,
267 struct msdos_dir_entry **de, int *ino);
268 int fat_dir_empty(struct inode *dir);
269 int fat_new_dir(struct inode *inode, struct inode *parent, int is_vfat);
270
271 /* file.c */
272 extern struct inode_operations fat_file_inode_operations;
273 extern struct inode_operations fat_file_inode_operations_1024;
274 extern struct inode_operations fat_file_inode_operations_readpage;
275 extern struct file_operations fat_file_operations;
276 extern ssize_t fat_file_read(struct file *, char *, size_t, loff_t *);
277 extern ssize_t fat_file_write(struct file *, const char *, size_t, loff_t *);
278 extern void fat_truncate(struct inode *inode);
279
280 /* msdos.c */
281 extern struct super_block *msdos_read_super(struct super_block *sb,void *data, int silent);
282
283 /* msdos.c - these are for Umsdos */
284 extern void msdos_read_inode(struct inode *inode);
285 extern struct dentry *msdos_lookup(struct inode *dir,struct dentry *);
286 extern int msdos_create(struct inode *dir,struct dentry *dentry,int mode);
287 extern int msdos_rmdir(struct inode *dir,struct dentry *dentry);
288 extern int msdos_mkdir(struct inode *dir,struct dentry *dentry,int mode);
289 extern int msdos_unlink(struct inode *dir,struct dentry *dentry);
290 extern int msdos_rename(struct inode *old_dir,struct dentry *old_dentry,
291 struct inode *new_dir,struct dentry *new_dentry);
292
293 /* nls.c */
294 extern struct fat_nls_table *fat_load_nls(int codepage);
295
296 /* tables.c */
297 extern unsigned char fat_uni2esc[];
298 extern unsigned char fat_esc2uni[];
299
300 /* fatfs_syms.c */
301 extern void cleanup_fat_fs(void);
302
303 /* nls.c */
304 extern int fat_register_nls(struct fat_nls_table * fmt);
305 extern int fat_unregister_nls(struct fat_nls_table * fmt);
306 extern struct fat_nls_table *fat_find_nls(int codepage);
307 extern struct fat_nls_table *fat_load_nls(int codepage);
308 extern void fat_unload_nls(int codepage);
309 extern int init_fat_nls(void);
310
311 /* vfat/namei.c - these are for dmsdos */
312 extern int vfat_create(struct inode *dir,struct dentry *dentry,int mode);
313 extern int vfat_unlink(struct inode *dir,struct dentry *dentry);
314 extern int vfat_mkdir(struct inode *dir,struct dentry *dentry,int mode);
315 extern int vfat_rmdir(struct inode *dir,struct dentry *dentry);
316 extern int vfat_rename(struct inode *old_dir,struct dentry *old_dentry,
317 struct inode *new_dir,struct dentry *new_dentry);
318 extern struct super_block *vfat_read_super(struct super_block *sb,void *data,
319 int silent);
320 extern void vfat_read_inode(struct inode *inode);
321 extern struct dentry *vfat_lookup(struct inode *dir,struct dentry *);
322
323 /* vfat/vfatfs_syms.c */
324 extern struct file_system_type vfat_fs_type;
325
326 #endif /* __KERNEL__ */
327
328 #endif
329