blob: 6c58a842a34f45eed49c28744512792713dce547 [file] [log] [blame]
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001/*
2 exfatfs.h (29.08.09)
3 Definitions of structures and constants used in exFAT file system.
4
bigbiff bigbiffca829c42013-01-28 08:14:25 -05005 Copyright (C) 2010-2013 Andrew Nayenko
bigbiff bigbiff9c754052013-01-09 09:09:08 -05006
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.
11
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.
16
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/>.
19*/
20
21#ifndef EXFATFS_H_INCLUDED
22#define EXFATFS_H_INCLUDED
23
24#include "byteorder.h"
25
26typedef uint32_t cluster_t; /* cluster number */
27
28#define EXFAT_FIRST_DATA_CLUSTER 2
29#define EXFAT_LAST_DATA_CLUSTER 0xfffffff6
30
31#define EXFAT_CLUSTER_FREE 0 /* free cluster */
32#define EXFAT_CLUSTER_BAD 0xfffffff7 /* cluster contains bad sector */
33#define EXFAT_CLUSTER_END 0xffffffff /* final cluster of file or directory */
34
35#define EXFAT_STATE_MOUNTED 2
36
37struct exfat_super_block
38{
39 uint8_t jump[3]; /* 0x00 jmp and nop instructions */
40 uint8_t oem_name[8]; /* 0x03 "EXFAT " */
41 uint8_t __unused1[53]; /* 0x0B always 0 */
42 le64_t sector_start; /* 0x40 partition first sector */
43 le64_t sector_count; /* 0x48 partition sectors count */
44 le32_t fat_sector_start; /* 0x50 FAT first sector */
45 le32_t fat_sector_count; /* 0x54 FAT sectors count */
46 le32_t cluster_sector_start; /* 0x58 first cluster sector */
47 le32_t cluster_count; /* 0x5C total clusters count */
48 le32_t rootdir_cluster; /* 0x60 first cluster of the root dir */
49 le32_t volume_serial; /* 0x64 volume serial number */
50 struct /* 0x68 FS version */
51 {
52 uint8_t minor;
53 uint8_t major;
54 }
55 version;
56 le16_t volume_state; /* 0x6A volume state flags */
57 uint8_t sector_bits; /* 0x6C sector size as (1 << n) */
58 uint8_t spc_bits; /* 0x6D sectors per cluster as (1 << n) */
59 uint8_t fat_count; /* 0x6E always 1 */
60 uint8_t drive_no; /* 0x6F always 0x80 */
61 uint8_t allocated_percent; /* 0x70 percentage of allocated space */
62 uint8_t __unused2[397]; /* 0x71 always 0 */
63 le16_t boot_signature; /* the value of 0xAA55 */
64}
65__attribute__((__packed__));
66
67#define EXFAT_ENTRY_VALID 0x80
68#define EXFAT_ENTRY_CONTINUED 0x40
69
70#define EXFAT_ENTRY_BITMAP (0x01 | EXFAT_ENTRY_VALID)
71#define EXFAT_ENTRY_UPCASE (0x02 | EXFAT_ENTRY_VALID)
72#define EXFAT_ENTRY_LABEL (0x03 | EXFAT_ENTRY_VALID)
73#define EXFAT_ENTRY_FILE (0x05 | EXFAT_ENTRY_VALID)
74#define EXFAT_ENTRY_FILE_INFO (0x00 | EXFAT_ENTRY_VALID | EXFAT_ENTRY_CONTINUED)
75#define EXFAT_ENTRY_FILE_NAME (0x01 | EXFAT_ENTRY_VALID | EXFAT_ENTRY_CONTINUED)
76
77struct exfat_entry /* common container for all entries */
78{
79 uint8_t type; /* any of EXFAT_ENTRY_xxx */
80 uint8_t data[31];
81}
82__attribute__((__packed__));
83
84#define EXFAT_ENAME_MAX 15
85
86struct exfat_entry_bitmap /* allocated clusters bitmap */
87{
88 uint8_t type; /* EXFAT_ENTRY_BITMAP */
89 uint8_t __unknown1[19];
90 le32_t start_cluster;
91 le64_t size; /* in bytes */
92}
93__attribute__((__packed__));
94
95struct exfat_entry_upcase /* upper case translation table */
96{
97 uint8_t type; /* EXFAT_ENTRY_UPCASE */
98 uint8_t __unknown1[3];
99 le32_t checksum;
100 uint8_t __unknown2[12];
101 le32_t start_cluster;
102 le64_t size; /* in bytes */
103}
104__attribute__((__packed__));
105
106struct exfat_entry_label /* volume label */
107{
108 uint8_t type; /* EXFAT_ENTRY_LABEL */
109 uint8_t length; /* number of characters */
110 le16_t name[EXFAT_ENAME_MAX]; /* in UTF-16LE */
111}
112__attribute__((__packed__));
113
114#define EXFAT_ATTRIB_RO 0x01
115#define EXFAT_ATTRIB_HIDDEN 0x02
116#define EXFAT_ATTRIB_SYSTEM 0x04
117#define EXFAT_ATTRIB_VOLUME 0x08
118#define EXFAT_ATTRIB_DIR 0x10
119#define EXFAT_ATTRIB_ARCH 0x20
120
121struct exfat_entry_meta1 /* file or directory info (part 1) */
122{
123 uint8_t type; /* EXFAT_ENTRY_FILE */
124 uint8_t continuations;
125 le16_t checksum;
126 le16_t attrib; /* combination of EXFAT_ATTRIB_xxx */
127 le16_t __unknown1;
128 le16_t crtime, crdate; /* creation date and time */
129 le16_t mtime, mdate; /* latest modification date and time */
130 le16_t atime, adate; /* latest access date and time */
131 uint8_t crtime_cs; /* creation time in cs (centiseconds) */
132 uint8_t mtime_cs; /* latest modification time in cs */
133 uint8_t __unknown2[10];
134}
135__attribute__((__packed__));
136
137#define EXFAT_FLAG_ALWAYS1 (1u << 0)
138#define EXFAT_FLAG_CONTIGUOUS (1u << 1)
139
140struct exfat_entry_meta2 /* file or directory info (part 2) */
141{
142 uint8_t type; /* EXFAT_ENTRY_FILE_INFO */
143 uint8_t flags; /* combination of EXFAT_FLAG_xxx */
144 uint8_t __unknown1;
145 uint8_t name_length;
146 le16_t name_hash;
147 le16_t __unknown2;
148 le64_t real_size; /* in bytes, equals to size */
149 uint8_t __unknown3[4];
150 le32_t start_cluster;
151 le64_t size; /* in bytes, equals to real_size */
152}
153__attribute__((__packed__));
154
155struct exfat_entry_name /* file or directory name */
156{
157 uint8_t type; /* EXFAT_ENTRY_FILE_NAME */
158 uint8_t __unknown;
159 le16_t name[EXFAT_ENAME_MAX]; /* in UTF-16LE */
160}
161__attribute__((__packed__));
162
163#endif /* ifndef EXFATFS_H_INCLUDED */