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 IS_CONTIGUOUS(node) (((node).flags & EXFAT_ATTRIB_CONTIGUOUS) != 0)
29 #define BLOCK_SIZE(sb) (1 << (sb).block_bits)
30 #define CLUSTER_SIZE(sb) (BLOCK_SIZE(sb) << (sb).bpc_bits)
31 #define CLUSTER_INVALID(c) ((c) == EXFAT_CLUSTER_BAD || (c) == EXFAT_CLUSTER_END)
33 #define MIN(a, b) ((a) < (b) ? (a) : (b))
37 struct exfat_node* child;
38 struct exfat_node* next;
39 struct exfat_node* prev;
43 cluster_t fptr_cluster;
44 off_t meta1_offset, meta2_offset;
45 cluster_t start_cluster;
49 le16_t name[EXFAT_NAME_MAX + 1];
54 struct exfat_super_block* sb;
58 struct exfat_node* root;
61 cluster_t start_cluster;
62 uint32_t size; /* in bits */
64 uint32_t chunk_size; /* in bits */
70 /* in-core nodes iterator */
73 struct exfat_node* parent;
74 struct exfat_node* current;
77 extern int exfat_errors;
79 void exfat_bug(const char* format, ...);
80 void exfat_error(const char* format, ...);
81 void exfat_warn(const char* format, ...);
82 void exfat_debug(const char* format, ...);
84 void exfat_read_raw(void* buffer, size_t size, off_t offset, int fd);
85 void exfat_write_raw(const void* buffer, size_t size, off_t offset, int fd);
86 ssize_t exfat_read(const struct exfat* ef, struct exfat_node* node,
87 void* buffer, size_t size, off_t offset);
88 ssize_t exfat_write(struct exfat* ef, struct exfat_node* node,
89 const void* buffer, size_t size, off_t offset);
91 int exfat_opendir(struct exfat* ef, struct exfat_node* dir,
92 struct exfat_iterator* it);
93 void exfat_closedir(struct exfat* ef, struct exfat_iterator* it);
94 struct exfat_node* exfat_readdir(struct exfat* ef, struct exfat_iterator* it);
95 int exfat_lookup(struct exfat* ef, struct exfat_node** node,
98 off_t exfat_c2o(const struct exfat* ef, cluster_t cluster);
99 cluster_t exfat_next_cluster(const struct exfat* ef,
100 const struct exfat_node* node, cluster_t cluster);
101 cluster_t exfat_advance_cluster(const struct exfat* ef,
102 struct exfat_node* node, uint32_t count);
103 cluster_t exfat_allocate_cluster(struct exfat* ef, cluster_t previous);
104 void exfat_free_cluster(struct exfat* ef, cluster_t cluster,
106 int exfat_truncate(struct exfat* ef, struct exfat_node* node, uint64_t size);
108 void exfat_stat(const struct exfat_node* node, struct stat *stbuf);
109 time_t exfat_exfat2unix(le16_t date, le16_t time);
110 void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time);
111 void exfat_get_name(const struct exfat_node* node, char* buffer, size_t n);
112 uint16_t exfat_start_checksum(const struct exfat_file* entry);
113 uint16_t exfat_add_checksum(const void* entry, uint16_t sum);
115 int utf16_to_utf8(char* output, const le16_t* input, size_t outsize,
117 int utf8_to_utf16(le16_t* output, const char* input, size_t outsize,
120 struct exfat_node* exfat_get_node(struct exfat_node* node);
121 void exfat_put_node(struct exfat* ef, struct exfat_node* node);
122 int exfat_cache_directory(struct exfat* ef, struct exfat_node* dir);
123 void exfat_reset_cache(struct exfat* ef);
124 void exfat_flush_node(struct exfat* ef, struct exfat_node* node);
126 int exfat_mount(struct exfat* ef, const char* spec);
127 void exfat_unmount(struct exfat* ef);
129 #endif /* ifndef EXFAT_H_INCLUDED */