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 DENTRY_SIZE 32 /* directory entry size */
72 #define DENTRY_SIZE_BITS 5
74 #define MAX_FAT_DENTRIES 65536 /* FAT allows 65536 directory entries */
75 #define MAX_EXFAT_DENTRIES 8388608 /* exFAT allows 8388608(256MB) directory entries */
78 #define PBR_SIGNATURE 0xAA55
79 #define EXT_SIGNATURE 0xAA550000
80 #define VOL_LABEL "NO NAME " /* size should be 11 */
81 #define OEM_NAME "MSWIN4.1" /* size should be 8 */
82 #define STR_FAT12 "FAT12 " /* size should be 8 */
83 #define STR_FAT16 "FAT16 " /* size should be 8 */
84 #define STR_FAT32 "FAT32 " /* size should be 8 */
85 #define STR_EXFAT "EXFAT " /* size should be 8 */
87 #define VOL_CLEAN 0x0000
88 #define VOL_DIRTY 0x0002
90 #define FAT_VOL_DIRTY 0x01
92 /* max number of clusters */
93 #define FAT12_THRESHOLD 4087 // 2^12 - 1 + 2 (clu 0 & 1)
94 #define FAT16_THRESHOLD 65527 // 2^16 - 1 + 2
95 #define FAT32_THRESHOLD 268435457 // 2^28 - 1 + 2
96 #define EXFAT_THRESHOLD 268435457 // 2^28 - 1 + 2
99 #define MSDOS_DELETED 0xE5 /* deleted mark */
100 #define MSDOS_UNUSED 0x00 /* end of directory */
102 #define EXFAT_UNUSED 0x00 /* end of directory */
103 #define IS_EXFAT_DELETED(x) ((x) < 0x80) /* deleted file (0x01~0x7F) */
104 #define EXFAT_INVAL 0x80 /* invalid value */
105 #define EXFAT_BITMAP 0x81 /* allocation bitmap */
106 #define EXFAT_UPCASE 0x82 /* upcase table */
107 #define EXFAT_VOLUME 0x83 /* volume label */
108 #define EXFAT_FILE 0x85 /* file or dir */
109 #define EXFAT_STREAM 0xC0 /* stream entry */
110 #define EXFAT_NAME 0xC1 /* file name entry */
111 #define EXFAT_ACL 0xC2 /* stream entry */
114 #define MSDOS_LAST_LFN 0x40
116 /* file attributes */
117 #define ATTR_NORMAL 0x0000
118 #define ATTR_READONLY 0x0001
119 #define ATTR_HIDDEN 0x0002
120 #define ATTR_SYSTEM 0x0004
121 #define ATTR_VOLUME 0x0008
122 #define ATTR_SUBDIR 0x0010
123 #define ATTR_ARCHIVE 0x0020
124 #define ATTR_SYMLINK 0x0040
125 #define ATTR_EXTEND (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | \
126 ATTR_VOLUME) /* 0x000F */
128 #define ATTR_EXTEND_MASK (ATTR_EXTEND | ATTR_SUBDIR | ATTR_ARCHIVE)
129 #define ATTR_RWMASK (ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME | \
130 ATTR_SUBDIR | ATTR_ARCHIVE | ATTR_SYMLINK)/* 0x007E */
132 /* file creation modes */
133 #define FM_REGULAR 0x00
134 #define FM_SYMLINK 0x40
142 #define CS_DIR_ENTRY 0
143 #define CS_PBR_SECTOR 1
149 #define SDFAT_IOCTL_GET_VOLUME_ID _IOR('r', 0x12, __u32)
150 #define SDFAT_IOCTL_DFR_INFO _IOC(_IOC_NONE, 'E', 0x13, sizeof(u32))
151 #define SDFAT_IOCTL_DFR_TRAV _IOC(_IOC_NONE, 'E', 0x14, sizeof(u32))
152 #define SDFAT_IOCTL_DFR_REQ _IOC(_IOC_NONE, 'E', 0x15, sizeof(u32))
153 #define SDFAT_IOCTL_DFR_SPO_FLAG _IOC(_IOC_NONE, 'E', 0x16, sizeof(u32))
154 #define SDFAT_IOCTL_PANIC _IOC(_IOC_NONE, 'E', 0x17, sizeof(u32))
157 * ioctl command for debugging
161 * IOCTL code 'f' used by
162 * - file systems typically #0~0x1F
163 * - embedded terminal devices #128~
164 * - exts for debugging purpose #99
165 * number 100 and 101 is available now but has possible conflicts
167 * NOTE : This is available only If CONFIG_SDFAT_DVBG_IOCTL is enabled.
170 #define SDFAT_IOC_GET_DEBUGFLAGS _IOR('f', 100, long)
171 #define SDFAT_IOC_SET_DEBUGFLAGS _IOW('f', 101, long)
173 #define SDFAT_DEBUGFLAGS_INVALID_UMOUNT 0x01
174 #define SDFAT_DEBUGFLAGS_ERROR_RW 0x02
176 /*----------------------------------------------------------------------*/
177 /* On-Disk Type Definitions */
178 /*----------------------------------------------------------------------*/
180 /* FAT12/16 BIOS parameter block (64 bytes) */
185 __u8 sect_size
[2]; /* unaligned */
187 __le16 num_reserved
; /* . */
189 __u8 num_root_entries
[2]; /* unaligned */
190 __u8 num_sectors
[2]; /* unaligned */
192 __le16 num_fat_sectors
;
193 __le16 sectors_in_track
;
195 __le32 num_hid_sectors
; /* . */
196 __le32 num_huge_sectors
;
199 __u8 state
; /* used by WindowsNT for mount state */
207 /* FAT32 BIOS parameter block (64 bytes) */
212 __u8 sect_size
[2]; /* unaligned */
216 __u8 num_root_entries
[2]; /* unaligned */
217 __u8 num_sectors
[2]; /* unaligned */
219 __le16 num_fat_sectors
; /* zero */
220 __le16 sectors_in_track
;
222 __le32 num_hid_sectors
; /* . */
223 __le32 num_huge_sectors
;
225 __le32 num_fat32_sectors
;
228 __le32 root_cluster
; /* . */
229 __le16 fsinfo_sector
;
230 __le16 backup_sector
;
231 __le16 reserved
[6]; /* . */
234 /* FAT32 EXTEND BIOS parameter block (32 bytes) */
237 __u8 state
; /* used by WindowsNT for mount state */
245 /* EXFAT BIOS parameter block (64 bytes) */
252 /* EXFAT EXTEND BIOS parameter block (56 bytes) */
265 __u8 sect_per_clus_bits
;
272 /* FAT32 PBR (64 bytes) */
277 /* FAT32 PBR[BPB+BSX] (96 bytes) */
283 /* EXFAT PBR[BPB+BSX] (120 bytes) */
289 /* Common PBR[Partition Boot Record] (512 bytes) */
306 /* FAT32 filesystem information sector (512 bytes) */
308 __le32 signature1
; // aligned
310 __le32 signature2
; // aligned
311 __le32 free_cluster
; // aligned
312 __le32 next_cluster
; // aligned
314 __le16 signature3
[2];
317 /* FAT directory entry (32 bytes) */
323 __u8 name
[DOS_NAME_LENGTH
]; /* 11 chars */
327 __le16 create_time
; // aligned
328 __le16 create_date
; // aligned
329 __le16 access_date
; // aligned
330 __le16 start_clu_hi
; // aligned
331 __le16 modify_time
; // aligned
332 __le16 modify_date
; // aligned
333 __le16 start_clu_lo
; // aligned
334 __le32 size
; // aligned
337 /* FAT extended directory entry (32 bytes) */
340 __u8 unicode_0_4
[10];
344 __le16 unicode_5_10
[6]; // aligned
345 __le16 start_clu
; // aligned
346 __le16 unicode_11_12
[2]; // aligned
349 /* EXFAT file directory entry (32 bytes) */
353 __le16 checksum
; // aligned
354 __le16 attr
; // aligned
356 __le16 create_time
; // aligned
357 __le16 create_date
; // aligned
358 __le16 modify_time
; // aligned
359 __le16 modify_date
; // aligned
360 __le16 access_time
; // aligned
361 __le16 access_date
; // aligned
368 /* EXFAT stream extension directory entry (32 bytes) */
374 __le16 name_hash
; // aligned
376 __le64 valid_size
; // aligned
377 __le32 reserved3
; // aligned
378 __le32 start_clu
; // aligned
379 __le64 size
; // aligned
382 /* EXFAT file name directory entry (32 bytes) */
386 __le16 unicode_0_14
[15]; // aligned
389 /* EXFAT allocation bitmap directory entry (32 bytes) */
394 __le32 start_clu
; // aligned
395 __le64 size
; // aligned
398 /* EXFAT up-case table directory entry (32 bytes) */
402 __le32 checksum
; // aligned
404 __le32 start_clu
; // aligned
405 __le64 size
; // aligned
408 /* EXFAT volume label directory entry (32 bytes) */
412 __le16 unicode_0_10
[11]; // aligned
416 #endif /* _SDFAT_FS_H */