File: /usr/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     /*
80      * Inode flags
81      */
82     #define FAT_BINARY_FL		0x00000001 /* File contains binary data */
83     
84     /*
85      * ioctl commands
86      */
87     #define	VFAT_IOCTL_READDIR_BOTH		_IOR('r', 1, struct dirent [2])
88     #define	VFAT_IOCTL_READDIR_SHORT	_IOR('r', 2, struct dirent [2])
89     
90     /*
91      * Conversion from and to little-endian byte order. (no-op on i386/i486)
92      *
93      * Naming: Ca_b_c, where a: F = from, T = to, b: LE = little-endian,
94      * BE = big-endian, c: W = word (16 bits), L = longword (32 bits)
95      */
96     
97     #define CF_LE_W(v) le16_to_cpu(v)
98     #define CF_LE_L(v) le32_to_cpu(v)
99     #define CT_LE_W(v) cpu_to_le16(v)
100     #define CT_LE_L(v) cpu_to_le32(v)
101     
102     struct fat_boot_sector {
103     	__s8	ignored[3];	/* Boot strap short or near jump */
104     	__s8	system_id[8];	/* Name - can be used to special case
105     				   partition manager volumes */
106     	__u8	sector_size[2];	/* bytes per logical sector */
107     	__u8	cluster_size;	/* sectors/cluster */
108     	__u16	reserved;	/* reserved sectors */
109     	__u8	fats;		/* number of FATs */
110     	__u8	dir_entries[2];	/* root directory entries */
111     	__u8	sectors[2];	/* number of sectors */
112     	__u8	media;		/* media code (unused) */
113     	__u16	fat_length;	/* sectors/FAT */
114     	__u16	secs_track;	/* sectors per track */
115     	__u16	heads;		/* number of heads */
116     	__u32	hidden;		/* hidden sectors (unused) */
117     	__u32	total_sect;	/* number of sectors (if sectors == 0) */
118     
119     	/* The following fields are only used by FAT32 */
120     	__u32	fat32_length;	/* sectors/FAT */
121     	__u16	flags;		/* bit 8: fat mirroring, low 4: active fat */
122     	__u8	version[2];	/* major, minor filesystem version */
123     	__u32	root_cluster;	/* first cluster in root directory */
124     	__u16	info_sector;	/* filesystem info sector */
125     	__u16	backup_boot;	/* backup boot sector */
126     	__u16	reserved2[6];	/* Unused */
127     };
128     
129     struct fat_boot_fsinfo {
130     	__u32   reserved1;	/* Nothing as far as I can tell */
131     	__u32   signature;	/* 0x61417272L */
132     	__u32   free_clusters;	/* Free cluster count.  -1 if unknown */
133     	__u32   next_cluster;	/* Most recently allocated cluster.
134     				 * Unused under Linux. */
135     	__u32   reserved2[4];
136     };
137     
138     struct msdos_dir_entry {
139     	__s8	name[8],ext[3];	/* name and extension */
140     	__u8	attr;		/* attribute bits */
141     	__u8    lcase;		/* Case for base and extension */
142     	__u8	ctime_ms;	/* Creation time, milliseconds */
143     	__u16	ctime;		/* Creation time */
144     	__u16	cdate;		/* Creation date */
145     	__u16	adate;		/* Last access date */
146     	__u16   starthi;	/* High 16 bits of cluster in FAT32 */
147     	__u16	time,date,start;/* time, date and first cluster */
148     	__u32	size;		/* file size (in bytes) */
149     };
150     
151     /* Up to 13 characters of the name */
152     struct msdos_dir_slot {
153     	__u8    id;		/* sequence number for slot */
154     	__u8    name0_4[10];	/* first 5 characters in name */
155     	__u8    attr;		/* attribute byte */
156     	__u8    reserved;	/* always 0 */
157     	__u8    alias_checksum;	/* checksum for 8.3 alias */
158     	__u8    name5_10[12];	/* 6 more characters in name */
159     	__u16   start;		/* starting cluster number, 0 in long slots */
160     	__u8    name11_12[4];	/* last 2 characters in name */
161     };
162     
163     struct vfat_slot_info {
164     	int is_long;		       /* was the found entry long */
165     	int long_slots;		       /* number of long slots in filename */
166     	int total_slots;	       /* total slots (long and short) */
167     	loff_t longname_offset;	       /* dir offset for longname start */
168     	loff_t shortname_offset;       /* dir offset for shortname start */
169     	int ino;		       /* ino for the file */
170     };
171     
172     /* Determine whether this FS has kB-aligned data. */
173     #define MSDOS_CAN_BMAP(mib) (!(((mib)->cluster_size & 1) || \
174         ((mib)->data_start & 1)))
175     
176     /* Convert attribute bits and a mask to the UNIX mode. */
177     #define MSDOS_MKMODE(a,m) (m & (a & ATTR_RO ? S_IRUGO|S_IXUGO : S_IRWXUGO))
178     
179     /* Convert the UNIX mode to MS-DOS attribute bits. */
180     #define MSDOS_MKATTR(m) ((m & S_IWUGO) ? ATTR_NONE : ATTR_RO)
181     
182     
183     #ifdef __KERNEL__
184     
185     struct fat_cache {
186     	kdev_t device; /* device number. 0 means unused. */
187     	int start_cluster; /* first cluster of the chain. */
188     	int file_cluster; /* cluster number in the file. */
189     	int disk_cluster; /* cluster number on disk. */
190     	struct fat_cache *next; /* next cache entry */
191     };
192     
193     /* misc.c */
194     extern int fat_is_binary(char conversion,char *extension);
195     extern void lock_fat(struct super_block *sb);
196     extern void unlock_fat(struct super_block *sb);
197     extern int fat_add_cluster(struct inode *inode);
198     extern struct buffer_head *fat_extend_dir(struct inode *inode);
199     extern int date_dos2unix(__u16 time, __u16 date);
200     extern void fat_fs_panic(struct super_block *s,const char *msg);
201     extern void fat_lock_creation(void);
202     extern void fat_unlock_creation(void);
203     extern void fat_date_unix2dos(int unix_date,__u16 *time, __u16 *date);
204     extern int fat__get_entry(struct inode *dir,loff_t *pos,struct buffer_head **bh,
205     			 struct msdos_dir_entry **de,int *ino);
206     static __inline__ int fat_get_entry(struct inode *dir,loff_t *pos,
207     		struct buffer_head **bh,struct msdos_dir_entry **de,int *ino)
208     {
209     	/* Fast stuff first */
210     	if (*bh && *de &&
211     	    	(*de - (struct msdos_dir_entry *)(*bh)->b_data) < MSDOS_DPB-1) {
212     		*pos += sizeof(struct msdos_dir_entry);
213     		(*de)++;
214     		(*ino)++;
215     		return 0;
216     	}
217     	return fat__get_entry(dir,pos,bh,de,ino);
218     }
219     extern int fat_scan(struct inode *dir,const char *name,struct buffer_head **res_bh,
220     		    struct msdos_dir_entry **res_de,int *ino);
221     extern int fat_parent_ino(struct inode *dir,int locked);
222     extern int fat_subdirs(struct inode *dir);
223     void fat_clusters_flush(struct super_block *sb);
224     
225     /* fat.c */
226     extern int fat_access(struct super_block *sb,int nr,int new_value);
227     extern int fat_free(struct inode *inode,int skip);
228     void fat_cache_inval_inode(struct inode *inode);
229     void fat_cache_inval_dev(kdev_t device);
230     extern void fat_cache_init(void);
231     void fat_cache_lookup(struct inode *inode,int cluster,int *f_clu,int *d_clu);
232     void fat_cache_add(struct inode *inode,int f_clu,int d_clu);
233     int fat_get_cluster(struct inode *inode,int cluster);
234     
235     /* inode.c */
236     extern void fat_hash_init(void);
237     extern int fat_bmap(struct inode *inode,int block);
238     extern int fat_get_block(struct inode *, long, struct buffer_head *, int);
239     extern int fat_notify_change(struct dentry *, struct iattr *);
240     extern void fat_clear_inode(struct inode *inode);
241     extern void fat_delete_inode(struct inode *inode);
242     extern void fat_put_super(struct super_block *sb);
243     extern void fat_attach(struct inode *inode, int ino);
244     extern void fat_detach(struct inode *inode);
245     extern struct inode *fat_iget(struct super_block*,int);
246     extern struct inode *fat_build_inode(struct super_block*,struct msdos_dir_entry*,int,int*);
247     extern struct super_block *fat_read_super(struct super_block *s, void *data, int silent, struct inode_operations *dir_ops);
248     extern void msdos_put_super(struct super_block *sb);
249     extern int fat_statfs(struct super_block *sb,struct statfs *buf);
250     extern void fat_write_inode(struct inode *inode, int);
251     
252     /* dir.c */
253     extern struct file_operations fat_dir_operations;
254     extern int fat_search_long(struct inode *dir, const char *name, int len,
255     			   int anycase, loff_t *spos, loff_t *lpos);
256     extern int fat_readdir(struct file *filp,
257     		       void *dirent, filldir_t);
258     extern int fat_dir_ioctl(struct inode * inode, struct file * filp,
259     			 unsigned int cmd, unsigned long arg);
260     int fat_add_entries(struct inode *dir,int slots, struct buffer_head **bh,
261     		  struct msdos_dir_entry **de, int *ino);
262     int fat_dir_empty(struct inode *dir);
263     int fat_new_dir(struct inode *inode, struct inode *parent, int is_vfat);
264     
265     /* file.c */
266     extern struct inode_operations fat_file_inode_operations;
267     extern struct inode_operations fat_file_inode_operations_1024;
268     extern struct inode_operations fat_file_inode_operations_readpage;
269     extern struct file_operations fat_file_operations;
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);
273     
274     /* msdos.c */
275     extern struct super_block *msdos_read_super(struct super_block *sb,void *data, int silent);
276     
277     /* msdos.c - these are for Umsdos */
278     extern void msdos_read_inode(struct inode *inode);
279     extern struct dentry *msdos_lookup(struct inode *dir,struct dentry *);
280     extern int msdos_create(struct inode *dir,struct dentry *dentry,int mode);
281     extern int msdos_rmdir(struct inode *dir,struct dentry *dentry);
282     extern int msdos_mkdir(struct inode *dir,struct dentry *dentry,int mode);
283     extern int msdos_unlink(struct inode *dir,struct dentry *dentry);
284     extern int msdos_rename(struct inode *old_dir,struct dentry *old_dentry,
285     			struct inode *new_dir,struct dentry *new_dentry);
286     
287     /* nls.c */
288     extern struct fat_nls_table *fat_load_nls(int codepage);
289     
290     /* tables.c */
291     extern unsigned char fat_uni2esc[];
292     extern unsigned char fat_esc2uni[];
293     
294     /* fatfs_syms.c */
295     extern void cleanup_fat_fs(void);
296     
297     /* nls.c */
298     extern int fat_register_nls(struct fat_nls_table * fmt);
299     extern int fat_unregister_nls(struct fat_nls_table * fmt);
300     extern struct fat_nls_table *fat_find_nls(int codepage);
301     extern struct fat_nls_table *fat_load_nls(int codepage);
302     extern void fat_unload_nls(int codepage);
303     extern int init_fat_nls(void);
304     
305     /* vfat/namei.c - these are for dmsdos */
306     extern int vfat_create(struct inode *dir,struct dentry *dentry,int mode);
307     extern int vfat_unlink(struct inode *dir,struct dentry *dentry);
308     extern int vfat_mkdir(struct inode *dir,struct dentry *dentry,int mode);
309     extern int vfat_rmdir(struct inode *dir,struct dentry *dentry);
310     extern int vfat_rename(struct inode *old_dir,struct dentry *old_dentry,
311     		       struct inode *new_dir,struct dentry *new_dentry);
312     extern struct super_block *vfat_read_super(struct super_block *sb,void *data,
313     					   int silent);
314     extern void vfat_read_inode(struct inode *inode);
315     extern struct dentry *vfat_lookup(struct inode *dir,struct dentry *);
316     
317     /* vfat/vfatfs_syms.c */
318     extern struct file_system_type vfat_fs_type;
319     
320     #endif /* __KERNEL__ */
321     
322     #endif
323