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
23 #define EXFAT_VERSION_PATCH 0
25 #define EXFAT_NAME_MAX 256
26 #define EXFAT_ATTRIB_CONTIGUOUS 0x10000
27 #define EXFAT_ATTRIB_CACHED 0x20000
28 #define EXFAT_ATTRIB_DIRTY 0x40000
29 #define EXFAT_ATTRIB_UNLINKED 0x80000
30 #define IS_CONTIGUOUS(node) (((node).flags & EXFAT_ATTRIB_CONTIGUOUS) != 0)
31 #define BLOCK_SIZE(sb) (1 << (sb).block_bits)
32 #define CLUSTER_SIZE(sb) (BLOCK_SIZE(sb) << (sb).bpc_bits)
33 #define CLUSTER_INVALID(c) ((c) == EXFAT_CLUSTER_BAD || (c) == EXFAT_CLUSTER_END)
35 #define MIN(a, b) ((a) < (b) ? (a) : (b))
36 #define DIV_ROUND_UP(x, d) (((x) + (d) - 1) / (d))
40 struct exfat_node* parent;
41 struct exfat_node* child;
42 struct exfat_node* next;
43 struct exfat_node* prev;
47 cluster_t fptr_cluster;
48 cluster_t entry_cluster;
50 cluster_t start_cluster;
54 le16_t name[EXFAT_NAME_MAX + 1];
59 struct exfat_super_block* sb;
63 struct exfat_node* root;
66 cluster_t start_cluster;
67 uint32_t size; /* in bits */
69 uint32_t chunk_size; /* in bits */
81 /* in-core nodes iterator */
84 struct exfat_node* parent;
85 struct exfat_node* current;
88 extern int exfat_errors;
90 void exfat_bug(const char* format, ...)
91 __attribute__((format(printf, 1, 2), noreturn));
92 void exfat_error(const char* format, ...)
93 __attribute__((format(printf, 1, 2)));
94 void exfat_warn(const char* format, ...)
95 __attribute__((format(printf, 1, 2)));
96 void exfat_debug(const char* format, ...)
97 __attribute__((format(printf, 1, 2)));
99 void exfat_read_raw(void* buffer, size_t size, off_t offset, int fd);
100 void exfat_write_raw(const void* buffer, size_t size, off_t offset, int fd);
101 ssize_t exfat_read(const struct exfat* ef, struct exfat_node* node,
102 void* buffer, size_t size, off_t offset);
103 ssize_t exfat_write(struct exfat* ef, struct exfat_node* node,
104 const void* buffer, size_t size, off_t offset);
106 int exfat_opendir(struct exfat* ef, struct exfat_node* dir,
107 struct exfat_iterator* it);
108 void exfat_closedir(struct exfat* ef, struct exfat_iterator* it);
109 struct exfat_node* exfat_readdir(struct exfat* ef, struct exfat_iterator* it);
110 int exfat_lookup(struct exfat* ef, struct exfat_node** node,
112 int exfat_split(struct exfat* ef, struct exfat_node** node, le16_t* name,
115 off_t exfat_c2o(const struct exfat* ef, cluster_t cluster);
116 cluster_t exfat_next_cluster(const struct exfat* ef,
117 const struct exfat_node* node, cluster_t cluster);
118 cluster_t exfat_advance_cluster(const struct exfat* ef,
119 struct exfat_node* node, uint32_t count);
120 void exfat_flush_cmap(struct exfat* ef);
121 int exfat_truncate(struct exfat* ef, struct exfat_node* node, uint64_t size);
123 void exfat_stat(const struct exfat* ef, const struct exfat_node* node,
125 time_t exfat_exfat2unix(le16_t date, le16_t time);
126 void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time);
127 void exfat_get_name(const struct exfat_node* node, char* buffer, size_t n);
128 uint16_t exfat_start_checksum(const struct exfat_file* entry);
129 uint16_t exfat_add_checksum(const void* entry, uint16_t sum);
130 le16_t exfat_calc_checksum(const struct exfat_file* meta1,
131 const struct exfat_file_info* meta2, const le16_t* name);
132 le16_t exfat_calc_name_hash(const struct exfat* ef, const le16_t* name);
134 int utf16_to_utf8(char* output, const le16_t* input, size_t outsize,
136 int utf8_to_utf16(le16_t* output, const char* input, size_t outsize,
138 size_t utf16_length(const le16_t* str);
140 struct exfat_node* exfat_get_node(struct exfat_node* node);
141 void exfat_put_node(struct exfat* ef, struct exfat_node* node);
142 int exfat_cache_directory(struct exfat* ef, struct exfat_node* dir);
143 void exfat_reset_cache(struct exfat* ef);
144 void exfat_flush_node(struct exfat* ef, struct exfat_node* node);
145 int exfat_unlink(struct exfat* ef, struct exfat_node* node);
146 int exfat_rmdir(struct exfat* ef, struct exfat_node* node);
147 int exfat_mknod(struct exfat* ef, const char* path);
148 int exfat_mkdir(struct exfat* ef, const char* path);
149 int exfat_rename(struct exfat* ef, const char* old_path, const char* new_path);
150 void exfat_utimes(struct exfat_node* node, const struct timespec tv[2]);
151 void exfat_update_atime(struct exfat_node* node);
152 void exfat_update_mtime(struct exfat_node* node);
154 int exfat_mount(struct exfat* ef, const char* spec, const char* options);
155 void exfat_unmount(struct exfat* ef);
157 #endif /* ifndef EXFAT_H_INCLUDED */