OSDN Git Service

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