1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Copyright (C) 2019 Namjae Jeon <linkinjeon@kernel.org>
16 #ifdef WORDS_BIGENDIAN
17 #define cpu_to_le16(x) ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8))
18 #define cpu_to_le32(x) \
19 ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \
20 (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
21 #define cpu_to_le64(x) (cpu_to_le32((uint64_t)(x)) << 32 | \
22 cpu_to_le32((uint64_t)(x) >> 32))
24 #define cpu_to_le16(x) (x)
25 #define cpu_to_le32(x) (x)
26 #define cpu_to_le64(x) (x)
29 #define le64_to_cpu(x) ((uint64_t)cpu_to_le64(x))
30 #define le32_to_cpu(x) ((uint32_t)cpu_to_le32(x))
31 #define le16_to_cpu(x) ((uint16_t)cpu_to_le16(x))
33 #define PBR_SIGNATURE 0xAA55
35 #define VOL_CLEAN 0x0000
36 #define VOL_DIRTY 0x0002
38 #define DENTRY_SIZE 32 /* directory entry size */
39 #define DENTRY_SIZE_BITS 5
40 /* exFAT allows 8388608(256MB) directory entries */
41 #define MAX_EXFAT_DENTRIES 8388608
42 #define MIN_FILE_DENTRIES 3
45 #define MSDOS_DELETED 0xE5 /* deleted mark */
46 #define MSDOS_UNUSED 0x00 /* end of directory */
48 #define EXFAT_LAST 0x00 /* end of directory */
49 #define EXFAT_DELETE ~(0x80)
50 #define IS_EXFAT_DELETED(x) ((x) < 0x80) /* deleted file (0x01~0x7F) */
51 #define EXFAT_INVAL 0x80 /* invalid value */
52 #define EXFAT_BITMAP 0x81 /* allocation bitmap */
53 #define EXFAT_UPCASE 0x82 /* upcase table */
54 #define EXFAT_VOLUME 0x83 /* volume label */
55 #define EXFAT_FILE 0x85 /* file or dir */
56 #define EXFAT_GUID 0xA0
57 #define EXFAT_PADDING 0xA1
58 #define EXFAT_ACLTAB 0xA2
59 #define EXFAT_STREAM 0xC0 /* stream entry */
60 #define EXFAT_NAME 0xC1 /* file name entry */
61 #define EXFAT_ACL 0xC2 /* stream entry */
64 #define CS_DIR_ENTRY 0
65 #define CS_PBR_SECTOR 1
69 #define ATTR_READONLY 0x0001
70 #define ATTR_HIDDEN 0x0002
71 #define ATTR_SYSTEM 0x0004
72 #define ATTR_VOLUME 0x0008
73 #define ATTR_SUBDIR 0x0010
74 #define ATTR_ARCHIVE 0x0020
75 #define ATTR_EXTEND (ATTR_READONLY | ATTR_HIDDEN | ATTR_SYSTEM | \
76 ATTR_VOLUME) /* 0x000F */
78 #define ATTR_EXTEND_MASK (ATTR_EXTEND | ATTR_SUBDIR | ATTR_ARCHIVE)
79 #define ATTR_RWMASK (ATTR_HIDDEN | ATTR_SYSTEM | ATTR_VOLUME | \
80 ATTR_SUBDIR | ATTR_ARCHIVE)
82 #define ATTR_READONLY_LE cpu_to_le16(0x0001)
83 #define ATTR_HIDDEN_LE cpu_to_le16(0x0002)
84 #define ATTR_SYSTEM_LE cpu_to_le16(0x0004)
85 #define ATTR_VOLUME_LE cpu_to_le16(0x0008)
86 #define ATTR_SUBDIR_LE cpu_to_le16(0x0010)
87 #define ATTR_ARCHIVE_LE cpu_to_le16(0x0020)
90 #define EXFAT_SF_CONTIGUOUS 0x02
92 #define CLUSTER_32(x) ((unsigned int)((x) & 0xFFFFFFFFU))
93 #define EXFAT_EOF_CLUSTER CLUSTER_32(~0)
94 #define EXFAT_BAD_CLUSTER (0xFFFFFFF7U)
95 #define EXFAT_FREE_CLUSTER (0)
96 #define EXFAT_FIRST_CLUSTER (2)
97 #define EXFAT_RESERVED_CLUSTERS (2)
100 /* EXFAT BIOS parameter block (64 bytes) */
107 /* EXFAT EXTEND BIOS parameter block (56 bytes) */
120 __u8 sect_per_clus_bits;
127 /* Common PBR[Partition Boot Record] (512 bytes) */
135 #define VOLUME_LABEL_MAX_LEN 11
136 #define ENTRY_NAME_MAX 15
138 struct exfat_dentry {
142 __u8 character_count;
143 __le16 volume_label[VOLUME_LABEL_MAX_LEN];
145 } __attribute__((packed)) vol; /* file directory entry */
164 } __attribute__((packed)) file; /* file directory entry */
175 } __attribute__((packed)) stream; /* stream extension directory entry */
178 __le16 unicode_0_14[15];
179 } __attribute__((packed)) name; /* file name directory entry */
185 } __attribute__((packed)) bitmap; /* allocation bitmap directory entry */
192 } __attribute__((packed)) upcase; /* up-case table directory entry */
193 } __attribute__((packed)) dentry;
194 } __attribute__((packed));
196 #define vol_char_cnt dentry.vol.character_count
197 #define vol_label dentry.vol.volume_label
198 #define file_num_ext dentry.file.num_ext
199 #define file_checksum dentry.file.checksum
200 #define file_attr dentry.file.attr
201 #define file_create_time dentry.file.create_time
202 #define file_create_date dentry.file.create_date
203 #define file_modify_time dentry.file.modify_time
204 #define file_modify_date dentry.file.modify_date
205 #define file_access_time dentry.file.access_time
206 #define file_access_date dentry.file.access_date
207 #define file_create_time_ms dentry.file.create_time_ms
208 #define file_modify_time_ms dentry.file.modify_time_ms
209 #define file_access_time_ms dentry.file.access_time_ms
210 #define stream_flags dentry.stream.flags
211 #define stream_name_len dentry.stream.name_len
212 #define stream_name_hash dentry.stream.name_hash
213 #define stream_start_clu dentry.stream.start_clu
214 #define stream_valid_size dentry.stream.valid_size
215 #define stream_size dentry.stream.size
216 #define name_flags dentry.name.flags
217 #define name_unicode dentry.name.unicode_0_14
218 #define bitmap_flags dentry.bitmap.flags
219 #define bitmap_start_clu dentry.bitmap.start_clu
220 #define bitmap_size dentry.bitmap.size
221 #define upcase_start_clu dentry.upcase.start_clu
222 #define upcase_size dentry.upcase.size
223 #define upcase_checksum dentry.upcase.checksum
225 #endif /* !_EXFAT_H */