OSDN Git Service

Pass pointer to a node to exfat_next_cluster() and exfat_advance_cluster() for simpli...
[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 IS_CONTIGUOUS(node) (((node).flags & EXFAT_ATTRIB_CONTIGUOUS) != 0)
28 #define BLOCK_SIZE(sb) (1 << (sb).block_bits)
29 #define CLUSTER_SIZE(sb) (BLOCK_SIZE(sb) << (sb).bpc_bits)
30 #define CLUSTER_INVALID(c) ((c) == EXFAT_CLUSTER_BAD || (c) == EXFAT_CLUSTER_END)
31
32 struct exfat_node
33 {
34         struct exfat_node* child;
35         struct exfat_node* next;
36         struct exfat_node* prev;
37
38         int references;
39         cluster_t start_cluster;
40         int flags;
41         uint64_t size;
42         time_t mtime, atime;
43         le16_t name[EXFAT_NAME_MAX + 1];
44 };
45
46 struct exfat
47 {
48         struct exfat_super_block* sb;
49         int fd;
50         le16_t* upcase;
51         size_t upcase_chars;
52         struct exfat_node* root;
53 };
54
55 /* in-core nodes iterator */
56 struct exfat_iterator
57 {
58         struct exfat_node* parent;
59         struct exfat_node* current;
60 };
61
62 extern int exfat_errors;
63
64 void exfat_bug(const char* format, ...);
65 void exfat_error(const char* format, ...);
66 void exfat_warn(const char* format, ...);
67 void exfat_debug(const char* format, ...);
68
69 void exfat_read_raw(void* buffer, size_t size, off_t offset, int fd);
70 ssize_t exfat_read(const struct exfat* ef, const struct exfat_node* node,
71                 void* buffer, size_t size, off_t offset);
72
73 int exfat_opendir(struct exfat* ef, struct exfat_node* dir,
74                 struct exfat_iterator* it);
75 void exfat_closedir(struct exfat_iterator* it);
76 struct exfat_node* exfat_readdir(struct exfat* ef, struct exfat_iterator* it);
77 int exfat_lookup(struct exfat* ef, struct exfat_node** node,
78                 const char* path);
79
80 off_t exfat_c2o(const struct exfat* ef, cluster_t cluster);
81 cluster_t exfat_next_cluster(const struct exfat* ef,
82                 const struct exfat_node* node, cluster_t cluster);
83 cluster_t exfat_advance_cluster(const struct exfat* ef,
84                 const struct exfat_node* node, cluster_t cluster, uint32_t count);
85
86 void exfat_stat(const struct exfat_node* node, struct stat *stbuf);
87 time_t exfat_exfat2unix(le16_t date, le16_t time);
88 void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time);
89 void exfat_get_name(const struct exfat_node* node, char* buffer, size_t n);
90
91 int utf16_to_utf8(char* output, const le16_t* input, size_t outsize,
92                 size_t insize);
93 int utf8_to_utf16(le16_t* output, const char* input, size_t outsize,
94                 size_t insize);
95
96 struct exfat_node* exfat_get_node(struct exfat_node* node);
97 void exfat_put_node(struct exfat_node* node);
98 int exfat_cache_directory(struct exfat* ef, struct exfat_node* dir);
99 void exfat_reset_cache(struct exfat* ef);
100
101 int exfat_mount(struct exfat* ef, const char* spec);
102 void exfat_unmount(struct exfat* ef);
103
104 #endif /* ifndef EXFAT_H_INCLUDED */