-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibfatx.h
156 lines (137 loc) · 3.75 KB
/
libfatx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/**
* \file libfatx.h
* \author Tim Wu
*/
#include <sys/stat.h>
#include <sys/types.h>
#include <stdint.h>
#ifndef FATX_LIBFATX_H
#define FATX_LIBFATX_H
/**
* A fatx opaque object.
*/
typedef struct fatx_handle * fatx_t;
/**
* Directory entry returned when iterating over folder.
*/
typedef struct fatx_dirent {
char * d_name; /**< direntry name */
unsigned short int d_namelen; /**< length of the name */
} fatx_dirent_t;
/** Structure to store mount options */
typedef struct fatx_options {
/** User to own the files */
uid_t user;
/** Group of the files */
gid_t group;
/** File permissions */
uint32_t filePerm;
/** Mount mode */
uint32_t mode;
} fatx_options_t;
/**
* Initializes a fatx opaque object with the path to
* the device to use.
*
* \param path Path to the image or device.
* \param options options to set.
* \return The initilized fatx object; NULL on error.
*/
fatx_t fatx_init(const char* path, fatx_options_t * options);
/**
* Frees a fatx object.
*
* \param fatx The fatx object to be freed.
*/
void fatx_free(fatx_t fatx);
/**
* Print stats about a fatx_t object.
*
* \param fatx The fatx object to print info from.
*/
void fatx_printInfo(fatx_t fatx);
/**
* Read bytes from a file.
*
* \param fatx The fatx object
* \param path Path to the file to be read.
* \param buf Buffer to write read file data into.
* \param offset Offset from the beginning of the file to start reading
* \param size Number of bytes to read
* \return The number of bytes written or an error.
*/
int fatx_read(fatx_t fatx, const char* path, char* buf, off_t offset, size_t size);
/**
* Write bytes into a file
*
* \param fatx The fatx object
* \param path The path to the file to be written to.
* \param buf Buffer to read data from.
* \param offset Offset in the file to write to.
* \param size Number of bytes to write into the file.
* \return The number of bytes written or an error
*/
int fatx_write(fatx_t fatx, const char* path, const char* buf, off_t offset, size_t size);
/**
* Stat a file.
*
* \param fatx The fatx object.
* \param path The path to the file to stat.
* \param st_buf Pointer to the stat struct to populate.
* \return Error code
*/
int fatx_stat(fatx_t fatx, const char* path, struct stat *st_buf);
/**
* Remove a file
*
* \param fatx The fatx object.
* \param path The path to the file to remove.
* \return Error code
*/
int fatx_remove(fatx_t fatx, const char* path);
/**
* Create a file
*
* \param fatx The fatx objects.
* \param path Path to the file to create.
* \return Error code
*/
int fatx_mkfile(fatx_t fatx, const char* path);
/**
* Create a directory
*
* \param fatx The fatx object.
* \param path Path to the directory to create.
* \return Error code
*/
int fatx_mkdir(fatx_t fatx, const char* path);
/**
* Fatx dir opaque object used to iterate over
* the contents of a directory.
*/
typedef struct fatx_dir_iter * fatx_dir_iter_t;
/**
* Opens a directory for reading. The resultant
* iterator will be used to read directory entries
* with the fatx_readdir() method. The iterator should
* be freed with fatx_closedir() when no longer needed.
*
* \param fatx The fatx object
* \param path Path of the directory to be opened.
* \return Iterator to iterate over the directory entries; NULL on error.
*/
fatx_dir_iter_t fatx_opendir(fatx_t fatx, const char* path);
/**
* Reads a directory entry from the given directory iterator.
*
* \param iter The iterator to get the directory entries from.
* \return A directory entry; NULL if none left.
*/
fatx_dirent_t * fatx_readdir(fatx_dir_iter_t iter);
/**
* Closes the iterator and frees up any associated structures.
*
* \param iter Iterator to free.
*/
void fatx_closedir(fatx_dir_iter_t iter);
#endif //FATX_LIBFATX_H