2 * Copyright (C) 2012-2013 Samsung Electronics Co., Ltd.
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.
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.
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/>.
21 #include <linux/types.h>
22 #include <linux/magic.h>
23 #include <asm/byteorder.h>
25 /*----------------------------------------------------------------------*/
26 /* Constant & Macro Definitions */
27 /*----------------------------------------------------------------------*/
28 #ifndef MSDOS_SUPER_MAGIC
29 #define MSDOS_SUPER_MAGIC 0x4d44 /* MD */
32 #ifndef EXFAT_SUPER_MAGIC
33 #define EXFAT_SUPER_MAGIC (0x2011BAB0UL)
34 #endif /* EXFAT_SUPER_MAGIC */
36 #define SDFAT_SUPER_MAGIC (0x5EC5DFA4UL)
37 #define SDFAT_ROOT_INO 1
40 #define FAT12 0x01 // FAT12
41 #define FAT16 0x0E // Win95 FAT16 (LBA)
42 #define FAT32 0x0C // Win95 FAT32 (LBA)
43 #define EXFAT 0x07 // exFAT
45 /* directory file name */
46 #define DOS_CUR_DIR_NAME ". "
47 #define DOS_PAR_DIR_NAME ".. "
49 #ifdef __LITTLE_ENDIAN
50 #define UNI_CUR_DIR_NAME ".\0"
51 #define UNI_PAR_DIR_NAME ".\0.\0"
53 #define UNI_CUR_DIR_NAME "\0."
54 #define UNI_PAR_DIR_NAME "\0.\0."
57 /* file name lengths */
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
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
71 #define SECTOR_SIZE_BITS 9 /* VFS sector size is 512 bytes */
73 #define DENTRY_SIZE 32 /* directory entry size */
74 #define DENTRY_SIZE_BITS 5
76 #define MAX_FAT_DENTRIES 65536 /* FAT allows 65536 directory entries */
77 #define MAX_EXFAT_DENTRIES 8388608 /* exFAT allows 8388608(256MB) directory 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 */
89 #define VOL_CLEAN 0x0000
90 #define VOL_DIRTY 0x0002
92 #define FAT_VOL_DIRTY 0x01
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
101 #define MSDOS_DELETED 0xE5 /* deleted mark */
102 #define MSDOS_UNUSED 0x00 /* end of directory */
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 */
116 #define MSDOS_LAST_LFN 0x40
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 */
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 */
134 /* file creation modes */
135 #define FM_REGULAR 0x00
136 #define FM_SYMLINK 0x40
144 #define CS_DIR_ENTRY 0
145 #define CS_PBR_SECTOR 1
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))
159 * ioctl command for debugging
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
169 * NOTE : This is available only If CONFIG_SDFAT_DVBG_IOCTL is enabled.
172 #define SDFAT_IOC_GET_DEBUGFLAGS _IOR('f', 100, long)
173 #define SDFAT_IOC_SET_DEBUGFLAGS _IOW('f', 101, long)
175 #define SDFAT_DEBUGFLAGS_INVALID_UMOUNT 0x01
176 #define SDFAT_DEBUGFLAGS_ERROR_RW 0x02
178 /*----------------------------------------------------------------------*/
179 /* On-Disk Type Definitions */
180 /*----------------------------------------------------------------------*/
182 /* FAT12/16 BIOS parameter block (64 bytes) */
187 __u8 sect_size
[2]; /* unaligned */
189 __le16 num_reserved
; /* . */
191 __u8 num_root_entries
[2]; /* unaligned */
192 __u8 num_sectors
[2]; /* unaligned */
194 __le16 num_fat_sectors
;
195 __le16 sectors_in_track
;
197 __le32 num_hid_sectors
; /* . */
198 __le32 num_huge_sectors
;
201 __u8 state
; /* used by WindowsNT for mount state */
209 /* FAT32 BIOS parameter block (64 bytes) */
214 __u8 sect_size
[2]; /* unaligned */
218 __u8 num_root_entries
[2]; /* unaligned */
219 __u8 num_sectors
[2]; /* unaligned */
221 __le16 num_fat_sectors
; /* zero */
222 __le16 sectors_in_track
;
224 __le32 num_hid_sectors
; /* . */
225 __le32 num_huge_sectors
;
227 __le32 num_fat32_sectors
;
230 __le32 root_cluster
; /* . */
231 __le16 fsinfo_sector
;
232 __le16 backup_sector
;
233 __le16 reserved
[6]; /* . */
236 /* FAT32 EXTEND BIOS parameter block (32 bytes) */
239 __u8 state
; /* used by WindowsNT for mount state */
247 /* EXFAT BIOS parameter block (64 bytes) */
254 /* EXFAT EXTEND BIOS parameter block (56 bytes) */
267 __u8 sect_per_clus_bits
;
274 /* FAT32 PBR (64 bytes) */
279 /* FAT32 PBR[BPB+BSX] (96 bytes) */
285 /* EXFAT PBR[BPB+BSX] (120 bytes) */
291 /* Common PBR[Partition Boot Record] (512 bytes) */
308 /* FAT32 filesystem information sector (512 bytes) */
310 __le32 signature1
; // aligned
312 __le32 signature2
; // aligned
313 __le32 free_cluster
; // aligned
314 __le32 next_cluster
; // aligned
316 __le16 signature3
[2];
319 /* FAT directory entry (32 bytes) */
325 __u8 name
[DOS_NAME_LENGTH
]; /* 11 chars */
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
339 /* FAT extended directory entry (32 bytes) */
342 __u8 unicode_0_4
[10];
346 __le16 unicode_5_10
[6]; // aligned
347 __le16 start_clu
; // aligned
348 __le16 unicode_11_12
[2]; // aligned
351 /* EXFAT file directory entry (32 bytes) */
355 __le16 checksum
; // aligned
356 __le16 attr
; // aligned
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
370 /* EXFAT stream extension directory entry (32 bytes) */
376 __le16 name_hash
; // aligned
378 __le64 valid_size
; // aligned
379 __le32 reserved3
; // aligned
380 __le32 start_clu
; // aligned
381 __le64 size
; // aligned
384 /* EXFAT file name directory entry (32 bytes) */
388 __le16 unicode_0_14
[15]; // aligned
391 /* EXFAT allocation bitmap directory entry (32 bytes) */
396 __le32 start_clu
; // aligned
397 __le64 size
; // aligned
400 /* EXFAT up-case table directory entry (32 bytes) */
404 __le32 checksum
; // aligned
406 __le32 start_clu
; // aligned
407 __le64 size
; // aligned
410 /* EXFAT volume label directory entry (32 bytes) */
414 __le16 unicode_0_10
[11]; // aligned
418 #endif /* _SDFAT_FS_H */