OSDN Git Service

Implement uid and gid mount options.
[android-x86/external-exfat.git] / libexfat / exfat.h
1 /*
2  *  exfat.h
3  *  Definitions of structures and constants used in exFAT file system
4  *  implementation.
5  *
6  *  Created by Andrew Nayenko on 29.08.09.
7  *  This software is distributed under the GNU General Public License 
8  *  version 3 or any later.
9  */
10
11 #ifndef EXFAT_H_INCLUDED
12 #define EXFAT_H_INCLUDED
13
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <time.h>
17 #include <sys/stat.h>
18 #include <sys/types.h>
19 #include "exfatfs.h"
20
21 #define EXFAT_VERSION_MAJOR 0
22 #define EXFAT_VERSION_MINOR 5
23
24 #define EXFAT_NAME_MAX 256
25 #define EXFAT_ATTRIB_CONTIGUOUS 0x10000
26 #define EXFAT_ATTRIB_CACHED     0x20000
27 #define EXFAT_ATTRIB_DIRTY      0x40000
28 #define EXFAT_ATTRIB_UNLINKED   0x80000
29 #define IS_CONTIGUOUS(node) (((node).flags & EXFAT_ATTRIB_CONTIGUOUS) != 0)
30 #define BLOCK_SIZE(sb) (1 << (sb).block_bits)
31 #define CLUSTER_SIZE(sb) (BLOCK_SIZE(sb) << (sb).bpc_bits)
32 #define CLUSTER_INVALID(c) ((c) == EXFAT_CLUSTER_BAD || (c) == EXFAT_CLUSTER_END)
33
34 #define MIN(a, b) ((a) < (b) ? (a) : (b))
35 #define DIV_ROUND_UP(x, d) (((x) + (d) - 1) / (d))
36
37 struct exfat_node
38 {
39         struct exfat_node* parent;
40         struct exfat_node* child;
41         struct exfat_node* next;
42         struct exfat_node* prev;
43
44         int references;
45         uint32_t fptr_index;
46         cluster_t fptr_cluster;
47         cluster_t entry_cluster;
48         off_t entry_offset;
49         cluster_t start_cluster;
50         int flags;
51         uint64_t size;
52         time_t mtime, atime;
53         le16_t name[EXFAT_NAME_MAX + 1];
54 };
55
56 struct exfat
57 {
58         struct exfat_super_block* sb;
59         int fd;
60         le16_t* upcase;
61         size_t upcase_chars;
62         struct exfat_node* root;
63         struct
64         {
65                 cluster_t start_cluster;
66                 uint32_t size;                          /* in bits */
67                 uint8_t* chunk;
68                 uint32_t chunk_size;            /* in bits */
69                 int dirty;
70         }
71         cmap;
72         void* zero_block;
73         int dmask, fmask;
74         uid_t uid;
75         gid_t gid;
76 };
77
78 /* in-core nodes iterator */
79 struct exfat_iterator
80 {
81         struct exfat_node* parent;
82         struct exfat_node* current;
83 };
84
85 extern int exfat_errors;
86
87 void exfat_bug(const char* format, ...)
88         __attribute__((format(printf, 1, 2), noreturn));
89 void exfat_error(const char* format, ...)
90         __attribute__((format(printf, 1, 2)));
91 void exfat_warn(const char* format, ...)
92         __attribute__((format(printf, 1, 2)));
93 void exfat_debug(const char* format, ...)
94         __attribute__((format(printf, 1, 2)));
95
96 void exfat_read_raw(void* buffer, size_t size, off_t offset, int fd);
97 void exfat_write_raw(const void* buffer, size_t size, off_t offset, int fd);
98 ssize_t exfat_read(const struct exfat* ef, struct exfat_node* node,
99                 void* buffer, size_t size, off_t offset);
100 ssize_t exfat_write(struct exfat* ef, struct exfat_node* node,
101                 const void* buffer, size_t size, off_t offset);
102
103 int exfat_opendir(struct exfat* ef, struct exfat_node* dir,
104                 struct exfat_iterator* it);
105 void exfat_closedir(struct exfat* ef, struct exfat_iterator* it);
106 struct exfat_node* exfat_readdir(struct exfat* ef, struct exfat_iterator* it);
107 int exfat_lookup(struct exfat* ef, struct exfat_node** node,
108                 const char* path);
109 int exfat_split(struct exfat* ef, struct exfat_node** node, le16_t* name,
110                 const char* path);
111
112 off_t exfat_c2o(const struct exfat* ef, cluster_t cluster);
113 cluster_t exfat_next_cluster(const struct exfat* ef,
114                 const struct exfat_node* node, cluster_t cluster);
115 cluster_t exfat_advance_cluster(const struct exfat* ef,
116                 struct exfat_node* node, uint32_t count);
117 void exfat_flush_cmap(struct exfat* ef);
118 int exfat_truncate(struct exfat* ef, struct exfat_node* node, uint64_t size);
119
120 void exfat_stat(const struct exfat* ef, const struct exfat_node* node,
121                 struct stat* stbuf);
122 time_t exfat_exfat2unix(le16_t date, le16_t time);
123 void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time);
124 void exfat_get_name(const struct exfat_node* node, char* buffer, size_t n);
125 uint16_t exfat_start_checksum(const struct exfat_file* entry);
126 uint16_t exfat_add_checksum(const void* entry, uint16_t sum);
127 le16_t exfat_calc_checksum(const struct exfat_file* meta1,
128                 const struct exfat_file_info* meta2, const le16_t* name);
129 le16_t exfat_calc_name_hash(const struct exfat* ef, const le16_t* name);
130
131 int utf16_to_utf8(char* output, const le16_t* input, size_t outsize,
132                 size_t insize);
133 int utf8_to_utf16(le16_t* output, const char* input, size_t outsize,
134                 size_t insize);
135 size_t utf16_length(const le16_t* str);
136
137 struct exfat_node* exfat_get_node(struct exfat_node* node);
138 void exfat_put_node(struct exfat* ef, struct exfat_node* node);
139 int exfat_cache_directory(struct exfat* ef, struct exfat_node* dir);
140 void exfat_reset_cache(struct exfat* ef);
141 void exfat_flush_node(struct exfat* ef, struct exfat_node* node);
142 int exfat_unlink(struct exfat* ef, struct exfat_node* node);
143 int exfat_rmdir(struct exfat* ef, struct exfat_node* node);
144 int exfat_mknod(struct exfat* ef, const char* path);
145 int exfat_mkdir(struct exfat* ef, const char* path);
146 void exfat_utimes(struct exfat_node* node, const struct timespec tv[2]);
147
148 int exfat_mount(struct exfat* ef, const char* spec, const char* options);
149 void exfat_unmount(struct exfat* ef);
150
151 #endif /* ifndef EXFAT_H_INCLUDED */