Import 2.1.42pre1
[davej-history.git] / include / linux / msdos_fs.h
blobd7f46b1d8bb72b38ff84aa7cb726e86effd3bf92
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>
10 #include <linux/config.h>
12 #include <asm/byteorder.h>
14 #define MSDOS_ROOT_INO 1 /* == MINIX_ROOT_INO */
15 #define SECTOR_SIZE 512 /* sector size (bytes) */
16 #define SECTOR_BITS 9 /* log2(SECTOR_SIZE) */
17 #define MSDOS_DPB (MSDOS_DPS) /* dir entries per block */
18 #define MSDOS_DPB_BITS 4 /* log2(MSDOS_DPB) */
19 #define MSDOS_DPS (SECTOR_SIZE/sizeof(struct msdos_dir_entry))
20 #define MSDOS_DPS_BITS 4 /* log2(MSDOS_DPS) */
21 #define MSDOS_DIR_BITS 5 /* log2(sizeof(struct msdos_dir_entry)) */
23 #define MSDOS_SUPER_MAGIC 0x4d44 /* MD */
25 #define FAT_CACHE 8 /* FAT cache size */
27 #define MSDOS_MAX_EXTRA 3 /* tolerate up to that number of clusters which are
28 inaccessible because the FAT is too short */
30 #define ATTR_RO 1 /* read-only */
31 #define ATTR_HIDDEN 2 /* hidden */
32 #define ATTR_SYS 4 /* system */
33 #define ATTR_VOLUME 8 /* volume label */
34 #define ATTR_DIR 16 /* directory */
35 #define ATTR_ARCH 32 /* archived */
37 #define ATTR_NONE 0 /* no attribute bits */
38 #define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
39 /* attribute bits that are copied "as is" */
40 #define ATTR_EXT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
41 /* bits that are used by the Windows 95/Windows NT extended FAT */
43 #define ATTR_DIR_READ_BOTH 512 /* read both short and long names from the
44 * vfat filesystem. This is used by Samba
45 * to export the vfat filesystem with correct
46 * shortnames. */
47 #define ATTR_DIR_READ_SHORT 1024
49 #define CASE_LOWER_BASE 8 /* base is lower case */
50 #define CASE_LOWER_EXT 16 /* extension is lower case */
52 #define SCAN_ANY 0 /* either hidden or not */
53 #define SCAN_HID 1 /* only hidden */
54 #define SCAN_NOTHID 2 /* only not hidden */
55 #define SCAN_NOTANY 3 /* test name, then use SCAN_HID or SCAN_NOTHID */
57 #define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
58 #define IS_FREE(n) (!*(n) || *(const unsigned char *) (n) == DELETED_FLAG || \
59 *(const unsigned char *) (n) == FD_FILL_BYTE)
61 #define MSDOS_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)
62 /* valid file mode bits */
64 #define MSDOS_SB(s) (&((s)->u.msdos_sb))
65 #define MSDOS_I(i) (&((i)->u.msdos_i))
67 #define MSDOS_NAME 11 /* maximum name length */
68 #define MSDOS_LONGNAME 256 /* maximum name length */
69 #define MSDOS_SLOTS 21 /* max # of slots needed for short and long names */
70 #define MSDOS_DOT ". " /* ".", padded to MSDOS_NAME chars */
71 #define MSDOS_DOTDOT ".. " /* "..", padded to MSDOS_NAME chars */
73 #define MSDOS_FAT12 4078 /* maximum number of clusters in a 12 bit FAT */
75 #ifdef CONFIG_ATARI
76 #define EOF_FAT12 0xFFF /* Atari GEMDOS fs uses a different EOF */
77 #define EOF_FAT16 0xFFFF
78 #else
79 #define EOF_FAT12 0xFF8 /* standard EOF */
80 #define EOF_FAT16 0xFFF8
81 #endif
84 * Inode flags
86 #define FAT_BINARY_FL 0x00000001 /* File contains binary data */
89 * ioctl commands
91 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, long)
92 #define VFAT_IOCTL_READDIR_SHORT _IOW('r', 2, long)
95 * Conversion from and to little-endian byte order. (no-op on i386/i486)
97 * Naming: Ca_b_c, where a: F = from, T = to, b: LE = little-endian,
98 * BE = big-endian, c: W = word (16 bits), L = longword (32 bits)
101 #define CF_LE_W(v) le16_to_cpu(v)
102 #define CF_LE_L(v) le32_to_cpu(v)
103 #define CT_LE_W(v) cpu_to_le16(v)
104 #define CT_LE_L(v) cpu_to_le32(v)
106 struct msdos_boot_sector {
107 __s8 ignored[3]; /* Boot strap short or near jump */
108 __s8 system_id[8]; /* Name - can be used to special case
109 partition manager volumes */
110 __u8 sector_size[2]; /* bytes per logical sector */
111 __u8 cluster_size; /* sectors/cluster */
112 __u16 reserved; /* reserved sectors */
113 __u8 fats; /* number of FATs */
114 __u8 dir_entries[2]; /* root directory entries */
115 __u8 sectors[2]; /* number of sectors */
116 __u8 media; /* media code (unused) */
117 __u16 fat_length; /* sectors/FAT */
118 __u16 secs_track; /* sectors per track */
119 __u16 heads; /* number of heads */
120 __u32 hidden; /* hidden sectors (unused) */
121 __u32 total_sect; /* number of sectors (if sectors == 0) */
124 struct msdos_dir_entry {
125 __s8 name[8],ext[3]; /* name and extension */
126 __u8 attr; /* attribute bits */
127 __u8 lcase; /* Case for base and extension */
128 __u8 ctime_ms; /* Creation time, milliseconds */
129 __u16 ctime; /* Creation time */
130 __u16 cdate; /* Creation date */
131 __u16 adate; /* Last access date */
132 __u8 unused[2];
133 __u16 time,date,start;/* time, date and first cluster */
134 __u32 size; /* file size (in bytes) */
137 /* Up to 13 characters of the name */
138 struct msdos_dir_slot {
139 __u8 id; /* sequence number for slot */
140 __u8 name0_4[10]; /* first 5 characters in name */
141 __u8 attr; /* attribute byte */
142 __u8 reserved; /* always 0 */
143 __u8 alias_checksum; /* checksum for 8.3 alias */
144 __u8 name5_10[12]; /* 6 more characters in name */
145 __u8 start[2]; /* starting cluster number */
146 __u8 name11_12[4]; /* last 2 characters in name */
149 struct slot_info {
150 int is_long; /* was the found entry long */
151 int long_slots; /* number of long slots in filename */
152 int total_slots; /* total slots (long and short) */
153 loff_t longname_offset; /* dir offset for longname start */
154 loff_t shortname_offset; /* dir offset for shortname start */
155 int ino; /* ino for the file */
158 /* Determine whether this FS has kB-aligned data. */
159 #define MSDOS_CAN_BMAP(mib) (!(((mib)->cluster_size & 1) || \
160 ((mib)->data_start & 1)))
162 /* Convert attribute bits and a mask to the UNIX mode. */
163 #define MSDOS_MKMODE(a,m) (m & (a & ATTR_RO ? S_IRUGO|S_IXUGO : S_IRWXUGO))
165 /* Convert the UNIX mode to MS-DOS attribute bits. */
166 #define MSDOS_MKATTR(m) ((m & S_IWUGO) ? ATTR_NONE : ATTR_RO)
169 #ifdef __KERNEL__
171 typedef int (*fat_filldir_t)(filldir_t filldir, void *, const char *,
172 int, int, off_t, off_t, int, ino_t);
174 struct fat_cache {
175 kdev_t device; /* device number. 0 means unused. */
176 int ino; /* inode number. */
177 int file_cluster; /* cluster number in the file. */
178 int disk_cluster; /* cluster number on disk. */
179 struct fat_cache *next; /* next cache entry */
182 /* misc.c */
183 extern int is_binary(char conversion,char *extension);
184 extern void lock_fat(struct super_block *sb);
185 extern void unlock_fat(struct super_block *sb);
186 extern int fat_add_cluster(struct inode *inode);
187 extern int date_dos2unix(__u16 time, __u16 date);
188 extern void fat_fs_panic(struct super_block *s,const char *msg);
189 extern void fat_lock_creation(void);
190 extern void fat_unlock_creation(void);
191 extern void fat_date_unix2dos(int unix_date,__u16 *time, __u16 *date);
192 extern int fat_get_entry(struct inode *dir,loff_t *pos,struct buffer_head **bh,
193 struct msdos_dir_entry **de);
194 extern int fat_scan(struct inode *dir,const char *name,struct buffer_head **res_bh,
195 struct msdos_dir_entry **res_de,int *ino,char scantype);
196 extern int fat_parent_ino(struct inode *dir,int locked);
197 extern int fat_subdirs(struct inode *dir);
199 /* fat.c */
200 extern int fat_access(struct super_block *sb,int nr,int new_value);
201 extern int fat_smap(struct inode *inode,int sector);
202 extern int fat_free(struct inode *inode,int skip);
203 void fat_cache_inval_inode(struct inode *inode);
204 void fat_cache_inval_dev(kdev_t device);
205 extern void cache_init(void);
206 void cache_lookup(struct inode *inode,int cluster,int *f_clu,int *d_clu);
207 void cache_add(struct inode *inode,int f_clu,int d_clu);
208 int get_cluster(struct inode *inode,int cluster);
210 /* inode.c */
211 extern int fat_bmap(struct inode *inode,int block);
212 extern int fat_notify_change(struct inode *,struct iattr *);
213 extern void fat_put_inode(struct inode *inode);
214 extern void fat_put_super(struct super_block *sb);
215 extern void fat_read_inode(struct inode *inode, struct inode_operations *dir_ops);
216 extern struct super_block *fat_read_super(struct super_block *s, void *data, int silent);
217 extern void msdos_put_super(struct super_block *sb);
218 extern void fat_statfs(struct super_block *sb,struct statfs *buf, int);
219 extern void fat_write_inode(struct inode *inode);
221 /* dir.c */
222 extern struct file_operations fat_dir_operations;
223 extern int fat_readdirx(struct inode *inode, struct file *filp, void *dirent,
224 fat_filldir_t fat_filldir, filldir_t filldir,
225 int shortnames, int longnames, int both);
226 extern int fat_readdir(struct inode *inode, struct file *filp,
227 void *dirent, filldir_t);
228 extern int fat_dir_ioctl(struct inode * inode, struct file * filp,
229 unsigned int cmd, unsigned long arg);
231 /* file.c */
232 extern struct inode_operations fat_file_inode_operations;
233 extern struct inode_operations fat_file_inode_operations_1024;
234 extern long fat_file_read(struct inode *, struct file *, char *, unsigned long);
235 extern long fat_file_write(struct inode *, struct file *, const char *, unsigned long);
236 extern void fat_truncate(struct inode *inode);
238 /* mmap.c */
239 extern int fat_mmap(struct inode *, struct file *, struct vm_area_struct *);
242 /* vfat.c */
243 extern int init_vfat_fs(void);
246 /* msdosfs_syms.c */
247 extern int init_msdos_fs(void);
248 extern struct file_system_type msdos_fs_type;
250 /* msdos.c */
251 extern struct super_block *msdos_read_super(struct super_block *sb,void *data, int silent);
253 /* msdos.c - these are for Umsdos */
254 extern void msdos_read_inode(struct inode *inode);
255 extern int msdos_lookup(struct inode *dir,const char *name,int len,
256 struct inode **result);
257 extern int msdos_create(struct inode *dir,const char *name,int len,int mode,
258 struct inode **result);
259 extern int msdos_rmdir(struct inode *dir,const char *name,int len);
260 extern int msdos_mkdir(struct inode *dir,const char *name,int len,int mode);
261 extern int msdos_unlink(struct inode *dir,const char *name,int len);
262 extern int msdos_unlink_umsdos(struct inode *dir,const char *name,int len);
263 extern int msdos_rename(struct inode *old_dir,const char *old_name,int old_len,
264 struct inode *new_dir,const char *new_name,int new_len,
265 int must_be_dir);
267 /* fatfs_syms.c */
268 extern int init_fat_fs(void);
270 /* vfat/namei.c - these are for dmsdos */
271 extern int vfat_create(struct inode *dir,const char *name,int len,int mode,
272 struct inode **result);
273 extern int vfat_unlink(struct inode *dir,const char *name,int len);
274 extern int vfat_mkdir(struct inode *dir,const char *name,int len,int mode);
275 extern int vfat_rmdir(struct inode *dir,const char *name,int len);
276 extern int vfat_rename(struct inode *old_dir,const char *old_name,int old_len,
277 struct inode *new_dir,const char *new_name,int new_len,
278 int must_be_dir);
279 extern void vfat_put_super(struct super_block *sb);
280 extern struct super_block *vfat_read_super(struct super_block *sb,void *data,
281 int silent);
282 extern void vfat_read_inode(struct inode *inode);
283 extern int vfat_lookup(struct inode *dir,const char *name,int len,
284 struct inode **result);
286 #endif /* __KERNEL__ */
288 #endif