• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _UAPI_LINUX_MSDOS_FS_H
2 #define _UAPI_LINUX_MSDOS_FS_H
3 
4 #include <linux/types.h>
5 #include <linux/magic.h>
6 #include <asm/byteorder.h>
7 
8 /*
9  * The MS-DOS filesystem constants/structures
10  */
11 
12 #define SECTOR_SIZE	512		/* sector size (bytes) */
13 #define SECTOR_BITS	9		/* log2(SECTOR_SIZE) */
14 #define MSDOS_DPB	(MSDOS_DPS)	/* dir entries per block */
15 #define MSDOS_DPB_BITS	4		/* log2(MSDOS_DPB) */
16 #define MSDOS_DPS	(SECTOR_SIZE / sizeof(struct msdos_dir_entry))
17 #define MSDOS_DPS_BITS	4		/* log2(MSDOS_DPS) */
18 #define MSDOS_LONGNAME	256		/* maximum name length */
19 #define CF_LE_W(v)	le16_to_cpu(v)
20 #define CF_LE_L(v)	le32_to_cpu(v)
21 #define CT_LE_W(v)	cpu_to_le16(v)
22 #define CT_LE_L(v)	cpu_to_le32(v)
23 
24 #define MSDOS_ROOT_INO	 1	/* The root inode number */
25 #define MSDOS_FSINFO_INO 2	/* Used for managing the FSINFO block */
26 
27 #define MSDOS_DIR_BITS	5	/* log2(sizeof(struct msdos_dir_entry)) */
28 
29 /* directory limit */
30 #define FAT_MAX_DIR_ENTRIES	(65536)
31 #define FAT_MAX_DIR_SIZE	(FAT_MAX_DIR_ENTRIES << MSDOS_DIR_BITS)
32 
33 #define ATTR_NONE	0	/* no attribute bits */
34 #define ATTR_RO		1	/* read-only */
35 #define ATTR_HIDDEN	2	/* hidden */
36 #define ATTR_SYS	4	/* system */
37 #define ATTR_VOLUME	8	/* volume label */
38 #define ATTR_DIR	16	/* directory */
39 #define ATTR_ARCH	32	/* archived */
40 
41 /* attribute bits that are copied "as is" */
42 #define ATTR_UNUSED	(ATTR_VOLUME | ATTR_ARCH | ATTR_SYS | ATTR_HIDDEN)
43 /* bits that are used by the Windows 95/Windows NT extended FAT */
44 #define ATTR_EXT	(ATTR_RO | ATTR_HIDDEN | ATTR_SYS | ATTR_VOLUME)
45 
46 #define CASE_LOWER_BASE	8	/* base is lower case */
47 #define CASE_LOWER_EXT	16	/* extension is lower case */
48 
49 #define DELETED_FLAG	0xe5	/* marks file as deleted when in name[0] */
50 #define IS_FREE(n)	(!*(n) || *(n) == DELETED_FLAG)
51 
52 #define FAT_LFN_LEN	255	/* maximum long name length */
53 #define MSDOS_NAME	11	/* maximum name length */
54 #define MSDOS_SLOTS	21	/* max # of slots 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 FAT_FIRST_ENT(s, x)	((MSDOS_SB(s)->fat_bits == 32 ? 0x0FFFFF00 : \
59 	MSDOS_SB(s)->fat_bits == 16 ? 0xFF00 : 0xF00) | (x))
60 
61 /* start of data cluster's entry (number of reserved clusters) */
62 #define FAT_START_ENT	2
63 
64 /* maximum number of clusters */
65 #define MAX_FAT12	0xFF4
66 #define MAX_FAT16	0xFFF4
67 #define MAX_FAT32	0x0FFFFFF6
68 #define MAX_FAT(s)	(MSDOS_SB(s)->fat_bits == 32 ? MAX_FAT32 : \
69 	MSDOS_SB(s)->fat_bits == 16 ? MAX_FAT16 : MAX_FAT12)
70 
71 /* bad cluster mark */
72 #define BAD_FAT12	0xFF7
73 #define BAD_FAT16	0xFFF7
74 #define BAD_FAT32	0x0FFFFFF7
75 
76 /* standard EOF */
77 #define EOF_FAT12	0xFFF
78 #define EOF_FAT16	0xFFFF
79 #define EOF_FAT32	0x0FFFFFFF
80 
81 #define FAT_ENT_FREE	(0)
82 #define FAT_ENT_BAD	(BAD_FAT32)
83 #define FAT_ENT_EOF	(EOF_FAT32)
84 
85 #define FAT_FSINFO_SIG1	0x41615252
86 #define FAT_FSINFO_SIG2	0x61417272
87 #define IS_FSINFO(x)	(le32_to_cpu((x)->signature1) == FAT_FSINFO_SIG1 \
88 			 && le32_to_cpu((x)->signature2) == FAT_FSINFO_SIG2)
89 
90 #define FAT_STATE_DIRTY 0x01
91 
92 struct __fat_dirent {
93 	long		d_ino;
94 	__kernel_off_t	d_off;
95 	unsigned short	d_reclen;
96 	char		d_name[256]; /* We must not include limits.h! */
97 };
98 
99 /*
100  * ioctl commands
101  */
102 #define VFAT_IOCTL_READDIR_BOTH		_IOR('r', 1, struct __fat_dirent[2])
103 #define VFAT_IOCTL_READDIR_SHORT	_IOR('r', 2, struct __fat_dirent[2])
104 /* <linux/videotext.h> has used 0x72 ('r') in collision, so skip a few */
105 #define FAT_IOCTL_GET_ATTRIBUTES	_IOR('r', 0x10, __u32)
106 #define FAT_IOCTL_SET_ATTRIBUTES	_IOW('r', 0x11, __u32)
107 /*Android kernel has used 0x12, so we use 0x13*/
108 #define FAT_IOCTL_GET_VOLUME_ID		_IOR('r', 0x13, __u32)
109 
110 struct fat_boot_sector {
111 	__u8	ignored[3];	/* Boot strap short or near jump */
112 	__u8	system_id[8];	/* Name - can be used to special case
113 				   partition manager volumes */
114 	__u8	sector_size[2];	/* bytes per logical sector */
115 	__u8	sec_per_clus;	/* sectors/cluster */
116 	__le16	reserved;	/* reserved sectors */
117 	__u8	fats;		/* number of FATs */
118 	__u8	dir_entries[2];	/* root directory entries */
119 	__u8	sectors[2];	/* number of sectors */
120 	__u8	media;		/* media code */
121 	__le16	fat_length;	/* sectors/FAT */
122 	__le16	secs_track;	/* sectors per track */
123 	__le16	heads;		/* number of heads */
124 	__le32	hidden;		/* hidden sectors (unused) */
125 	__le32	total_sect;	/* number of sectors (if sectors == 0) */
126 
127 	union {
128 		struct {
129 			/*  Extended BPB Fields for FAT16 */
130 			__u8	drive_number;	/* Physical drive number */
131 			__u8	state;		/* undocumented, but used
132 						   for mount state. */
133 			__u8	signature;  /* extended boot signature */
134 			__u8	vol_id[4];	/* volume ID */
135 			__u8	vol_label[11];	/* volume label */
136 			__u8	fs_type[8];		/* file system type */
137 			/* other fields are not added here */
138 		} fat16;
139 
140 		struct {
141 			/* only used by FAT32 */
142 			__le32	length;		/* sectors/FAT */
143 			__le16	flags;		/* bit 8: fat mirroring,
144 						   low 4: active fat */
145 			__u8	version[2];	/* major, minor filesystem
146 						   version */
147 			__le32	root_cluster;	/* first cluster in
148 						   root directory */
149 			__le16	info_sector;	/* filesystem info sector */
150 			__le16	backup_boot;	/* backup boot sector */
151 			__le16	reserved2[6];	/* Unused */
152 			/* Extended BPB Fields for FAT32 */
153 			__u8	drive_number;   /* Physical drive number */
154 			__u8    state;       	/* undocumented, but used
155 						   for mount state. */
156 			__u8	signature;  /* extended boot signature */
157 			__u8	vol_id[4];	/* volume ID */
158 			__u8	vol_label[11];	/* volume label */
159 			__u8	fs_type[8];		/* file system type */
160 			/* other fields are not added here */
161 		} fat32;
162 	};
163 };
164 
165 struct fat_boot_fsinfo {
166 	__le32   signature1;	/* 0x41615252L */
167 	__le32   reserved1[120];	/* Nothing as far as I can tell */
168 	__le32   signature2;	/* 0x61417272L */
169 	__le32   free_clusters;	/* Free cluster count.  -1 if unknown */
170 	__le32   next_cluster;	/* Most recently allocated cluster */
171 	__le32   reserved2[4];
172 };
173 
174 struct msdos_dir_entry {
175 	__u8	name[MSDOS_NAME];/* name and extension */
176 	__u8	attr;		/* attribute bits */
177 	__u8    lcase;		/* Case for base and extension */
178 	__u8	ctime_cs;	/* Creation time, centiseconds (0-199) */
179 	__le16	ctime;		/* Creation time */
180 	__le16	cdate;		/* Creation date */
181 	__le16	adate;		/* Last access date */
182 	__le16	starthi;	/* High 16 bits of cluster in FAT32 */
183 	__le16	time,date,start;/* time, date and first cluster */
184 	__le32	size;		/* file size (in bytes) */
185 };
186 
187 /* Up to 13 characters of the name */
188 struct msdos_dir_slot {
189 	__u8    id;		/* sequence number for slot */
190 	__u8    name0_4[10];	/* first 5 characters in name */
191 	__u8    attr;		/* attribute byte */
192 	__u8    reserved;	/* always 0 */
193 	__u8    alias_checksum;	/* checksum for 8.3 alias */
194 	__u8    name5_10[12];	/* 6 more characters in name */
195 	__le16   start;		/* starting cluster number, 0 in long slots */
196 	__u8    name11_12[4];	/* last 2 characters in name */
197 };
198 
199 #endif /* _UAPI_LINUX_MSDOS_FS_H */
200