2 * Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
\r
3 * All rights reserved.
\r
5 * Redistribution and use in source and binary forms, with or without
\r
6 * modification, are permitted provided that the following conditions
\r
9 * - Redistributions of source code must retain the above copyright
\r
10 * notice, this list of conditions and the following disclaimer.
\r
11 * - Redistributions in binary form must reproduce the above copyright
\r
12 * notice, this list of conditions and the following disclaimer in the
\r
13 * documentation and/or other materials provided with the distribution.
\r
14 * - The name of the author may not be used to endorse or promote products
\r
15 * derived from this software without specific prior written permission.
\r
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
\r
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
\r
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
\r
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
\r
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
\r
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
\r
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
\r
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
29 /** @addtogroup lwext4
\r
34 * @brief Ext4 high level operations (files, directories, mountpoints...).
\r
35 * Client has to include only this file.
\r
41 #include <ext4_config.h>
\r
42 #include <ext4_blockdev.h>
\r
45 /********************************FILE OPEN FLAGS*****************************/
\r
60 #define O_CREAT 0100
\r
68 #define O_TRUNC 01000
\r
72 #define O_APPEND 02000
\r
75 /********************************FILE SEEK FLAGS*****************************/
\r
89 /********************************OS LOCK INFERFACE***************************/
\r
91 /**@brief OS dependent lock interface.*/
\r
94 /**@brief Lock access to mountpoint*/
\r
97 /**@brief Unlock access to mountpoint*/
\r
98 void (*unlock)(void);
\r
102 /********************************FILE DESCRIPTOR*****************************/
\r
104 /**@brief File descriptor*/
\r
105 typedef struct ext4_file {
\r
107 /**@brief Pountpoint handle.*/
\r
108 struct ext4_mountpoint *mp;
\r
110 /**@brief File inode id*/
\r
113 /**@brief Open flags.*/
\r
116 /**@brief File size.*/
\r
119 /**@brief File position*/
\r
123 /*****************************DIRECTORY DESCRIPTOR***************************/
\r
124 /**@brief Directory entry types. Copy from ext4_types.h*/
\r
126 EXT4_DIRENTRY_UNKNOWN = 0,
\r
127 EXT4_DIRENTRY_REG_FILE,
\r
129 EXT4_DIRENTRY_CHRDEV,
\r
130 EXT4_DIRENTRY_BLKDEV,
\r
131 EXT4_DIRENTRY_FIFO,
\r
132 EXT4_DIRENTRY_SOCK,
\r
133 EXT4_DIRENTRY_SYMLINK
\r
136 /**@brief Directory entry descriptor. Copy from ext4_types.h*/
\r
139 uint16_t entry_length;
\r
140 uint8_t name_length;
\r
142 uint8_t name_length_high;
\r
143 uint8_t inode_type;
\r
149 /**@brief File descriptor*/
\r
151 /**@brief Current direntry.*/
\r
155 /********************************MOUNT OPERATIONS****************************/
\r
157 /**@brief Register a block device to a name.
\r
158 * @warning Block device has to be filled by
\r
159 * @ref EXT4_BLOCKDEV_STATIC_INSTANCE. Block cache may be created
\r
160 * @ref EXT4_BCACHE_STATIC_INSTANCE.
\r
161 * Block cache may by created automaticly when bc parameter is 0.
\r
162 * @param bd block device
\r
163 * @param bd block device cache (0 = automatic cache mode)
\r
164 * @param dev_name register name
\r
165 * @param standard error code*/
\r
166 int ext4_device_register(struct ext4_blockdev *bd, struct ext4_bcache *bc,
\r
167 const char *dev_name);
\r
169 /**@brief Mount a block device with EXT4 partition to the mountpoint.
\r
170 * @param dev_name block device name (@ref ext4_device_register)
\r
171 * @param mount_point pount point, for example
\r
174 * - /my_second_partition/
\r
176 * @return standard error code */
\r
177 int ext4_mount(const char * dev_name, char *mount_point);
\r
179 /**@brief Umount operation.
\r
180 * @param mount_point mount name
\r
181 * @return standard error code */
\r
182 int ext4_umount(char *mount_point);
\r
185 /**@brief Some of the filesystem stats.*/
\r
186 struct ext4_mount_stats {
\r
187 uint32_t inodes_count;
\r
188 uint32_t free_inodes_count;
\r
189 uint64_t blocks_count;
\r
190 uint64_t free_blocks_count;
\r
192 uint32_t block_size;
\r
193 uint32_t block_group_count;
\r
194 uint32_t blocks_per_group;
\r
195 uint32_t inodes_per_group;
\r
197 char volume_name[16];
\r
200 /**@brief Get file system params.
\r
201 * @param mount_point mount path
\r
202 * @param stats ext fs stats
\r
203 * @return standard error code */
\r
204 int ext4_mount_point_stats(const char *mount_point,
\r
205 struct ext4_mount_stats *stats);
\r
207 /********************************FILE OPERATIONS*****************************/
\r
209 /**@brief Remove file by path.
\r
210 * @param path path to file
\r
211 * @return standard error code */
\r
212 int ext4_fremove(const char *path);
\r
214 /**@brief File open function.
\r
215 * @param filename, (has to start from mountpoint)
\r
216 * /my_partition/my_file
\r
217 * @param flags open file flags
\r
218 * |---------------------------------------------------------------|
\r
219 * | r or rb O_RDONLY |
\r
220 * |---------------------------------------------------------------|
\r
221 * | w or wb O_WRONLY|O_CREAT|O_TRUNC |
\r
222 * |---------------------------------------------------------------|
\r
223 * | a or ab O_WRONLY|O_CREAT|O_APPEND |
\r
224 * |---------------------------------------------------------------|
\r
225 * | r+ or rb+ or r+b O_RDWR |
\r
226 * |---------------------------------------------------------------|
\r
227 * | w+ or wb+ or w+b O_RDWR|O_CREAT|O_TRUNC |
\r
228 * |---------------------------------------------------------------|
\r
229 * | a+ or ab+ or a+b O_RDWR|O_CREAT|O_APPEND |
\r
230 * |---------------------------------------------------------------|
\r
232 * @return standard error code*/
\r
233 int ext4_fopen (ext4_file *f, const char *path, const char *flags);
\r
235 /**@brief File close function.
\r
236 * @param f file handle
\r
237 * @return standard error code*/
\r
238 int ext4_fclose(ext4_file *f);
\r
240 /**@brief Read data from file.
\r
241 * @param f file handle
\r
242 * @param buf output buffer
\r
243 * @param size bytes to read
\r
244 * @param rcnt readed bytes (may be NULL)
\r
245 * @return standard error code*/
\r
246 int ext4_fread (ext4_file *f, void *buf, uint32_t size, uint32_t *rcnt);
\r
248 /**@brief Write data to file.
\r
249 * @param f file handle
\r
250 * @param buf data to write
\r
251 * @param size write length
\r
252 * @param wcnt bytes written (may be NULL)
\r
253 * @return standard error code*/
\r
254 int ext4_fwrite(ext4_file *f, void *buf, uint32_t size, uint32_t *wcnt);
\r
256 /**@brief File seek operation.
\r
257 * @param f file handle
\r
258 * @param offset offset to seek
\r
259 * @param origin seek type:
\r
263 * @return standard error code*/
\r
264 int ext4_fseek (ext4_file *f, uint64_t offset, uint32_t origin);
\r
266 /**@brief Get file position.
\r
267 * @param f file handle
\r
268 * @return actual file position */
\r
269 uint64_t ext4_ftell (ext4_file *f);
\r
271 /**@brief Get file size.
\r
272 * @param f file handle
\r
273 * @return file size */
\r
274 uint64_t ext4_fsize (ext4_file *f);
\r
276 /*********************************DIRECTORY OPERATION***********************/
\r
278 /**@brief Recursive directory remove.
\r
279 * @param path directory path to remove
\r
280 * @return standard error code*/
\r
281 int ext4_dir_rm(const char *path);
\r
283 /**@brief Create new directory.
\r
284 * @param name new directory name
\r
285 * @return standard error code*/
\r
286 int ext4_dir_mk(const char *path);
\r
288 /**@brief Directory open.
\r
289 * @param d directory handle
\r
290 * @param path directory path
\r
291 * @return standard error code*/
\r
292 int ext4_dir_open (ext4_dir *d, const char *path);
\r
294 /**@brief Directory close.
\r
295 * @param d directory handle
\r
296 * @return standard error code*/
\r
297 int ext4_dir_close(ext4_dir *d);
\r
300 /**@brief Return directory entry by id.
\r
301 * @param d directory handle
\r
302 * @param id entry id
\r
303 * @return directory entry id (NULL id no entry)*/
\r
304 ext4_direntry* ext4_dir_entry_get(ext4_dir *d, uint32_t id);
\r
306 #endif /* EXT4_H_ */
\r