fs: sdfat: Update to version 2.1.8
[GitHub/LineageOS/android_kernel_samsung_universal7580.git] / fs / sdfat / sdfat_fs.h
1 /*
2 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #ifndef _SDFAT_FS_H
19 #define _SDFAT_FS_H
20
21 #include <linux/types.h>
22 #include <linux/magic.h>
23 #include <asm/byteorder.h>
24
25 /*----------------------------------------------------------------------*/
26 /* Constant & Macro Definitions */
27 /*----------------------------------------------------------------------*/
28 #ifndef MSDOS_SUPER_MAGIC
29 #define MSDOS_SUPER_MAGIC 0x4d44 /* MD */
30 #endif
31
32 #ifndef EXFAT_SUPER_MAGIC
33 #define EXFAT_SUPER_MAGIC (0x2011BAB0UL)
34 #endif /* EXFAT_SUPER_MAGIC */
35
36 #define SDFAT_SUPER_MAGIC (0x5EC5DFA4UL)
37 #define SDFAT_ROOT_INO 1
38
39 /* FAT types */
40 #define FAT12 0x01 // FAT12
41 #define FAT16 0x0E // Win95 FAT16 (LBA)
42 #define FAT32 0x0C // Win95 FAT32 (LBA)
43 #define EXFAT 0x07 // exFAT
44
45 /* directory file name */
46 #define DOS_CUR_DIR_NAME ". "
47 #define DOS_PAR_DIR_NAME ".. "
48
49 #ifdef __LITTLE_ENDIAN
50 #define UNI_CUR_DIR_NAME ".\0"
51 #define UNI_PAR_DIR_NAME ".\0.\0"
52 #else
53 #define UNI_CUR_DIR_NAME "\0."
54 #define UNI_PAR_DIR_NAME "\0.\0."
55 #endif
56
57 /* file name lengths */
58 /* NOTE :
59 * The maximum length of input or output is limited to 256 including NULL,
60 * But we allocate 4 extra bytes for utf8 translation reside in last position,
61 * because utf8 can uses memory upto 6 bytes per one character.
62 * Therefore, MAX_CHARSET_SIZE supports upto 6 bytes for utf8
63 */
64 #define MAX_UNINAME_BUF_SIZE (((MAX_NAME_LENGTH+1)*2)+4)
65 #define MAX_DOSNAME_BUF_SIZE ((DOS_NAME_LENGTH+2)+6)
66 #define MAX_VFSNAME_BUF_SIZE ((MAX_NAME_LENGTH+1)*MAX_CHARSET_SIZE)
67 #define MAX_CHARSET_SIZE 6 // max size of multi-byte character
68 #define MAX_NAME_LENGTH 255 // max len of file name excluding NULL
69 #define DOS_NAME_LENGTH 11 // DOS file name length excluding NULL
70
71 #define SECTOR_SIZE_BITS 9 /* VFS sector size is 512 bytes */
72
73 #define DENTRY_SIZE 32 /* directory entry size */
74 #define DENTRY_SIZE_BITS 5
75
76 #define MAX_FAT_DENTRIES 65536 /* FAT allows 65536 directory entries */
77 #define MAX_EXFAT_DENTRIES 8388608 /* exFAT allows 8388608(256MB) directory entries */
78
79 /* PBR entries */
80 #define PBR_SIGNATURE 0xAA55
81 #define EXT_SIGNATURE 0xAA550000
82 #define VOL_LABEL "NO NAME " /* size should be 11 */
83 #define OEM_NAME "MSWIN4.1" /* size should be 8 */
84 #define STR_FAT12 "FAT12 " /* size should be 8 */
85 #define STR_FAT16 "FAT16 " /* size should be 8 */
86 #define STR_FAT32 "FAT32 " /* size should be 8 */
87 #define STR_EXFAT "EXFAT " /* size should be 8 */
88
89 #define VOL_CLEAN 0x0000
90 #define VOL_DIRTY 0x0002
91
92 #define FAT_VOL_DIRTY 0x01
93
94 /* max number of clusters */
95 #define FAT12_THRESHOLD 4087 // 2^12 - 1 + 2 (clu 0 & 1)
96 #define FAT16_THRESHOLD 65527 // 2^16 - 1 + 2
97 #define FAT32_THRESHOLD 268435457 // 2^28 - 1 + 2
98 #define EXFAT_THRESHOLD 268435457 // 2^28 - 1 + 2
99
100 /* dentry types */
101 #define MSDOS_DELETED 0xE5 /* deleted mark */
102 #define MSDOS_UNUSED 0x00 /* end of directory */
103
104 #define EXFAT_UNUSED 0x00 /* end of directory */
105 #define IS_EXFAT_DELETED(x) ((x) < 0x80) /* deleted file (0x01~0x7F) */
106 #define EXFAT_INVAL 0x80 /* invalid value */
107 #define EXFAT_BITMAP 0x81 /* allocation bitmap */
108 #define EXFAT_UPCASE 0x82 /* upcase table */
109 #define EXFAT_VOLUME 0x83 /* volume label */
110 #define EXFAT_FILE 0x85 /* file or dir */
111 #define EXFAT_STREAM 0xC0 /* stream entry */
112 #define EXFAT_NAME 0xC1 /* file name entry */
113 #define EXFAT_ACL 0xC2 /* stream entry */
114
115 /* specific flag */
116 #define MSDOS_LAST_LFN 0x40
117
118 /* file attributes */
119 #define ATTR_NORMAL 0x0000
120 #define ATTR_READONLY 0x0001
121 #define ATTR_HIDDEN 0x0002
122 #define ATTR_SYSTEM 0x0004
123 #define ATTR_VOLUME 0x0008
124 #define ATTR_SUBDIR 0x0010
125 #define ATTR_ARCHIVE 0x0020
126 #define ATTR_SYMLINK 0x0040
127 #define ATTR_EXTEND (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | \
128 ATTR_VOLUME) /* 0x000F */
129
130 #define ATTR_EXTEND_MASK (ATTR_EXTEND | ATTR_SUBDIR | ATTR_ARCHIVE)
131 #define ATTR_RWMASK (ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME | \
132 ATTR_SUBDIR | ATTR_ARCHIVE | ATTR_SYMLINK)/* 0x007E */
133
134 /* file creation modes */
135 #define FM_REGULAR 0x00
136 #define FM_SYMLINK 0x40
137
138 /* time modes */
139 #define TM_CREATE 0
140 #define TM_MODIFY 1
141 #define TM_ACCESS 2
142
143 /* checksum types */
144 #define CS_DIR_ENTRY 0
145 #define CS_PBR_SECTOR 1
146 #define CS_DEFAULT 2
147
148 /*
149 * ioctl command
150 */
151 #define SDFAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x12, __u32)
152 #define SDFAT_IOCTL_DFR_INFO _IOC(_IOC_NONE, 'E', 0x13, sizeof(u32))
153 #define SDFAT_IOCTL_DFR_TRAV _IOC(_IOC_NONE, 'E', 0x14, sizeof(u32))
154 #define SDFAT_IOCTL_DFR_REQ _IOC(_IOC_NONE, 'E', 0x15, sizeof(u32))
155 #define SDFAT_IOCTL_DFR_SPO_FLAG _IOC(_IOC_NONE, 'E', 0x16, sizeof(u32))
156 #define SDFAT_IOCTL_PANIC _IOC(_IOC_NONE, 'E', 0x17, sizeof(u32))
157
158 /*
159 * ioctl command for debugging
160 */
161
162 /*
163 * IOCTL code 'f' used by
164 * - file systems typically #0~0x1F
165 * - embedded terminal devices #128~
166 * - exts for debugging purpose #99
167 * number 100 and 101 is available now but has possible conflicts
168 *
169 * NOTE : This is available only If CONFIG_SDFAT_DVBG_IOCTL is enabled.
170 *
171 */
172 #define SDFAT_IOC_GET_DEBUGFLAGS _IOR('f', 100, long)
173 #define SDFAT_IOC_SET_DEBUGFLAGS _IOW('f', 101, long)
174
175 #define SDFAT_DEBUGFLAGS_INVALID_UMOUNT 0x01
176 #define SDFAT_DEBUGFLAGS_ERROR_RW 0x02
177
178 /*----------------------------------------------------------------------*/
179 /* On-Disk Type Definitions */
180 /*----------------------------------------------------------------------*/
181
182 /* FAT12/16 BIOS parameter block (64 bytes) */
183 typedef struct {
184 __u8 jmp_boot[3];
185 __u8 oem_name[8];
186
187 __u8 sect_size[2]; /* unaligned */
188 __u8 sect_per_clus;
189 __le16 num_reserved; /* . */
190 __u8 num_fats;
191 __u8 num_root_entries[2]; /* unaligned */
192 __u8 num_sectors[2]; /* unaligned */
193 __u8 media_type;
194 __le16 num_fat_sectors;
195 __le16 sectors_in_track;
196 __le16 num_heads;
197 __le32 num_hid_sectors; /* . */
198 __le32 num_huge_sectors;
199
200 __u8 phy_drv_no;
201 __u8 state; /* used by WindowsNT for mount state */
202 __u8 ext_signature;
203 __u8 vol_serial[4];
204 __u8 vol_label[11];
205 __u8 vol_type[8];
206 __le16 dummy;
207 } bpb16_t;
208
209 /* FAT32 BIOS parameter block (64 bytes) */
210 typedef struct {
211 __u8 jmp_boot[3];
212 __u8 oem_name[8];
213
214 __u8 sect_size[2]; /* unaligned */
215 __u8 sect_per_clus;
216 __le16 num_reserved;
217 __u8 num_fats;
218 __u8 num_root_entries[2]; /* unaligned */
219 __u8 num_sectors[2]; /* unaligned */
220 __u8 media_type;
221 __le16 num_fat_sectors; /* zero */
222 __le16 sectors_in_track;
223 __le16 num_heads;
224 __le32 num_hid_sectors; /* . */
225 __le32 num_huge_sectors;
226
227 __le32 num_fat32_sectors;
228 __le16 ext_flags;
229 __u8 fs_version[2];
230 __le32 root_cluster; /* . */
231 __le16 fsinfo_sector;
232 __le16 backup_sector;
233 __le16 reserved[6]; /* . */
234 } bpb32_t;
235
236 /* FAT32 EXTEND BIOS parameter block (32 bytes) */
237 typedef struct {
238 __u8 phy_drv_no;
239 __u8 state; /* used by WindowsNT for mount state */
240 __u8 ext_signature;
241 __u8 vol_serial[4];
242 __u8 vol_label[11];
243 __u8 vol_type[8];
244 __le16 dummy[3];
245 } bsx32_t;
246
247 /* EXFAT BIOS parameter block (64 bytes) */
248 typedef struct {
249 __u8 jmp_boot[3];
250 __u8 oem_name[8];
251 __u8 res_zero[53];
252 } bpb64_t;
253
254 /* EXFAT EXTEND BIOS parameter block (56 bytes) */
255 typedef struct {
256 __le64 vol_offset;
257 __le64 vol_length;
258 __le32 fat_offset;
259 __le32 fat_length;
260 __le32 clu_offset;
261 __le32 clu_count;
262 __le32 root_cluster;
263 __le32 vol_serial;
264 __u8 fs_version[2];
265 __le16 vol_flags;
266 __u8 sect_size_bits;
267 __u8 sect_per_clus_bits;
268 __u8 num_fats;
269 __u8 phy_drv_no;
270 __u8 perc_in_use;
271 __u8 reserved2[7];
272 } bsx64_t;
273
274 /* FAT32 PBR (64 bytes) */
275 typedef struct {
276 bpb16_t bpb;
277 } pbr16_t;
278
279 /* FAT32 PBR[BPB+BSX] (96 bytes) */
280 typedef struct {
281 bpb32_t bpb;
282 bsx32_t bsx;
283 } pbr32_t;
284
285 /* EXFAT PBR[BPB+BSX] (120 bytes) */
286 typedef struct {
287 bpb64_t bpb;
288 bsx64_t bsx;
289 } pbr64_t;
290
291 /* Common PBR[Partition Boot Record] (512 bytes) */
292 typedef struct {
293 union {
294 __u8 raw[64];
295 bpb16_t f16;
296 bpb32_t f32;
297 bpb64_t f64;
298 } bpb;
299 union {
300 __u8 raw[56];
301 bsx32_t f32;
302 bsx64_t f64;
303 } bsx;
304 __u8 boot_code[390];
305 __le16 signature;
306 } pbr_t;
307
308 /* FAT32 filesystem information sector (512 bytes) */
309 typedef struct {
310 __le32 signature1; // aligned
311 __u8 reserved1[480];
312 __le32 signature2; // aligned
313 __le32 free_cluster; // aligned
314 __le32 next_cluster; // aligned
315 __u8 reserved2[14];
316 __le16 signature3[2];
317 } fat32_fsi_t;
318
319 /* FAT directory entry (32 bytes) */
320 typedef struct {
321 __u8 dummy[32];
322 } DENTRY_T;
323
324 typedef struct {
325 __u8 name[DOS_NAME_LENGTH]; /* 11 chars */
326 __u8 attr;
327 __u8 lcase;
328 __u8 create_time_ms;
329 __le16 create_time; // aligned
330 __le16 create_date; // aligned
331 __le16 access_date; // aligned
332 __le16 start_clu_hi; // aligned
333 __le16 modify_time; // aligned
334 __le16 modify_date; // aligned
335 __le16 start_clu_lo; // aligned
336 __le32 size; // aligned
337 } DOS_DENTRY_T;
338
339 /* FAT extended directory entry (32 bytes) */
340 typedef struct {
341 __u8 order;
342 __u8 unicode_0_4[10];
343 __u8 attr;
344 __u8 sysid;
345 __u8 checksum;
346 __le16 unicode_5_10[6]; // aligned
347 __le16 start_clu; // aligned
348 __le16 unicode_11_12[2]; // aligned
349 } EXT_DENTRY_T;
350
351 /* EXFAT file directory entry (32 bytes) */
352 typedef struct {
353 __u8 type;
354 __u8 num_ext;
355 __le16 checksum; // aligned
356 __le16 attr; // aligned
357 __le16 reserved1;
358 __le16 create_time; // aligned
359 __le16 create_date; // aligned
360 __le16 modify_time; // aligned
361 __le16 modify_date; // aligned
362 __le16 access_time; // aligned
363 __le16 access_date; // aligned
364 __u8 create_time_ms;
365 __u8 modify_time_ms;
366 __u8 access_time_ms;
367 __u8 reserved2[9];
368 } FILE_DENTRY_T;
369
370 /* EXFAT stream extension directory entry (32 bytes) */
371 typedef struct {
372 __u8 type;
373 __u8 flags;
374 __u8 reserved1;
375 __u8 name_len;
376 __le16 name_hash; // aligned
377 __le16 reserved2;
378 __le64 valid_size; // aligned
379 __le32 reserved3; // aligned
380 __le32 start_clu; // aligned
381 __le64 size; // aligned
382 } STRM_DENTRY_T;
383
384 /* EXFAT file name directory entry (32 bytes) */
385 typedef struct {
386 __u8 type;
387 __u8 flags;
388 __le16 unicode_0_14[15]; // aligned
389 } NAME_DENTRY_T;
390
391 /* EXFAT allocation bitmap directory entry (32 bytes) */
392 typedef struct {
393 __u8 type;
394 __u8 flags;
395 __u8 reserved[18];
396 __le32 start_clu; // aligned
397 __le64 size; // aligned
398 } BMAP_DENTRY_T;
399
400 /* EXFAT up-case table directory entry (32 bytes) */
401 typedef struct {
402 __u8 type;
403 __u8 reserved1[3];
404 __le32 checksum; // aligned
405 __u8 reserved2[12];
406 __le32 start_clu; // aligned
407 __le64 size; // aligned
408 } CASE_DENTRY_T;
409
410 /* EXFAT volume label directory entry (32 bytes) */
411 typedef struct {
412 __u8 type;
413 __u8 label_len;
414 __le16 unicode_0_10[11]; // aligned
415 __u8 reserved[8];
416 } VOLM_DENTRY_T;
417
418 #endif /* _SDFAT_FS_H */