source: mainline/uspace/app/mkexfat/exfat.h@ b2906c0

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since b2906c0 was 8d2dd7f2, checked in by Jakub Jermar <jakub@…>, 8 years ago

Reduce the number of files that include <sys/types.h>

  • Property mode set to 100644
File size: 5.3 KB
Line 
1/*
2 * Copyright (c) 2008 Jakub Jermar
3 * Copyright (c) 2011 Oleg Romanenko
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
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.
17 *
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.
28 */
29
30/** @addtogroup fs
31 * @{
32 */
33
34#include <stdint.h>
35#include <stdbool.h>
36
37#define EXFAT_FILENAME_LEN 255
38#define EXFAT_NAME_PART_LEN 15
39
40#define EXFAT_TYPE_UNUSED 0x00
41#define EXFAT_TYPE_USED 0x80
42#define EXFAT_TYPE_VOLLABEL 0x83
43#define EXFAT_TYPE_BITMAP 0x81
44#define EXFAT_TYPE_UCTABLE 0x82
45#define EXFAT_TYPE_GUID 0xA0
46#define EXFAT_TYPE_FILE 0x85
47#define EXFAT_TYPE_STREAM 0xC0
48#define EXFAT_TYPE_NAME 0xC1
49
50#define EXFAT_ATTR_RDONLY 0x01
51#define EXFAT_ATTR_HIDDEN 0x02
52#define EXFAT_ATTR_SYSTEM 0x04
53#define EXFAT_ATTR_SUBDIR 0x10
54#define EXFAT_ATTR_ARCHIVE 0x20
55
56
57/* All dentry structs should have 31 byte size */
58typedef struct {
59 uint8_t size;
60 uint16_t label[11];
61 uint8_t _reserved[8];
62} __attribute__ ((packed)) exfat_vollabel_dentry_t;
63
64typedef struct {
65 uint8_t flags;
66 uint8_t _reserved[18];
67 uint32_t firstc;
68 uint64_t size;
69} __attribute__ ((packed)) exfat_bitmap_dentry_t;
70
71typedef struct {
72 uint8_t _reserved1[3];
73 uint32_t checksum;
74 uint8_t _reserved2[12];
75 uint32_t firstc;
76 uint64_t size;
77} __attribute__ ((packed)) exfat_uctable_dentry_t;
78
79typedef struct {
80 uint8_t count; /* Always zero */
81 uint16_t checksum;
82 uint16_t flags;
83 uint8_t guid[16];
84 uint8_t _reserved[10];
85} __attribute__ ((packed)) exfat_guid_dentry_t;
86
87typedef struct {
88 uint8_t count;
89 uint16_t checksum;
90 uint16_t attr;
91 uint8_t _reserved1[2];
92 uint32_t ctime;
93 uint32_t mtime;
94 uint32_t atime;
95 uint8_t ctime_fine;
96 uint8_t mtime_fine;
97 uint8_t ctime_tz;
98 uint8_t mtime_tz;
99 uint8_t atime_tz;
100 uint8_t _reserved2[7];
101} __attribute__ ((packed)) exfat_file_dentry_t;
102
103typedef struct {
104 uint8_t flags;
105 uint8_t _reserved1[1];
106 uint8_t name_size;
107 uint16_t hash;
108 uint8_t _reserved2[2];
109 uint64_t valid_data_size;
110 uint8_t _reserved3[4];
111 uint32_t firstc;
112 uint64_t data_size;
113} __attribute__ ((packed)) exfat_stream_dentry_t;
114
115typedef struct {
116 uint8_t flags;
117 uint16_t name[EXFAT_NAME_PART_LEN];
118} __attribute__ ((packed)) exfat_name_dentry_t;
119
120
121typedef struct {
122 uint8_t type;
123 union {
124 exfat_vollabel_dentry_t vollabel;
125 exfat_bitmap_dentry_t bitmap;
126 exfat_uctable_dentry_t uctable;
127 exfat_guid_dentry_t guid;
128 exfat_file_dentry_t file;
129 exfat_stream_dentry_t stream;
130 exfat_name_dentry_t name;
131 };
132} __attribute__ ((packed)) exfat_dentry_t;
133
134
135typedef enum {
136 EXFAT_DENTRY_SKIP,
137 EXFAT_DENTRY_LAST,
138 EXFAT_DENTRY_FREE,
139 EXFAT_DENTRY_VOLLABEL,
140 EXFAT_DENTRY_BITMAP,
141 EXFAT_DENTRY_UCTABLE,
142 EXFAT_DENTRY_GUID,
143 EXFAT_DENTRY_FILE,
144 EXFAT_DENTRY_STREAM,
145 EXFAT_DENTRY_NAME
146} exfat_dentry_clsf_t;
147
148
149typedef struct exfat_bs {
150 uint8_t jump[3]; /* 0x00 jmp and nop instructions */
151 uint8_t oem_name[8]; /* 0x03 "EXFAT " */
152 uint8_t __reserved[53]; /* 0x0B always 0 */
153 uint64_t volume_start; /* 0x40 partition first sector */
154 uint64_t volume_count; /* 0x48 partition sectors count */
155 uint32_t fat_sector_start; /* 0x50 FAT first sector */
156 uint32_t fat_sector_count; /* 0x54 FAT sectors count */
157 uint32_t data_start_sector; /* 0x58 Data region first cluster sector */
158 uint32_t data_clusters; /* 0x5C total clusters count */
159 uint32_t rootdir_cluster; /* 0x60 first cluster of the root dir */
160 uint32_t volume_serial; /* 0x64 volume serial number */
161 struct { /* 0x68 FS version */
162 uint8_t minor;
163 uint8_t major;
164 } __attribute__ ((packed)) version;
165 uint16_t volume_flags; /* 0x6A volume state flags */
166 uint8_t bytes_per_sector; /* 0x6C sector size as (1 << n) */
167 uint8_t sec_per_cluster; /* 0x6D sectors per cluster as (1 << n) */
168 uint8_t fat_count; /* 0x6E always 1 */
169 uint8_t drive_no; /* 0x6F always 0x80 */
170 uint8_t allocated_percent; /* 0x70 percentage of allocated space */
171 uint8_t _reserved2[7]; /* 0x71 reserved */
172 uint8_t bootcode[390]; /* Boot code */
173 uint16_t signature; /* the value of 0xAA55 */
174} __attribute__((__packed__)) exfat_bs_t;
175
176/**
177 * @}
178 */
Note: See TracBrowser for help on using the repository browser.