merge mainline changes
[helenos.git] / uspace / app / mkexfat / exfat.h
blob60018bc535306e23dae4714efa3e65dcb3f805c7
1 /*
2 * Copyright (c) 2008 Jakub Jermar
3 * Copyright (c) 2011 Oleg Romanenko
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
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.
30 /** @addtogroup fs
31 * @{
34 #include <sys/types.h>
35 #include <stdint.h>
36 #include <stdbool.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 */
59 typedef struct {
60 uint8_t size;
61 uint16_t label[11];
62 uint8_t _reserved[8];
63 } __attribute__ ((packed)) exfat_vollabel_dentry_t;
65 typedef struct {
66 uint8_t flags;
67 uint8_t _reserved[18];
68 uint32_t firstc;
69 uint64_t size;
70 } __attribute__ ((packed)) exfat_bitmap_dentry_t;
72 typedef struct {
73 uint8_t _reserved1[3];
74 uint32_t checksum;
75 uint8_t _reserved2[12];
76 uint32_t firstc;
77 uint64_t size;
78 } __attribute__ ((packed)) exfat_uctable_dentry_t;
80 typedef struct {
81 uint8_t count; /* Always zero */
82 uint16_t checksum;
83 uint16_t flags;
84 uint8_t guid[16];
85 uint8_t _reserved[10];
86 } __attribute__ ((packed)) exfat_guid_dentry_t;
88 typedef struct {
89 uint8_t count;
90 uint16_t checksum;
91 uint16_t attr;
92 uint8_t _reserved1[2];
93 uint32_t ctime;
94 uint32_t mtime;
95 uint32_t atime;
96 uint8_t ctime_fine;
97 uint8_t mtime_fine;
98 uint8_t ctime_tz;
99 uint8_t mtime_tz;
100 uint8_t atime_tz;
101 uint8_t _reserved2[7];
102 } __attribute__ ((packed)) exfat_file_dentry_t;
104 typedef struct {
105 uint8_t flags;
106 uint8_t _reserved1[1];
107 uint8_t name_size;
108 uint16_t hash;
109 uint8_t _reserved2[2];
110 uint64_t valid_data_size;
111 uint8_t _reserved3[4];
112 uint32_t firstc;
113 uint64_t data_size;
114 } __attribute__ ((packed)) exfat_stream_dentry_t;
116 typedef struct {
117 uint8_t flags;
118 uint16_t name[EXFAT_NAME_PART_LEN];
119 } __attribute__ ((packed)) exfat_name_dentry_t;
122 typedef struct {
123 uint8_t type;
124 union {
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;
136 typedef enum {
137 EXFAT_DENTRY_SKIP,
138 EXFAT_DENTRY_LAST,
139 EXFAT_DENTRY_FREE,
140 EXFAT_DENTRY_VOLLABEL,
141 EXFAT_DENTRY_BITMAP,
142 EXFAT_DENTRY_UCTABLE,
143 EXFAT_DENTRY_GUID,
144 EXFAT_DENTRY_FILE,
145 EXFAT_DENTRY_STREAM,
146 EXFAT_DENTRY_NAME
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 */
163 uint8_t minor;
164 uint8_t major;
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;
178 * @}