OSDN Git Service

Move endianness stuff into a separate header.
[android-x86/external-exfat.git] / libexfat / exfatfs.h
1 /*
2         exfatfs.h (29.08.09)
3         Definitions of structures and constants used in exFAT file system.
4
5         Copyright (C) 2009, 2010  Andrew Nayenko
6
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
26 typedef uint32_t cluster_t;             /* cluster number */
27
28 #define EXFAT_FIRST_DATA_CLUSTER 2
29
30 #define EXFAT_CLUSTER_FREE         0 /* free cluster */
31 #define EXFAT_CLUSTER_BAD 0xfffffff7 /* cluster contains bad block */
32 #define EXFAT_CLUSTER_END 0xffffffff /* final cluster of file or directory */
33
34 struct exfat_super_block
35 {
36         uint8_t jump[3];                                /* 0x00 jmp and nop instructions */
37         uint8_t oem_name[8];                    /* 0x03 "EXFAT   " */
38         uint8_t __unknown1[53];                 /* 0x0B ? always 0 */
39         le64_t block_start;                             /* 0x40 partition first block */
40         le64_t block_count;                             /* 0x48 partition blocks count */
41         le32_t fat_block_start;                 /* 0x50 FAT first block */
42         le32_t fat_block_count;                 /* 0x54 FAT blocks count */
43         le32_t cluster_block_start;             /* 0x58 first cluster block */
44         le32_t cluster_count;                   /* 0x5C total clusters count */
45         le32_t rootdir_cluster;                 /* 0x60 first cluster of the root dir */
46         le32_t volume_serial;                   /* 0x64 */
47         le16_t __unknown2;                              /* 0x68 version? always 0x00 0x01 */
48         le16_t volume_state;                    /* 0x6A */
49         uint8_t block_bits;                             /* 0x6C block size as (1 << n) */
50         uint8_t bpc_bits;                               /* 0x6D blocks per cluster as (1 << n) */
51         uint8_t __unknown3;                             /* 0x6E ? always 1 */
52         uint8_t __unknown4;                             /* 0x6F drive number? always 0x80 */
53         uint8_t allocated_percent;              /* 0x70 percentage of allocated space */
54         uint8_t __unknown5[397];                /* 0x71 padding? all zero */
55         le16_t boot_signature;                  /* the value of 0xAA55 */
56 };
57
58 #define EXFAT_ENTRY_VALID     0x80
59 #define EXFAT_ENTRY_CONTINUED 0x40
60
61 #define EXFAT_ENTRY_EOD       (0x00)
62 #define EXFAT_ENTRY_BITMAP    (0x01 | EXFAT_ENTRY_VALID)
63 #define EXFAT_ENTRY_UPCASE    (0x02 | EXFAT_ENTRY_VALID)
64 #define EXFAT_ENTRY_LABEL     (0x03 | EXFAT_ENTRY_VALID)
65 #define EXFAT_ENTRY_FILE      (0x05 | EXFAT_ENTRY_VALID)
66 #define EXFAT_ENTRY_FILE_INFO (0x00 | EXFAT_ENTRY_VALID | EXFAT_ENTRY_CONTINUED)
67 #define EXFAT_ENTRY_FILE_NAME (0x01 | EXFAT_ENTRY_VALID | EXFAT_ENTRY_CONTINUED)
68
69 struct exfat_entry                                      /* common container for all entries */
70 {
71         uint8_t type;                                   /* any of EXFAT_ENTRY_xxx */
72         uint8_t data[31];
73 };
74
75 #define EXFAT_ENAME_MAX 15
76
77 struct exfat_bitmap                                     /* allocated clusters bitmap */
78 {
79         uint8_t type;                                   /* EXFAT_ENTRY_BITMAP */
80         uint8_t __unknown1[19];
81         le32_t start_cluster;
82         le64_t size;                                    /* in bytes */
83 };
84
85 struct exfat_upcase                                     /* upper case translation table */
86 {
87         uint8_t type;                                   /* EXFAT_ENTRY_UPCASE */
88         uint8_t __unknown1[3];
89         le32_t checksum;
90         uint8_t __unknown2[12];
91         le32_t start_cluster;
92         le64_t size;                                    /* in bytes */
93 };
94
95 struct exfat_label                                      /* volume label */
96 {
97         uint8_t type;                                   /* EXFAT_ENTRY_LABEL */
98         uint8_t length;                                 /* number of characters */
99         le16_t name[EXFAT_ENAME_MAX];   /* in UTF-16LE */
100 };
101
102 #define EXFAT_ATTRIB_RO     0x01
103 #define EXFAT_ATTRIB_HIDDEN 0x02
104 #define EXFAT_ATTRIB_SYSTEM 0x04
105 #define EXFAT_ATTRIB_VOLUME 0x08
106 #define EXFAT_ATTRIB_DIR    0x10
107 #define EXFAT_ATTRIB_ARCH   0x20
108
109 struct exfat_file                                       /* file or directory */
110 {
111         uint8_t type;                                   /* EXFAT_ENTRY_FILE */
112         uint8_t continuations;
113         le16_t checksum;
114         le16_t attrib;                                  /* combination of EXFAT_ATTRIB_xxx */
115         le16_t __unknown1;
116         le16_t crtime, crdate;                  /* creation date and time */
117         le16_t mtime, mdate;                    /* latest modification date and time */
118         le16_t atime, adate;                    /* latest access date and time */
119         uint8_t crtime_cs;                              /* creation time in cs (centiseconds) */
120         uint8_t mtime_cs;                               /* latest modification time in cs */
121         uint8_t __unknown2[10];
122 };
123
124 #define EXFAT_FLAG_FRAGMENTED 1
125 #define EXFAT_FLAG_CONTIGUOUS 3
126
127 struct exfat_file_info                          /* file or directory info */
128 {
129         uint8_t type;                                   /* EXFAT_ENTRY_FILE_INFO */
130         uint8_t flag;                                   /* fragmented or contiguous */
131         uint8_t __unknown1;
132         uint8_t name_length;
133         le16_t name_hash;
134         le16_t __unknown2;
135         le64_t real_size;                               /* in bytes, equals to size */
136         uint8_t __unknown3[4];
137         le32_t start_cluster;
138         le64_t size;                                    /* in bytes, equals to real_size */
139 };
140
141 struct exfat_file_name                          /* file or directory name */
142 {
143         uint8_t type;                                   /* EXFAT_ENTRY_FILE_NAME */
144         uint8_t __unknown;
145         le16_t name[EXFAT_ENAME_MAX];   /* in UTF-16LE */
146 };
147
148 #endif /* ifndef EXFATFS_H_INCLUDED */