3 * Definitions of structures and constants used in exFAT file system
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.
11 #ifndef EXFAT_H_INCLUDED
12 #define EXFAT_H_INCLUDED
18 #include <sys/types.h>
21 #define EXFAT_VERSION_MAJOR 0
22 #define EXFAT_VERSION_MINOR 5
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)
34 #define MIN(a, b) ((a) < (b) ? (a) : (b))
35 #define DIV_ROUND_UP(x, d) (((x) + (d) - 1) / (d))
39 struct exfat_node* parent;
40 struct exfat_node* child;
41 struct exfat_node* next;
42 struct exfat_node* prev;
46 cluster_t fptr_cluster;
47 cluster_t entry_cluster;
49 cluster_t start_cluster;
53 le16_t name[EXFAT_NAME_MAX + 1];
58 struct exfat_super_block* sb;
62 struct exfat_node* root;
65 cluster_t start_cluster;
66 uint32_t size; /* in bits */
68 uint32_t chunk_size; /* in bits */
76 /* in-core nodes iterator */
79 struct exfat_node* parent;
80 struct exfat_node* current;
83 extern int exfat_errors;
85 void exfat_bug(const char* format, ...);
86 void exfat_error(const char* format, ...);
87 void exfat_warn(const char* format, ...);
88 void exfat_debug(const char* format, ...);
90 void exfat_read_raw(void* buffer, size_t size, off_t offset, int fd);
91 void exfat_write_raw(const void* buffer, size_t size, off_t offset, int fd);
92 ssize_t exfat_read(const struct exfat* ef, struct exfat_node* node,
93 void* buffer, size_t size, off_t offset);
94 ssize_t exfat_write(struct exfat* ef, struct exfat_node* node,
95 const void* buffer, size_t size, off_t offset);
97 int exfat_opendir(struct exfat* ef, struct exfat_node* dir,
98 struct exfat_iterator* it);
99 void exfat_closedir(struct exfat* ef, struct exfat_iterator* it);
100 struct exfat_node* exfat_readdir(struct exfat* ef, struct exfat_iterator* it);
101 int exfat_lookup(struct exfat* ef, struct exfat_node** node,
103 int exfat_split(struct exfat* ef, struct exfat_node** node, le16_t* name,
106 off_t exfat_c2o(const struct exfat* ef, cluster_t cluster);
107 cluster_t exfat_next_cluster(const struct exfat* ef,
108 const struct exfat_node* node, cluster_t cluster);
109 cluster_t exfat_advance_cluster(const struct exfat* ef,
110 struct exfat_node* node, uint32_t count);
111 void exfat_flush_cmap(struct exfat* ef);
112 int exfat_truncate(struct exfat* ef, struct exfat_node* node, uint64_t size);
114 void exfat_stat(const struct exfat* ef, const struct exfat_node* node,
116 time_t exfat_exfat2unix(le16_t date, le16_t time);
117 void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time);
118 void exfat_get_name(const struct exfat_node* node, char* buffer, size_t n);
119 uint16_t exfat_start_checksum(const struct exfat_file* entry);
120 uint16_t exfat_add_checksum(const void* entry, uint16_t sum);
121 le16_t exfat_calc_checksum(const struct exfat_file* meta1,
122 const struct exfat_file_info* meta2, const le16_t* name);
123 le16_t exfat_calc_name_hash(const struct exfat* ef, const le16_t* name);
125 int utf16_to_utf8(char* output, const le16_t* input, size_t outsize,
127 int utf8_to_utf16(le16_t* output, const char* input, size_t outsize,
129 size_t utf16_length(const le16_t* str);
131 struct exfat_node* exfat_get_node(struct exfat_node* node);
132 void exfat_put_node(struct exfat* ef, struct exfat_node* node);
133 int exfat_cache_directory(struct exfat* ef, struct exfat_node* dir);
134 void exfat_reset_cache(struct exfat* ef);
135 void exfat_flush_node(struct exfat* ef, struct exfat_node* node);
136 int exfat_unlink(struct exfat* ef, struct exfat_node* node);
137 int exfat_rmdir(struct exfat* ef, struct exfat_node* node);
138 int exfat_mknod(struct exfat* ef, const char* path);
139 int exfat_mkdir(struct exfat* ef, const char* path);
141 int exfat_mount(struct exfat* ef, const char* spec, const char* options);
142 void exfat_unmount(struct exfat* ef);
144 #endif /* ifndef EXFAT_H_INCLUDED */