* added 0.99 linux version
[mascara-docs.git] / i386 / linux / linux-2.3.21 / include / linux / msdos_fs.h
blob3a7f286228c4b91024a2ff93f1e102d3d1602f2a
1 #ifndef _LINUX_MSDOS_FS_H
2 #define _LINUX_MSDOS_FS_H
4 /*
5 * The MS-DOS filesystem constants/structures
6 */
7 #include <linux/fs.h>
8 #include <linux/stat.h>
9 #include <linux/fd.h>
11 #include <asm/byteorder.h>
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)) */
22 #define MSDOS_SUPER_MAGIC 0x4d44 /* MD */
24 #define FAT_CACHE 8 /* FAT cache size */
26 #define MSDOS_MAX_EXTRA 3 /* tolerate up to that number of clusters which are
27 inaccessible because the FAT is too short */
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 */
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 */
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
48 #define CASE_LOWER_BASE 8 /* base is lower case */
49 #define CASE_LOWER_EXT 16 /* extension is lower case */
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 */
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 *(const unsigned char *) (n) == FD_FILL_BYTE)
60 #define MSDOS_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)
61 /* valid file mode bits */
63 #define MSDOS_SB(s) (&((s)->u.msdos_sb))
64 #define MSDOS_I(i) (&((i)->u.msdos_i))
66 #define MSDOS_NAME 11 /* maximum name length */
67 #define MSDOS_LONGNAME 256 /* maximum name length */
68 #define MSDOS_SLOTS 21 /* max # of slots needed for short and long names */
69 #define MSDOS_DOT ". " /* ".", padded to MSDOS_NAME chars */
70 #define MSDOS_DOTDOT ".. " /* "..", padded to MSDOS_NAME chars */
72 #define MSDOS_FAT12 4078 /* maximum number of clusters in a 12 bit FAT */
74 #define EOF_FAT12 0xFF8 /* standard EOF */
75 #define EOF_FAT16 0xFFF8
76 #define EOF_FAT32 0xFFFFFF8
77 #define EOF_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? EOF_FAT32 : \
78 MSDOS_SB(s)->fat_bits == 16 ? EOF_FAT16 : EOF_FAT12)
81 * Inode flags
83 #define FAT_BINARY_FL 0x00000001 /* File contains binary data */
86 * ioctl commands
88 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
89 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])
92 * Conversion from and to little-endian byte order. (no-op on i386/i486)
94 * Naming: Ca_b_c, where a: F = from, T = to, b: LE = little-endian,
95 * BE = big-endian, c: W = word (16 bits), L = longword (32 bits)
98 #define CF_LE_W(v) le16_to_cpu(v)
99 #define CF_LE_L(v) le32_to_cpu(v)
100 #define CT_LE_W(v) cpu_to_le16(v)
101 #define CT_LE_L(v) cpu_to_le32(v)
103 struct fat_boot_sector {
104 __s8 ignored[3]; /* Boot strap short or near jump */
105 __s8 system_id[8]; /* Name - can be used to special case
106 partition manager volumes */
107 __u8 sector_size[2]; /* bytes per logical sector */
108 __u8 cluster_size; /* sectors/cluster */
109 __u16 reserved; /* reserved sectors */
110 __u8 fats; /* number of FATs */
111 __u8 dir_entries[2]; /* root directory entries */
112 __u8 sectors[2]; /* number of sectors */
113 __u8 media; /* media code (unused) */
114 __u16 fat_length; /* sectors/FAT */
115 __u16 secs_track; /* sectors per track */
116 __u16 heads; /* number of heads */
117 __u32 hidden; /* hidden sectors (unused) */
118 __u32 total_sect; /* number of sectors (if sectors == 0) */
120 /* The following fields are only used by FAT32 */
121 __u32 fat32_length; /* sectors/FAT */
122 __u16 flags; /* bit 8: fat mirroring, low 4: active fat */
123 __u8 version[2]; /* major, minor filesystem version */
124 __u32 root_cluster; /* first cluster in root directory */
125 __u16 info_sector; /* filesystem info sector */
126 __u16 backup_boot; /* backup boot sector */
127 __u16 reserved2[6]; /* Unused */
130 struct fat_boot_fsinfo {
131 __u32 reserved1; /* Nothing as far as I can tell */
132 __u32 signature; /* 0x61417272L */
133 __u32 free_clusters; /* Free cluster count. -1 if unknown */
134 __u32 next_cluster; /* Most recently allocated cluster.
135 * Unused under Linux. */
136 __u32 reserved2[4];
139 struct msdos_dir_entry {
140 __s8 name[8],ext[3]; /* name and extension */
141 __u8 attr; /* attribute bits */
142 __u8 lcase; /* Case for base and extension */
143 __u8 ctime_ms; /* Creation time, milliseconds */
144 __u16 ctime; /* Creation time */
145 __u16 cdate; /* Creation date */
146 __u16 adate; /* Last access date */
147 __u16 starthi; /* High 16 bits of cluster in FAT32 */
148 __u16 time,date,start;/* time, date and first cluster */
149 __u32 size; /* file size (in bytes) */
152 /* Up to 13 characters of the name */
153 struct msdos_dir_slot {
154 __u8 id; /* sequence number for slot */
155 __u8 name0_4[10]; /* first 5 characters in name */
156 __u8 attr; /* attribute byte */
157 __u8 reserved; /* always 0 */
158 __u8 alias_checksum; /* checksum for 8.3 alias */
159 __u8 name5_10[12]; /* 6 more characters in name */
160 __u16 start; /* starting cluster number, 0 in long slots */
161 __u8 name11_12[4]; /* last 2 characters in name */
164 struct vfat_slot_info {
165 int is_long; /* was the found entry long */
166 int long_slots; /* number of long slots in filename */
167 int total_slots; /* total slots (long and short) */
168 loff_t longname_offset; /* dir offset for longname start */
169 loff_t shortname_offset; /* dir offset for shortname start */
170 int ino; /* ino for the file */
173 /* Determine whether this FS has kB-aligned data. */
174 #define MSDOS_CAN_BMAP(mib) (!(((mib)->cluster_size & 1) || \
175 ((mib)->data_start & 1)))
177 /* Convert attribute bits and a mask to the UNIX mode. */
178 #define MSDOS_MKMODE(a,m) (m & (a & ATTR_RO ? S_IRUGO|S_IXUGO : S_IRWXUGO))
180 /* Convert the UNIX mode to MS-DOS attribute bits. */
181 #define MSDOS_MKATTR(m) ((m & S_IWUGO) ? ATTR_NONE : ATTR_RO)
184 #ifdef __KERNEL__
186 struct fat_cache {
187 kdev_t device; /* device number. 0 means unused. */
188 int start_cluster; /* first cluster of the chain. */
189 int file_cluster; /* cluster number in the file. */
190 int disk_cluster; /* cluster number on disk. */
191 struct fat_cache *next; /* next cache entry */
194 /* misc.c */
195 extern int fat_is_binary(char conversion,char *extension);
196 extern void lock_fat(struct super_block *sb);
197 extern void unlock_fat(struct super_block *sb);
198 extern int fat_add_cluster(struct inode *inode);
199 extern struct buffer_head *fat_extend_dir(struct inode *inode);
200 extern int date_dos2unix(__u16 time, __u16 date);
201 extern void fat_fs_panic(struct super_block *s,const char *msg);
202 extern void fat_lock_creation(void);
203 extern void fat_unlock_creation(void);
204 extern void fat_date_unix2dos(int unix_date,__u16 *time, __u16 *date);
205 extern int fat__get_entry(struct inode *dir,loff_t *pos,struct buffer_head **bh,
206 struct msdos_dir_entry **de,int *ino);
207 static __inline__ int fat_get_entry(struct inode *dir,loff_t *pos,
208 struct buffer_head **bh,struct msdos_dir_entry **de,int *ino)
210 /* Fast stuff first */
211 if (*bh && *de &&
212 (*de - (struct msdos_dir_entry *)(*bh)->b_data) < MSDOS_DPB-1) {
213 *pos += sizeof(struct msdos_dir_entry);
214 (*de)++;
215 (*ino)++;
216 return 0;
218 return fat__get_entry(dir,pos,bh,de,ino);
220 extern int fat_scan(struct inode *dir,const char *name,struct buffer_head **res_bh,
221 struct msdos_dir_entry **res_de,int *ino);
222 extern int fat_parent_ino(struct inode *dir,int locked);
223 extern int fat_subdirs(struct inode *dir);
224 void fat_clusters_flush(struct super_block *sb);
226 /* fat.c */
227 extern int fat_access(struct super_block *sb,int nr,int new_value);
228 extern int fat_free(struct inode *inode,int skip);
229 void fat_cache_inval_inode(struct inode *inode);
230 void fat_cache_inval_dev(kdev_t device);
231 extern void fat_cache_init(void);
232 void fat_cache_lookup(struct inode *inode,int cluster,int *f_clu,int *d_clu);
233 void fat_cache_add(struct inode *inode,int f_clu,int d_clu);
234 int fat_get_cluster(struct inode *inode,int cluster);
236 /* inode.c */
237 extern void fat_hash_init(void);
238 extern int fat_bmap(struct inode *inode,int block);
239 extern int fat_get_block(struct inode *, long, struct buffer_head *, int);
240 extern int fat_notify_change(struct dentry *, struct iattr *);
241 extern void fat_clear_inode(struct inode *inode);
242 extern void fat_delete_inode(struct inode *inode);
243 extern void fat_put_super(struct super_block *sb);
244 extern void fat_attach(struct inode *inode, int ino);
245 extern void fat_detach(struct inode *inode);
246 extern struct inode *fat_iget(struct super_block*,int);
247 extern struct inode *fat_build_inode(struct super_block*,struct msdos_dir_entry*,int,int*);
248 extern struct super_block *fat_read_super(struct super_block *s, void *data, int silent, struct inode_operations *dir_ops);
249 extern void msdos_put_super(struct super_block *sb);
250 extern int fat_statfs(struct super_block *sb,struct statfs *buf, int);
251 extern void fat_write_inode(struct inode *inode);
253 /* dir.c */
254 extern struct file_operations fat_dir_operations;
255 extern int fat_search_long(struct inode *dir, const char *name, int len,
256 int anycase, loff_t *spos, loff_t *lpos);
257 extern int fat_readdir(struct file *filp,
258 void *dirent, filldir_t);
259 extern int fat_dir_ioctl(struct inode * inode, struct file * filp,
260 unsigned int cmd, unsigned long arg);
261 int fat_add_entries(struct inode *dir,int slots, struct buffer_head **bh,
262 struct msdos_dir_entry **de, int *ino);
263 int fat_dir_empty(struct inode *dir);
264 int fat_new_dir(struct inode *inode, struct inode *parent, int is_vfat);
266 /* file.c */
267 extern struct inode_operations fat_file_inode_operations;
268 extern struct inode_operations fat_file_inode_operations_1024;
269 extern struct inode_operations fat_file_inode_operations_readpage;
270 extern ssize_t fat_file_read(struct file *, char *, size_t, loff_t *);
271 extern ssize_t fat_file_write(struct file *, const char *, size_t, loff_t *);
272 extern void fat_truncate(struct inode *inode);
274 /* mmap.c */
275 extern int fat_mmap(struct file *, struct vm_area_struct *);
276 extern int fat_readpage(struct file *, struct page *);
279 /* vfat.c */
280 extern int init_vfat_fs(void);
283 /* msdosfs_syms.c */
284 extern int init_msdos_fs(void);
285 extern struct file_system_type msdos_fs_type;
287 /* msdos.c */
288 extern struct super_block *msdos_read_super(struct super_block *sb,void *data, int silent);
290 /* msdos.c - these are for Umsdos */
291 extern void msdos_read_inode(struct inode *inode);
292 extern struct dentry *msdos_lookup(struct inode *dir,struct dentry *);
293 extern int msdos_create(struct inode *dir,struct dentry *dentry,int mode);
294 extern int msdos_rmdir(struct inode *dir,struct dentry *dentry);
295 extern int msdos_mkdir(struct inode *dir,struct dentry *dentry,int mode);
296 extern int msdos_unlink(struct inode *dir,struct dentry *dentry);
297 extern int msdos_rename(struct inode *old_dir,struct dentry *old_dentry,
298 struct inode *new_dir,struct dentry *new_dentry);
300 /* nls.c */
301 extern int init_fat_nls(void);
302 extern struct fat_nls_table *fat_load_nls(int codepage);
304 /* tables.c */
305 extern unsigned char fat_uni2esc[];
306 extern unsigned char fat_esc2uni[];
308 /* fatfs_syms.c */
309 extern int init_fat_fs(void);
310 extern void cleanup_fat_fs(void);
312 /* nls.c */
313 extern int fat_register_nls(struct fat_nls_table * fmt);
314 extern int fat_unregister_nls(struct fat_nls_table * fmt);
315 extern struct fat_nls_table *fat_find_nls(int codepage);
316 extern struct fat_nls_table *fat_load_nls(int codepage);
317 extern void fat_unload_nls(int codepage);
318 extern int init_fat_nls(void);
320 /* vfat/namei.c - these are for dmsdos */
321 extern int vfat_create(struct inode *dir,struct dentry *dentry,int mode);
322 extern int vfat_unlink(struct inode *dir,struct dentry *dentry);
323 extern int vfat_mkdir(struct inode *dir,struct dentry *dentry,int mode);
324 extern int vfat_rmdir(struct inode *dir,struct dentry *dentry);
325 extern int vfat_rename(struct inode *old_dir,struct dentry *old_dentry,
326 struct inode *new_dir,struct dentry *new_dentry);
327 extern struct super_block *vfat_read_super(struct super_block *sb,void *data,
328 int silent);
329 extern void vfat_read_inode(struct inode *inode);
330 extern struct dentry *vfat_lookup(struct inode *dir,struct dentry *);
332 /* vfat/vfatfs_syms.c */
333 extern struct file_system_type vfat_fs_type;
335 #endif /* __KERNEL__ */
337 #endif