OSDN Git Service

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