2 * Copyright (c) 2008 Jakub Jermar
3 * Copyright (c) 2011 Oleg Romanenko
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * - Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * - The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include <sys/types.h>
38 #define EXFAT_FILENAME_LEN 255
39 #define EXFAT_NAME_PART_LEN 15
41 #define EXFAT_TYPE_UNUSED 0x00
42 #define EXFAT_TYPE_USED 0x80
43 #define EXFAT_TYPE_VOLLABEL 0x83
44 #define EXFAT_TYPE_BITMAP 0x81
45 #define EXFAT_TYPE_UCTABLE 0x82
46 #define EXFAT_TYPE_GUID 0xA0
47 #define EXFAT_TYPE_FILE 0x85
48 #define EXFAT_TYPE_STREAM 0xC0
49 #define EXFAT_TYPE_NAME 0xC1
51 #define EXFAT_ATTR_RDONLY 0x01
52 #define EXFAT_ATTR_HIDDEN 0x02
53 #define EXFAT_ATTR_SYSTEM 0x04
54 #define EXFAT_ATTR_SUBDIR 0x10
55 #define EXFAT_ATTR_ARCHIVE 0x20
58 /* All dentry structs should have 31 byte size */
63 } __attribute__ ((packed
)) exfat_vollabel_dentry_t
;
67 uint8_t _reserved
[18];
70 } __attribute__ ((packed
)) exfat_bitmap_dentry_t
;
73 uint8_t _reserved1
[3];
75 uint8_t _reserved2
[12];
78 } __attribute__ ((packed
)) exfat_uctable_dentry_t
;
81 uint8_t count
; /* Always zero */
85 uint8_t _reserved
[10];
86 } __attribute__ ((packed
)) exfat_guid_dentry_t
;
92 uint8_t _reserved1
[2];
101 uint8_t _reserved2
[7];
102 } __attribute__ ((packed
)) exfat_file_dentry_t
;
106 uint8_t _reserved1
[1];
109 uint8_t _reserved2
[2];
110 uint64_t valid_data_size
;
111 uint8_t _reserved3
[4];
114 } __attribute__ ((packed
)) exfat_stream_dentry_t
;
118 uint16_t name
[EXFAT_NAME_PART_LEN
];
119 } __attribute__ ((packed
)) exfat_name_dentry_t
;
125 exfat_vollabel_dentry_t vollabel
;
126 exfat_bitmap_dentry_t bitmap
;
127 exfat_uctable_dentry_t uctable
;
128 exfat_guid_dentry_t guid
;
129 exfat_file_dentry_t file
;
130 exfat_stream_dentry_t stream
;
131 exfat_name_dentry_t name
;
133 } __attribute__ ((packed
)) exfat_dentry_t
;
140 EXFAT_DENTRY_VOLLABEL
,
142 EXFAT_DENTRY_UCTABLE
,
147 } exfat_dentry_clsf_t
;
150 typedef struct exfat_bs
{
151 uint8_t jump
[3]; /* 0x00 jmp and nop instructions */
152 uint8_t oem_name
[8]; /* 0x03 "EXFAT " */
153 uint8_t __reserved
[53]; /* 0x0B always 0 */
154 uint64_t volume_start
; /* 0x40 partition first sector */
155 uint64_t volume_count
; /* 0x48 partition sectors count */
156 uint32_t fat_sector_start
; /* 0x50 FAT first sector */
157 uint32_t fat_sector_count
; /* 0x54 FAT sectors count */
158 uint32_t data_start_sector
; /* 0x58 Data region first cluster sector */
159 uint32_t data_clusters
; /* 0x5C total clusters count */
160 uint32_t rootdir_cluster
; /* 0x60 first cluster of the root dir */
161 uint32_t volume_serial
; /* 0x64 volume serial number */
162 struct { /* 0x68 FS version */
165 } __attribute__ ((packed
)) version
;
166 uint16_t volume_flags
; /* 0x6A volume state flags */
167 uint8_t bytes_per_sector
; /* 0x6C sector size as (1 << n) */
168 uint8_t sec_per_cluster
; /* 0x6D sectors per cluster as (1 << n) */
169 uint8_t fat_count
; /* 0x6E always 1 */
170 uint8_t drive_no
; /* 0x6F always 0x80 */
171 uint8_t allocated_percent
; /* 0x70 percentage of allocated space */
172 uint8_t _reserved2
[7]; /* 0x71 reserved */
173 uint8_t bootcode
[390]; /* Boot code */
174 uint16_t signature
; /* the value of 0xAA55 */
175 } __attribute__((__packed__
)) exfat_bs_t
;