Subversion Repositories shark

Rev

Rev 422 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
422 giacomo 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/buffer_head.h>
8
#include <linux/string.h>
9
#include <asm/byteorder.h>
10
 
11
struct statfs;
12
 
13
 
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
 
21
#define MSDOS_ROOT_INO  1       /* == MINIX_ROOT_INO */
22
#define MSDOS_DIR_BITS  5       /* log2(sizeof(struct msdos_dir_entry)) */
23
 
24
/* directory limit */
25
#define FAT_MAX_DIR_ENTRIES     (65536)
26
#define FAT_MAX_DIR_SIZE        (FAT_MAX_DIR_ENTRIES << MSDOS_DIR_BITS)
27
 
28
#define MSDOS_SUPER_MAGIC 0x4d44 /* MD */
29
 
30
#define ATTR_NONE    0 /* no attribute bits */
31
#define ATTR_RO      1  /* read-only */
32
#define ATTR_HIDDEN  2  /* hidden */
33
#define ATTR_SYS     4  /* system */
34
#define ATTR_VOLUME  8  /* volume label */
35
#define ATTR_DIR     16 /* directory */
36
#define ATTR_ARCH    32 /* archived */
37
 
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 */
42
 
43
#define CASE_LOWER_BASE 8       /* base is lower case */
44
#define CASE_LOWER_EXT  16      /* extension is lower case */
45
 
46
#define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
47
#define IS_FREE(n) (!*(n) || *(n) == DELETED_FLAG)
48
 
49
#define MSDOS_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)
50
        /* valid file mode bits */
51
 
52
#define MSDOS_NAME 11 /* maximum name length */
53
#define MSDOS_LONGNAME 256 /* maximum name length */
54
#define MSDOS_SLOTS 21  /* max # of slots needed for short and long names */
55
#define MSDOS_DOT    ".          " /* ".", padded to MSDOS_NAME chars */
56
#define MSDOS_DOTDOT "..         " /* "..", padded to MSDOS_NAME chars */
57
 
58
#define MSDOS_FAT12 4084 /* maximum number of clusters in a 12 bit FAT */
59
 
60
/* media of boot sector */
61
#define FAT_VALID_MEDIA(x)      ((0xF8 <= (x) && (x) <= 0xFF) || (x) == 0xF0)
62
#define FAT_FIRST_ENT(s, x)     ((MSDOS_SB(s)->fat_bits == 32 ? 0x0FFFFF00 : \
63
        MSDOS_SB(s)->fat_bits == 16 ? 0xFF00 : 0xF00) | (x))
64
 
65
/* bad cluster mark */
66
#define BAD_FAT12 0xFF7
67
#define BAD_FAT16 0xFFF7
68
#define BAD_FAT32 0xFFFFFF7
69
#define BAD_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? BAD_FAT32 : \
70
        MSDOS_SB(s)->fat_bits == 16 ? BAD_FAT16 : BAD_FAT12)
71
 
72
/* standard EOF */
73
#define EOF_FAT12 0xFFF
74
#define EOF_FAT16 0xFFFF
75
#define EOF_FAT32 0xFFFFFFF
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_ENT_FREE    (0)
80
#define FAT_ENT_BAD     (BAD_FAT32)
81
#define FAT_ENT_EOF     (EOF_FAT32)
82
 
83
#define FAT_FSINFO_SIG1         0x41615252
84
#define FAT_FSINFO_SIG2         0x61417272
85
#define IS_FSINFO(x)    (CF_LE_L((x)->signature1) == FAT_FSINFO_SIG1    \
86
                         && CF_LE_L((x)->signature2) == FAT_FSINFO_SIG2)
87
 
88
/*
89
 * ioctl commands
90
 */
91
#define VFAT_IOCTL_READDIR_BOTH         _IOR('r', 1, struct dirent [2])
92
#define VFAT_IOCTL_READDIR_SHORT        _IOR('r', 2, struct dirent [2])
93
 
94
/*
95
 * vfat shortname flags
96
 */
97
#define VFAT_SFN_DISPLAY_LOWER  0x0001 /* convert to lowercase for display */
98
#define VFAT_SFN_DISPLAY_WIN95  0x0002 /* emulate win95 rule for display */
99
#define VFAT_SFN_DISPLAY_WINNT  0x0004 /* emulate winnt rule for display */
100
#define VFAT_SFN_CREATE_WIN95   0x0100 /* emulate win95 rule for create */
101
#define VFAT_SFN_CREATE_WINNT   0x0200 /* emulate winnt rule for create */
102
 
103
/*
104
 * Conversion from and to little-endian byte order. (no-op on i386/i486)
105
 *
106
 * Naming: Ca_b_c, where a: F = from, T = to, b: LE = little-endian,
107
 * BE = big-endian, c: W = word (16 bits), L = longword (32 bits)
108
 */
109
 
110
#define CF_LE_W(v) le16_to_cpu(v)
111
#define CF_LE_L(v) le32_to_cpu(v)
112
#define CT_LE_W(v) cpu_to_le16(v)
113
#define CT_LE_L(v) cpu_to_le32(v)
114
 
115
struct fat_boot_sector {
116
        __u8    ignored[3];     /* Boot strap short or near jump */
117
        __u8    system_id[8];   /* Name - can be used to special case
118
                                   partition manager volumes */
119
        __u8    sector_size[2]; /* bytes per logical sector */
120
        __u8    sec_per_clus;   /* sectors/cluster */
121
        __u16   reserved;       /* reserved sectors */
122
        __u8    fats;           /* number of FATs */
123
        __u8    dir_entries[2]; /* root directory entries */
124
        __u8    sectors[2];     /* number of sectors */
125
        __u8    media;          /* media code */
126
        __u16   fat_length;     /* sectors/FAT */
127
        __u16   secs_track;     /* sectors per track */
128
        __u16   heads;          /* number of heads */
129
        __u32   hidden;         /* hidden sectors (unused) */
130
        __u32   total_sect;     /* number of sectors (if sectors == 0) */
131
 
132
        /* The following fields are only used by FAT32 */
133
        __u32   fat32_length;   /* sectors/FAT */
134
        __u16   flags;          /* bit 8: fat mirroring, low 4: active fat */
135
        __u8    version[2];     /* major, minor filesystem version */
136
        __u32   root_cluster;   /* first cluster in root directory */
137
        __u16   info_sector;    /* filesystem info sector */
138
        __u16   backup_boot;    /* backup boot sector */
139
        __u16   reserved2[6];   /* Unused */
140
};
141
 
142
struct fat_boot_fsinfo {
143
        __u32   signature1;     /* 0x41615252L */
144
        __u32   reserved1[120]; /* Nothing as far as I can tell */
145
        __u32   signature2;     /* 0x61417272L */
146
        __u32   free_clusters;  /* Free cluster count.  -1 if unknown */
147
        __u32   next_cluster;   /* Most recently allocated cluster */
148
        __u32   reserved2[4];
149
};
150
 
151
struct msdos_dir_entry {
152
        __u8    name[8],ext[3]; /* name and extension */
153
        __u8    attr;           /* attribute bits */
154
        __u8    lcase;          /* Case for base and extension */
155
        __u8    ctime_ms;       /* Creation time, milliseconds */
156
        __u16   ctime;          /* Creation time */
157
        __u16   cdate;          /* Creation date */
158
        __u16   adate;          /* Last access date */
159
        __u16   starthi;        /* High 16 bits of cluster in FAT32 */
160
        __u16   time,date,start;/* time, date and first cluster */
161
        __u32   size;           /* file size (in bytes) */
162
};
163
 
164
/* Up to 13 characters of the name */
165
struct msdos_dir_slot {
166
        __u8    id;             /* sequence number for slot */
167
        __u8    name0_4[10];    /* first 5 characters in name */
168
        __u8    attr;           /* attribute byte */
169
        __u8    reserved;       /* always 0 */
170
        __u8    alias_checksum; /* checksum for 8.3 alias */
171
        __u8    name5_10[12];   /* 6 more characters in name */
172
        __u16   start;          /* starting cluster number, 0 in long slots */
173
        __u8    name11_12[4];   /* last 2 characters in name */
174
};
175
 
176
struct vfat_slot_info {
177
        int long_slots;                /* number of long slots in filename */
178
        loff_t longname_offset;        /* dir offset for longname start */
179
        loff_t i_pos;                  /* on-disk position of directory entry */
180
};
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
#include <linux/nls.h>
192
#include <linux/msdos_fs_i.h>
193
#include <linux/msdos_fs_sb.h>
194
 
195
static inline struct msdos_sb_info *MSDOS_SB(struct super_block *sb)
196
{
197
        return sb->s_fs_info;
198
}
199
 
200
static inline struct msdos_inode_info *MSDOS_I(struct inode *inode)
201
{
202
        return container_of(inode, struct msdos_inode_info, vfs_inode);
203
}
204
 
205
static inline void fat16_towchar(wchar_t *dst, const __u8 *src, size_t len)
206
{
207
#ifdef __BIG_ENDIAN
208
        while (len--) {
209
                *dst++ = src[0] | (src[1] << 8);
210
                src += 2;
211
        }
212
#else
213
        memcpy(dst, src, len * 2);
214
#endif
215
}
216
 
217
static inline void fatwchar_to16(__u8 *dst, const wchar_t *src, size_t len)
218
{
219
#ifdef __BIG_ENDIAN
220
        while (len--) {
221
                dst[0] = *src & 0x00FF;
222
                dst[1] = (*src & 0xFF00) >> 8;
223
                dst += 2;
224
                src++;
225
        }
226
#else
227
        memcpy(dst, src, len * 2);
228
#endif
229
}
230
 
231
/* fat/cache.c */
232
extern int fat_access(struct super_block *sb, int nr, int new_value);
233
extern int __fat_access(struct super_block *sb, int nr, int new_value);
234
extern int fat_bmap(struct inode *inode, sector_t sector, sector_t *phys);
235
extern void fat_cache_init(struct super_block *sb);
236
extern void fat_cache_lookup(struct inode *inode, int cluster, int *f_clu,
237
                             int *d_clu);
238
extern void fat_cache_add(struct inode *inode, int f_clu, int d_clu);
239
extern void fat_cache_inval_inode(struct inode *inode);
240
extern int fat_get_cluster(struct inode *inode, int cluster,
241
                           int *fclus, int *dclus);
242
extern int fat_free(struct inode *inode, int skip);
243
 
244
/* fat/dir.c */
245
extern struct file_operations fat_dir_operations;
246
extern int fat_search_long(struct inode *inode, const unsigned char *name,
247
                           int name_len, int anycase,
248
                           loff_t *spos, loff_t *lpos);
249
extern int fat_readdir(struct file *filp, void *dirent, filldir_t filldir);
250
extern int fat_dir_ioctl(struct inode * inode, struct file * filp,
251
                         unsigned int cmd, unsigned long arg);
252
extern int fat_add_entries(struct inode *dir, int slots, struct buffer_head **bh,
253
                        struct msdos_dir_entry **de, loff_t *i_pos);
254
extern int fat_new_dir(struct inode *dir, struct inode *parent, int is_vfat);
255
extern int fat_dir_empty(struct inode *dir);
256
extern int fat_subdirs(struct inode *dir);
257
extern int fat_scan(struct inode *dir, const unsigned char *name,
258
                    struct buffer_head **res_bh,
259
                    struct msdos_dir_entry **res_de, loff_t *i_pos);
260
 
261
/* fat/file.c */
262
extern struct file_operations fat_file_operations;
263
extern struct inode_operations fat_file_inode_operations;
264
extern int fat_get_block(struct inode *inode, sector_t iblock,
265
                         struct buffer_head *bh_result, int create);
266
extern void fat_truncate(struct inode *inode);
267
 
268
/* fat/inode.c */
269
extern void fat_hash_init(void);
270
extern void fat_attach(struct inode *inode, loff_t i_pos);
271
extern void fat_detach(struct inode *inode);
272
extern struct inode *fat_iget(struct super_block *sb, loff_t i_pos);
273
extern struct inode *fat_build_inode(struct super_block *sb,
274
                        struct msdos_dir_entry *de, loff_t i_pos, int *res);
275
extern void fat_delete_inode(struct inode *inode);
276
extern void fat_clear_inode(struct inode *inode);
277
extern void fat_put_super(struct super_block *sb);
278
int fat_fill_super(struct super_block *sb, void *data, int silent,
279
                   struct inode_operations *fs_dir_inode_ops, int isvfat);
280
extern int fat_statfs(struct super_block *sb, struct kstatfs *buf);
281
extern void fat_write_inode(struct inode *inode, int wait);
282
extern int fat_notify_change(struct dentry * dentry, struct iattr * attr);
283
 
284
/* fat/misc.c */
285
extern void fat_fs_panic(struct super_block *s, const char *fmt, ...);
286
extern void lock_fat(struct super_block *sb);
287
extern void unlock_fat(struct super_block *sb);
288
extern void fat_clusters_flush(struct super_block *sb);
289
extern int fat_add_cluster(struct inode *inode);
290
extern struct buffer_head *fat_extend_dir(struct inode *inode);
291
extern int date_dos2unix(unsigned short time, unsigned short date);
292
extern void fat_date_unix2dos(int unix_date, unsigned short *time,
293
                              unsigned short *date);
294
extern int fat__get_entry(struct inode *dir, loff_t *pos,
295
                          struct buffer_head **bh,
296
                          struct msdos_dir_entry **de, loff_t *i_pos);
297
static __inline__ int fat_get_entry(struct inode *dir, loff_t *pos,
298
                                    struct buffer_head **bh,
299
                                    struct msdos_dir_entry **de, loff_t *i_pos)
300
{
301
        /* Fast stuff first */
302
        if (*bh && *de &&
303
            (*de - (struct msdos_dir_entry *)(*bh)->b_data) < MSDOS_SB(dir->i_sb)->dir_per_block - 1) {
304
                *pos += sizeof(struct msdos_dir_entry);
305
                (*de)++;
306
                (*i_pos)++;
307
                return 0;
308
        }
309
        return fat__get_entry(dir, pos, bh, de, i_pos);
310
}
311
 
312
/* msdos/namei.c  - these are for Umsdos */
313
extern struct dentry *msdos_lookup(struct inode *dir, struct dentry *, struct nameidata *);
314
extern int msdos_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *);
315
extern int msdos_rmdir(struct inode *dir, struct dentry *dentry);
316
extern int msdos_mkdir(struct inode *dir, struct dentry *dentry, int mode);
317
extern int msdos_unlink(struct inode *dir, struct dentry *dentry);
318
extern int msdos_rename(struct inode *old_dir, struct dentry *old_dentry,
319
                        struct inode *new_dir, struct dentry *new_dentry);
320
extern int msdos_fill_super(struct super_block *sb, void *data, int silent);
321
 
322
/* vfat/namei.c - these are for dmsdos */
323
extern struct dentry *vfat_lookup(struct inode *dir, struct dentry *, struct nameidata *);
324
extern int vfat_create(struct inode *dir, struct dentry *dentry, int mode, struct nameidata *);
325
extern int vfat_rmdir(struct inode *dir, struct dentry *dentry);
326
extern int vfat_unlink(struct inode *dir, struct dentry *dentry);
327
extern int vfat_mkdir(struct inode *dir, struct dentry *dentry, int mode);
328
extern int vfat_rename(struct inode *old_dir, struct dentry *old_dentry,
329
                       struct inode *new_dir, struct dentry *new_dentry);
330
extern int vfat_fill_super(struct super_block *sb, void *data, int silent);
331
 
332
/* vfat/vfatfs_syms.c */
333
extern struct file_system_type vfat_fs_type;
334
 
335
#endif /* __KERNEL__ */
336
 
337
#endif