blob: a436daa63905a84787e807d7fb5bc8d4eb950ab8 [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 bigbiff61cdc022013-08-08 08:35:06 -04005 Free exFAT implementation.
bigbiffc40c1c52014-11-01 09:34:57 -04006 Copyright (C) 2010-2013 Andrew Nayenko
bigbiff bigbiff9c754052013-01-09 09:09:08 -05007
bigbiff bigbiff61cdc022013-08-08 08:35:06 -04008 This program is free software; you can redistribute it and/or modify
bigbiff bigbiff9c754052013-01-09 09:09:08 -05009 it under the terms of the GNU General Public License as published by
bigbiff bigbiff61cdc022013-08-08 08:35:06 -040010 the Free Software Foundation, either version 2 of the License, or
bigbiff bigbiff9c754052013-01-09 09:09:08 -050011 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
bigbiff bigbiff61cdc022013-08-08 08:35:06 -040018 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bigbiff bigbiff9c754052013-01-09 09:09:08 -050021*/
22
23#ifndef EXFATFS_H_INCLUDED
24#define EXFATFS_H_INCLUDED
25
26#include "byteorder.h"
27
28typedef uint32_t cluster_t; /* cluster number */
29
30#define EXFAT_FIRST_DATA_CLUSTER 2
31#define EXFAT_LAST_DATA_CLUSTER 0xfffffff6
32
33#define EXFAT_CLUSTER_FREE 0 /* free cluster */
34#define EXFAT_CLUSTER_BAD 0xfffffff7 /* cluster contains bad sector */
35#define EXFAT_CLUSTER_END 0xffffffff /* final cluster of file or directory */
36
37#define EXFAT_STATE_MOUNTED 2
38
39struct exfat_super_block
40{
41 uint8_t jump[3]; /* 0x00 jmp and nop instructions */
42 uint8_t oem_name[8]; /* 0x03 "EXFAT " */
43 uint8_t __unused1[53]; /* 0x0B always 0 */
44 le64_t sector_start; /* 0x40 partition first sector */
45 le64_t sector_count; /* 0x48 partition sectors count */
46 le32_t fat_sector_start; /* 0x50 FAT first sector */
47 le32_t fat_sector_count; /* 0x54 FAT sectors count */
48 le32_t cluster_sector_start; /* 0x58 first cluster sector */
49 le32_t cluster_count; /* 0x5C total clusters count */
50 le32_t rootdir_cluster; /* 0x60 first cluster of the root dir */
51 le32_t volume_serial; /* 0x64 volume serial number */
52 struct /* 0x68 FS version */
53 {
54 uint8_t minor;
55 uint8_t major;
56 }
57 version;
58 le16_t volume_state; /* 0x6A volume state flags */
59 uint8_t sector_bits; /* 0x6C sector size as (1 << n) */
60 uint8_t spc_bits; /* 0x6D sectors per cluster as (1 << n) */
61 uint8_t fat_count; /* 0x6E always 1 */
62 uint8_t drive_no; /* 0x6F always 0x80 */
63 uint8_t allocated_percent; /* 0x70 percentage of allocated space */
64 uint8_t __unused2[397]; /* 0x71 always 0 */
65 le16_t boot_signature; /* the value of 0xAA55 */
66}
bigbiff bigbiff61cdc022013-08-08 08:35:06 -040067PACKED;
68STATIC_ASSERT(sizeof(struct exfat_super_block) == 512);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050069
70#define EXFAT_ENTRY_VALID 0x80
71#define EXFAT_ENTRY_CONTINUED 0x40
72
73#define EXFAT_ENTRY_BITMAP (0x01 | EXFAT_ENTRY_VALID)
74#define EXFAT_ENTRY_UPCASE (0x02 | EXFAT_ENTRY_VALID)
75#define EXFAT_ENTRY_LABEL (0x03 | EXFAT_ENTRY_VALID)
76#define EXFAT_ENTRY_FILE (0x05 | EXFAT_ENTRY_VALID)
77#define EXFAT_ENTRY_FILE_INFO (0x00 | EXFAT_ENTRY_VALID | EXFAT_ENTRY_CONTINUED)
78#define EXFAT_ENTRY_FILE_NAME (0x01 | EXFAT_ENTRY_VALID | EXFAT_ENTRY_CONTINUED)
79
80struct exfat_entry /* common container for all entries */
81{
82 uint8_t type; /* any of EXFAT_ENTRY_xxx */
83 uint8_t data[31];
84}
bigbiff bigbiff61cdc022013-08-08 08:35:06 -040085PACKED;
86STATIC_ASSERT(sizeof(struct exfat_entry) == 32);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050087
88#define EXFAT_ENAME_MAX 15
89
90struct exfat_entry_bitmap /* allocated clusters bitmap */
91{
92 uint8_t type; /* EXFAT_ENTRY_BITMAP */
93 uint8_t __unknown1[19];
94 le32_t start_cluster;
95 le64_t size; /* in bytes */
96}
bigbiff bigbiff61cdc022013-08-08 08:35:06 -040097PACKED;
98STATIC_ASSERT(sizeof(struct exfat_entry_bitmap) == 32);
bigbiff bigbiff9c754052013-01-09 09:09:08 -050099
100struct exfat_entry_upcase /* upper case translation table */
101{
102 uint8_t type; /* EXFAT_ENTRY_UPCASE */
103 uint8_t __unknown1[3];
104 le32_t checksum;
105 uint8_t __unknown2[12];
106 le32_t start_cluster;
107 le64_t size; /* in bytes */
108}
bigbiff bigbiff61cdc022013-08-08 08:35:06 -0400109PACKED;
110STATIC_ASSERT(sizeof(struct exfat_entry_upcase) == 32);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500111
112struct exfat_entry_label /* volume label */
113{
114 uint8_t type; /* EXFAT_ENTRY_LABEL */
115 uint8_t length; /* number of characters */
116 le16_t name[EXFAT_ENAME_MAX]; /* in UTF-16LE */
117}
bigbiff bigbiff61cdc022013-08-08 08:35:06 -0400118PACKED;
119STATIC_ASSERT(sizeof(struct exfat_entry_label) == 32);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500120
121#define EXFAT_ATTRIB_RO 0x01
122#define EXFAT_ATTRIB_HIDDEN 0x02
123#define EXFAT_ATTRIB_SYSTEM 0x04
124#define EXFAT_ATTRIB_VOLUME 0x08
125#define EXFAT_ATTRIB_DIR 0x10
126#define EXFAT_ATTRIB_ARCH 0x20
127
128struct exfat_entry_meta1 /* file or directory info (part 1) */
129{
130 uint8_t type; /* EXFAT_ENTRY_FILE */
131 uint8_t continuations;
132 le16_t checksum;
133 le16_t attrib; /* combination of EXFAT_ATTRIB_xxx */
134 le16_t __unknown1;
135 le16_t crtime, crdate; /* creation date and time */
136 le16_t mtime, mdate; /* latest modification date and time */
137 le16_t atime, adate; /* latest access date and time */
138 uint8_t crtime_cs; /* creation time in cs (centiseconds) */
139 uint8_t mtime_cs; /* latest modification time in cs */
140 uint8_t __unknown2[10];
141}
bigbiff bigbiff61cdc022013-08-08 08:35:06 -0400142PACKED;
143STATIC_ASSERT(sizeof(struct exfat_entry_meta1) == 32);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500144
145#define EXFAT_FLAG_ALWAYS1 (1u << 0)
146#define EXFAT_FLAG_CONTIGUOUS (1u << 1)
147
148struct exfat_entry_meta2 /* file or directory info (part 2) */
149{
150 uint8_t type; /* EXFAT_ENTRY_FILE_INFO */
151 uint8_t flags; /* combination of EXFAT_FLAG_xxx */
152 uint8_t __unknown1;
153 uint8_t name_length;
154 le16_t name_hash;
155 le16_t __unknown2;
bigbiffc40c1c52014-11-01 09:34:57 -0400156 le64_t real_size; /* in bytes, equals to size */
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500157 uint8_t __unknown3[4];
158 le32_t start_cluster;
bigbiffc40c1c52014-11-01 09:34:57 -0400159 le64_t size; /* in bytes, equals to real_size */
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500160}
bigbiff bigbiff61cdc022013-08-08 08:35:06 -0400161PACKED;
162STATIC_ASSERT(sizeof(struct exfat_entry_meta2) == 32);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500163
164struct exfat_entry_name /* file or directory name */
165{
166 uint8_t type; /* EXFAT_ENTRY_FILE_NAME */
167 uint8_t __unknown;
168 le16_t name[EXFAT_ENAME_MAX]; /* in UTF-16LE */
169}
bigbiff bigbiff61cdc022013-08-08 08:35:06 -0400170PACKED;
171STATIC_ASSERT(sizeof(struct exfat_entry_name) == 32);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500172
173#endif /* ifndef EXFATFS_H_INCLUDED */