OSDN Git Service

Remember recently used cluster of each node.
[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 #define MIN(a, b) ((a) < (b) ? (a) : (b))
33
34 struct exfat_node
35 {
36         struct exfat_node* child;
37         struct exfat_node* next;
38         struct exfat_node* prev;
39
40         int references;
41         uint32_t fptr_index;
42         cluster_t fptr_cluster;
43         off_t meta1_offset, meta2_offset;
44         cluster_t start_cluster;
45         int flags;
46         uint64_t size;
47         time_t mtime, atime;
48         le16_t name[EXFAT_NAME_MAX + 1];
49 };
50
51 struct exfat
52 {
53         struct exfat_super_block* sb;
54         int fd;
55         le16_t* upcase;
56         size_t upcase_chars;
57         struct exfat_node* root;
58         struct
59         {
60                 cluster_t start_cluster;
61                 uint32_t size;                          /* in bits */
62                 uint8_t* chunk;
63                 uint32_t chunk_size;            /* in bits */
64         }
65         cmap;
66         void* zero_block;
67 };
68
69 /* in-core nodes iterator */
70 struct exfat_iterator
71 {
72         struct exfat_node* parent;
73         struct exfat_node* current;
74 };
75
76 extern int exfat_errors;
77
78 void exfat_bug(const char* format, ...);
79 void exfat_error(const char* format, ...);
80 void exfat_warn(const char* format, ...);
81 void exfat_debug(const char* format, ...);
82
83 void exfat_read_raw(void* buffer, size_t size, off_t offset, int fd);
84 void exfat_write_raw(const void* buffer, size_t size, off_t offset, int fd);
85 ssize_t exfat_read(const struct exfat* ef, struct exfat_node* node,
86                 void* buffer, size_t size, off_t offset);
87 ssize_t exfat_write(struct exfat* ef, struct exfat_node* node,
88                 const void* buffer, size_t size, off_t offset);
89
90 int exfat_opendir(struct exfat* ef, struct exfat_node* dir,
91                 struct exfat_iterator* it);
92 void exfat_closedir(struct exfat_iterator* it);
93 struct exfat_node* exfat_readdir(struct exfat* ef, struct exfat_iterator* it);
94 int exfat_lookup(struct exfat* ef, struct exfat_node** node,
95                 const char* path);
96
97 off_t exfat_c2o(const struct exfat* ef, cluster_t cluster);
98 cluster_t exfat_next_cluster(const struct exfat* ef,
99                 const struct exfat_node* node, cluster_t cluster);
100 cluster_t exfat_advance_cluster(const struct exfat* ef,
101                 struct exfat_node* node, uint32_t count);
102 cluster_t exfat_allocate_cluster(struct exfat* ef, cluster_t previous);
103 void exfat_free_cluster(struct exfat* ef, cluster_t cluster,
104                 cluster_t previous);
105 int exfat_truncate(struct exfat* ef, struct exfat_node* node, uint64_t size);
106
107 void exfat_stat(const struct exfat_node* node, struct stat *stbuf);
108 time_t exfat_exfat2unix(le16_t date, le16_t time);
109 void exfat_unix2exfat(time_t unix_time, le16_t* date, le16_t* time);
110 void exfat_get_name(const struct exfat_node* node, char* buffer, size_t n);
111 uint16_t exfat_start_checksum(const struct exfat_file* entry);
112 uint16_t exfat_add_checksum(const void* entry, uint16_t sum);
113
114 int utf16_to_utf8(char* output, const le16_t* input, size_t outsize,
115                 size_t insize);
116 int utf8_to_utf16(le16_t* output, const char* input, size_t outsize,
117                 size_t insize);
118
119 struct exfat_node* exfat_get_node(struct exfat_node* node);
120 void exfat_put_node(struct exfat_node* node);
121 int exfat_cache_directory(struct exfat* ef, struct exfat_node* dir);
122 void exfat_reset_cache(struct exfat* ef);
123 void exfat_flush_node(struct exfat* ef, const struct exfat_node* node);
124
125 int exfat_mount(struct exfat* ef, const char* spec);
126 void exfat_unmount(struct exfat* ef);
127
128 #endif /* ifndef EXFAT_H_INCLUDED */