3 Definitions of structures and constants used in exFAT file system.
5 Copyright (C) 2009, 2010 Andrew Nayenko
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef EXFATFS_H_INCLUDED
22 #define EXFATFS_H_INCLUDED
28 typedef uint32_t cluster_t; /* cluster number */
30 typedef struct { uint16_t __u16; } le16_t;
31 typedef struct { uint32_t __u32; } le32_t;
32 typedef struct { uint64_t __u64; } le64_t;
34 #if __BYTE_ORDER == __LITTLE_ENDIAN
35 static inline uint16_t le16_to_cpu(le16_t v) { return v.__u16; }
36 static inline uint32_t le32_to_cpu(le32_t v) { return v.__u32; }
37 static inline uint64_t le64_to_cpu(le64_t v) { return v.__u64; }
39 static inline le16_t cpu_to_le16(uint16_t v) { le16_t t = {v}; return t; }
40 static inline le32_t cpu_to_le32(uint32_t v) { le32_t t = {v}; return t; }
41 static inline le64_t cpu_to_le64(uint64_t v) { le64_t t = {v}; return t; }
42 #elif __BYTE_ORDER == __BIG_ENDIAN
43 static inline uint16_t le16_to_cpu(le16_t v) { return bswap_16(v.__u16); }
44 static inline uint32_t le32_to_cpu(le32_t v) { return bswap_32(v.__u32); }
45 static inline uint64_t le64_to_cpu(le64_t v) { return bswap_64(v.__u64); }
47 static inline le16_t cpu_to_le16(uint16_t v)
48 { le16_t t = {bswap_16(v)}; return t; }
49 static inline le32_t cpu_to_le32(uint32_t v)
50 { le32_t t = {bswap_32(v)}; return t; }
51 static inline le64_t cpu_to_le64(uint64_t v)
52 { le64_t t = {bswap_64(v)}; return t; }
54 #error Wow! You have a PDP machine?!
57 #define EXFAT_FIRST_DATA_CLUSTER 2
59 #define EXFAT_CLUSTER_FREE 0 /* free cluster */
60 #define EXFAT_CLUSTER_BAD 0xfffffff7 /* cluster contains bad block */
61 #define EXFAT_CLUSTER_END 0xffffffff /* final cluster of file or directory */
63 struct exfat_super_block
65 uint8_t jump[3]; /* 0x00 jmp and nop instructions */
66 uint8_t oem_name[8]; /* 0x03 "EXFAT " */
67 uint8_t __unknown1[53]; /* 0x0B ? always 0 */
68 le64_t block_start; /* 0x40 partition first block */
69 le64_t block_count; /* 0x48 partition blocks count */
70 le32_t fat_block_start; /* 0x50 FAT first block */
71 le32_t fat_block_count; /* 0x54 FAT blocks count */
72 le32_t cluster_block_start; /* 0x58 first cluster block */
73 le32_t cluster_count; /* 0x5C total clusters count */
74 le32_t rootdir_cluster; /* 0x60 first cluster of the root dir */
75 le32_t volume_serial; /* 0x64 */
76 le16_t __unknown2; /* 0x68 version? always 0x00 0x01 */
77 le16_t volume_state; /* 0x6A */
78 uint8_t block_bits; /* 0x6C block size as (1 << n) */
79 uint8_t bpc_bits; /* 0x6D blocks per cluster as (1 << n) */
80 uint8_t __unknown3; /* 0x6E ? always 1 */
81 uint8_t __unknown4; /* 0x6F drive number? always 0x80 */
82 uint8_t allocated_percent; /* 0x70 percentage of allocated space */
83 uint8_t __unknown5[397]; /* 0x71 padding? all zero */
84 le16_t boot_signature; /* the value of 0xAA55 */
87 #define EXFAT_ENTRY_VALID 0x80
88 #define EXFAT_ENTRY_CONTINUED 0x40
90 #define EXFAT_ENTRY_EOD (0x00)
91 #define EXFAT_ENTRY_BITMAP (0x01 | EXFAT_ENTRY_VALID)
92 #define EXFAT_ENTRY_UPCASE (0x02 | EXFAT_ENTRY_VALID)
93 #define EXFAT_ENTRY_LABEL (0x03 | EXFAT_ENTRY_VALID)
94 #define EXFAT_ENTRY_FILE (0x05 | EXFAT_ENTRY_VALID)
95 #define EXFAT_ENTRY_FILE_INFO (0x00 | EXFAT_ENTRY_VALID | EXFAT_ENTRY_CONTINUED)
96 #define EXFAT_ENTRY_FILE_NAME (0x01 | EXFAT_ENTRY_VALID | EXFAT_ENTRY_CONTINUED)
98 struct exfat_entry /* common container for all entries */
100 uint8_t type; /* any of EXFAT_ENTRY_xxx */
104 #define EXFAT_ENAME_MAX 15
106 struct exfat_bitmap /* allocated clusters bitmap */
108 uint8_t type; /* EXFAT_ENTRY_BITMAP */
109 uint8_t __unknown1[19];
110 le32_t start_cluster;
111 le64_t size; /* in bytes */
114 struct exfat_upcase /* upper case translation table */
116 uint8_t type; /* EXFAT_ENTRY_UPCASE */
117 uint8_t __unknown1[3];
119 uint8_t __unknown2[12];
120 le32_t start_cluster;
121 le64_t size; /* in bytes */
124 struct exfat_label /* volume label */
126 uint8_t type; /* EXFAT_ENTRY_LABEL */
127 uint8_t length; /* number of characters */
128 le16_t name[EXFAT_ENAME_MAX]; /* in UTF-16LE */
131 #define EXFAT_ATTRIB_RO 0x01
132 #define EXFAT_ATTRIB_HIDDEN 0x02
133 #define EXFAT_ATTRIB_SYSTEM 0x04
134 #define EXFAT_ATTRIB_VOLUME 0x08
135 #define EXFAT_ATTRIB_DIR 0x10
136 #define EXFAT_ATTRIB_ARCH 0x20
138 struct exfat_file /* file or directory */
140 uint8_t type; /* EXFAT_ENTRY_FILE */
141 uint8_t continuations;
143 le16_t attrib; /* combination of EXFAT_ATTRIB_xxx */
145 le16_t crtime, crdate; /* creation date and time */
146 le16_t mtime, mdate; /* latest modification date and time */
147 le16_t atime, adate; /* latest access date and time */
148 uint8_t crtime_cs; /* creation time in cs (centiseconds) */
149 uint8_t mtime_cs; /* latest modification time in cs */
150 uint8_t __unknown2[10];
153 #define EXFAT_FLAG_FRAGMENTED 1
154 #define EXFAT_FLAG_CONTIGUOUS 3
156 struct exfat_file_info /* file or directory info */
158 uint8_t type; /* EXFAT_ENTRY_FILE_INFO */
159 uint8_t flag; /* fragmented or contiguous */
164 le64_t real_size; /* in bytes, equals to size */
165 uint8_t __unknown3[4];
166 le32_t start_cluster;
167 le64_t size; /* in bytes, equals to real_size */
170 struct exfat_file_name /* file or directory name */
172 uint8_t type; /* EXFAT_ENTRY_FILE_NAME */
174 le16_t name[EXFAT_ENAME_MAX]; /* in UTF-16LE */
177 #endif /* ifndef EXFATFS_H_INCLUDED */