1 #ifndef _LINUX_MSDOS_FS_H
2 #define _LINUX_MSDOS_FS_H
5 * The MS-DOS filesystem constants/structures
7 #include <asm/byteorder.h>
9 #define SECTOR_SIZE 512 /* sector size (bytes) */
10 #define SECTOR_BITS 9 /* log2(SECTOR_SIZE) */
11 #define MSDOS_DPB (MSDOS_DPS) /* dir entries per block */
12 #define MSDOS_DPB_BITS 4 /* log2(MSDOS_DPB) */
13 #define MSDOS_DPS (SECTOR_SIZE / sizeof(struct msdos_dir_entry))
14 #define MSDOS_DPS_BITS 4 /* log2(MSDOS_DPS) */
17 #define MSDOS_SUPER_MAGIC 0x4d44 /* MD */
19 #define MSDOS_ROOT_INO 1 /* == MINIX_ROOT_INO */
20 #define MSDOS_DIR_BITS 5 /* log2(sizeof(struct msdos_dir_entry)) */
23 #define FAT_MAX_DIR_ENTRIES (65536)
24 #define FAT_MAX_DIR_SIZE (FAT_MAX_DIR_ENTRIES << MSDOS_DIR_BITS)
26 #define ATTR_NONE 0 /* no attribute bits */
27 #define ATTR_RO 1 /* read-only */
28 #define ATTR_HIDDEN 2 /* hidden */
29 #define ATTR_SYS 4 /* system */
30 #define ATTR_VOLUME 8 /* volume label */
31 #define ATTR_DIR 16 /* directory */
32 #define ATTR_ARCH 32 /* archived */
34 /* attribute bits that are copied "as is" */
35 #define ATTR_UNUSED (ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
36 /* bits that are used by the Windows 95/Windows NT extended FAT */
37 #define ATTR_EXT (ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
39 #define CASE_LOWER_BASE 8 /* base is lower case */
40 #define CASE_LOWER_EXT 16 /* extension is lower case */
42 #define DELETED_FLAG 0xe5 /* marks file as deleted when in name[0] */
43 #define IS_FREE(n) (!*(n) || *(n) == DELETED_FLAG)
45 /* valid file mode bits */
46 #define MSDOS_VALID_MODE (S_IFREG | S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO)
47 /* Convert attribute bits and a mask to the UNIX mode. */
48 #define MSDOS_MKMODE(a, m) (m & (a & ATTR_RO ? S_IRUGO|S_IXUGO : S_IRWXUGO))
49 /* Convert the UNIX mode to MS-DOS attribute bits. */
50 #define MSDOS_MKATTR(m) ((m & S_IWUGO) ? ATTR_NONE : ATTR_RO)
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 */
58 /* media of boot sector */
59 #define FAT_VALID_MEDIA(x) ((0xF8 <= (x) && (x) <= 0xFF) || (x) == 0xF0)
60 #define FAT_FIRST_ENT(s, x) ((MSDOS_SB(s)->fat_bits == 32 ? 0x0FFFFF00 : \
61 MSDOS_SB(s)->fat_bits == 16 ? 0xFF00 : 0xF00) | (x))
63 /* maximum number of clusters */
64 #define MAX_FAT12 0xFF4
65 #define MAX_FAT16 0xFFF4
66 #define MAX_FAT32 0x0FFFFFF6
67 #define MAX_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? MAX_FAT32 : \
68 MSDOS_SB(s)->fat_bits == 16 ? MAX_FAT16 : MAX_FAT12)
70 /* bad cluster mark */
71 #define BAD_FAT12 0xFF7
72 #define BAD_FAT16 0xFFF7
73 #define BAD_FAT32 0x0FFFFFF7
74 #define BAD_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? BAD_FAT32 : \
75 MSDOS_SB(s)->fat_bits == 16 ? BAD_FAT16 : BAD_FAT12)
78 #define EOF_FAT12 0xFFF
79 #define EOF_FAT16 0xFFFF
80 #define EOF_FAT32 0x0FFFFFFF
81 #define EOF_FAT(s) (MSDOS_SB(s)->fat_bits == 32 ? EOF_FAT32 : \
82 MSDOS_SB(s)->fat_bits == 16 ? EOF_FAT16 : EOF_FAT12)
84 #define FAT_ENT_FREE (0)
85 #define FAT_ENT_BAD (BAD_FAT32)
86 #define FAT_ENT_EOF (EOF_FAT32)
88 #define FAT_FSINFO_SIG1 0x41615252
89 #define FAT_FSINFO_SIG2 0x61417272
90 #define IS_FSINFO(x) (CF_LE_L((x)->signature1) == FAT_FSINFO_SIG1 \
91 && CF_LE_L((x)->signature2) == FAT_FSINFO_SIG2)
96 #define VFAT_IOCTL_READDIR_BOTH _IOR('r', 1, struct dirent [2])
97 #define VFAT_IOCTL_READDIR_SHORT _IOR('r', 2, struct dirent [2])
100 * vfat shortname flags
102 #define VFAT_SFN_DISPLAY_LOWER 0x0001 /* convert to lowercase for display */
103 #define VFAT_SFN_DISPLAY_WIN95 0x0002 /* emulate win95 rule for display */
104 #define VFAT_SFN_DISPLAY_WINNT 0x0004 /* emulate winnt rule for display */
105 #define VFAT_SFN_CREATE_WIN95 0x0100 /* emulate win95 rule for create */
106 #define VFAT_SFN_CREATE_WINNT 0x0200 /* emulate winnt rule for create */
109 * Conversion from and to little-endian byte order. (no-op on i386/i486)
111 * Naming: Ca_b_c, where a: F = from, T = to, b: LE = little-endian,
112 * BE = big-endian, c: W = word (16 bits), L = longword (32 bits)
115 #define CF_LE_W(v) le16_to_cpu(v)
116 #define CF_LE_L(v) le32_to_cpu(v)
117 #define CT_LE_W(v) cpu_to_le16(v)
118 #define CT_LE_L(v) cpu_to_le32(v)
120 struct fat_boot_sector
{
121 __u8 ignored
[3]; /* Boot strap short or near jump */
122 __u8 system_id
[8]; /* Name - can be used to special case
123 partition manager volumes */
124 __u8 sector_size
[2]; /* bytes per logical sector */
125 __u8 sec_per_clus
; /* sectors/cluster */
126 __le16 reserved
; /* reserved sectors */
127 __u8 fats
; /* number of FATs */
128 __u8 dir_entries
[2]; /* root directory entries */
129 __u8 sectors
[2]; /* number of sectors */
130 __u8 media
; /* media code */
131 __le16 fat_length
; /* sectors/FAT */
132 __le16 secs_track
; /* sectors per track */
133 __le16 heads
; /* number of heads */
134 __le32 hidden
; /* hidden sectors (unused) */
135 __le32 total_sect
; /* number of sectors (if sectors == 0) */
137 /* The following fields are only used by FAT32 */
138 __le32 fat32_length
; /* sectors/FAT */
139 __le16 flags
; /* bit 8: fat mirroring, low 4: active fat */
140 __u8 version
[2]; /* major, minor filesystem version */
141 __le32 root_cluster
; /* first cluster in root directory */
142 __le16 info_sector
; /* filesystem info sector */
143 __le16 backup_boot
; /* backup boot sector */
144 __le16 reserved2
[6]; /* Unused */
147 struct fat_boot_fsinfo
{
148 __le32 signature1
; /* 0x41615252L */
149 __le32 reserved1
[120]; /* Nothing as far as I can tell */
150 __le32 signature2
; /* 0x61417272L */
151 __le32 free_clusters
; /* Free cluster count. -1 if unknown */
152 __le32 next_cluster
; /* Most recently allocated cluster */
156 struct msdos_dir_entry
{
157 __u8 name
[8],ext
[3]; /* name and extension */
158 __u8 attr
; /* attribute bits */
159 __u8 lcase
; /* Case for base and extension */
160 __u8 ctime_ms
; /* Creation time, milliseconds */
161 __le16 ctime
; /* Creation time */
162 __le16 cdate
; /* Creation date */
163 __le16 adate
; /* Last access date */
164 __le16 starthi
; /* High 16 bits of cluster in FAT32 */
165 __le16 time
,date
,start
;/* time, date and first cluster */
166 __le32 size
; /* file size (in bytes) */
169 /* Up to 13 characters of the name */
170 struct msdos_dir_slot
{
171 __u8 id
; /* sequence number for slot */
172 __u8 name0_4
[10]; /* first 5 characters in name */
173 __u8 attr
; /* attribute byte */
174 __u8 reserved
; /* always 0 */
175 __u8 alias_checksum
; /* checksum for 8.3 alias */
176 __u8 name5_10
[12]; /* 6 more characters in name */
177 __le16 start
; /* starting cluster number, 0 in long slots */
178 __u8 name11_12
[4]; /* last 2 characters in name */
181 struct vfat_slot_info
{
182 int long_slots
; /* number of long slots in filename */
183 loff_t longname_offset
; /* dir offset for longname start */
184 loff_t i_pos
; /* on-disk position of directory entry */
189 #include <linux/buffer_head.h>
190 #include <linux/string.h>
191 #include <linux/nls.h>
192 #include <linux/msdos_fs_i.h>
193 #include <linux/msdos_fs_sb.h>
195 static inline struct msdos_sb_info
*MSDOS_SB(struct super_block
*sb
)
197 return sb
->s_fs_info
;
200 static inline struct msdos_inode_info
*MSDOS_I(struct inode
*inode
)
202 return container_of(inode
, struct msdos_inode_info
, vfs_inode
);
205 static inline void fat16_towchar(wchar_t *dst
, const __u8
*src
, size_t len
)
209 *dst
++ = src
[0] | (src
[1] << 8);
213 memcpy(dst
, src
, len
* 2);
217 static inline void fatwchar_to16(__u8
*dst
, const wchar_t *src
, size_t len
)
221 dst
[0] = *src
& 0x00FF;
222 dst
[1] = (*src
& 0xFF00) >> 8;
227 memcpy(dst
, src
, len
* 2);
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_add(struct inode
*inode
, int f_clu
, int d_clu
);
237 extern void fat_cache_inval_inode(struct inode
*inode
);
238 extern int fat_get_cluster(struct inode
*inode
, int cluster
,
239 int *fclus
, int *dclus
);
240 extern int fat_free(struct inode
*inode
, int skip
);
243 extern struct file_operations fat_dir_operations
;
244 extern int fat_search_long(struct inode
*inode
, const unsigned char *name
,
245 int name_len
, int anycase
,
246 loff_t
*spos
, loff_t
*lpos
);
247 extern int fat_readdir(struct file
*filp
, void *dirent
, filldir_t filldir
);
248 extern int fat_dir_ioctl(struct inode
* inode
, struct file
* filp
,
249 unsigned int cmd
, unsigned long arg
);
250 extern int fat_add_entries(struct inode
*dir
, int slots
, struct buffer_head
**bh
,
251 struct msdos_dir_entry
**de
, loff_t
*i_pos
);
252 extern int fat_new_dir(struct inode
*dir
, struct inode
*parent
, int is_vfat
);
253 extern int fat_dir_empty(struct inode
*dir
);
254 extern int fat_subdirs(struct inode
*dir
);
255 extern int fat_scan(struct inode
*dir
, const unsigned char *name
,
256 struct buffer_head
**res_bh
,
257 struct msdos_dir_entry
**res_de
, loff_t
*i_pos
);
260 extern struct file_operations fat_file_operations
;
261 extern struct inode_operations fat_file_inode_operations
;
262 extern int fat_get_block(struct inode
*inode
, sector_t iblock
,
263 struct buffer_head
*bh_result
, int create
);
264 extern void fat_truncate(struct inode
*inode
);
267 extern void fat_hash_init(void);
268 extern void fat_attach(struct inode
*inode
, loff_t i_pos
);
269 extern void fat_detach(struct inode
*inode
);
270 extern struct inode
*fat_iget(struct super_block
*sb
, loff_t i_pos
);
271 extern struct inode
*fat_build_inode(struct super_block
*sb
,
272 struct msdos_dir_entry
*de
, loff_t i_pos
, int *res
);
273 extern void fat_delete_inode(struct inode
*inode
);
274 extern void fat_clear_inode(struct inode
*inode
);
275 extern void fat_put_super(struct super_block
*sb
);
276 int fat_fill_super(struct super_block
*sb
, void *data
, int silent
,
277 struct inode_operations
*fs_dir_inode_ops
, int isvfat
);
278 extern int fat_statfs(struct super_block
*sb
, struct kstatfs
*buf
);
279 extern int fat_write_inode(struct inode
*inode
, int wait
);
280 extern int fat_notify_change(struct dentry
* dentry
, struct iattr
* attr
);
283 extern void fat_fs_panic(struct super_block
*s
, const char *fmt
, ...);
284 extern void lock_fat(struct super_block
*sb
);
285 extern void unlock_fat(struct super_block
*sb
);
286 extern void fat_clusters_flush(struct super_block
*sb
);
287 extern int fat_add_cluster(struct inode
*inode
);
288 extern struct buffer_head
*fat_extend_dir(struct inode
*inode
);
289 extern int date_dos2unix(unsigned short time
, unsigned short date
);
290 extern void fat_date_unix2dos(int unix_date
, __le16
*time
, __le16
*date
);
291 extern int fat__get_entry(struct inode
*dir
, loff_t
*pos
,
292 struct buffer_head
**bh
,
293 struct msdos_dir_entry
**de
, loff_t
*i_pos
);
294 static __inline__
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
)
298 /* Fast stuff first */
300 (*de
- (struct msdos_dir_entry
*)(*bh
)->b_data
) < MSDOS_SB(dir
->i_sb
)->dir_per_block
- 1) {
301 *pos
+= sizeof(struct msdos_dir_entry
);
306 return fat__get_entry(dir
, pos
, bh
, de
, i_pos
);
309 #endif /* __KERNEL__ */