X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=lwext4%2Fext4.h;h=9679eb89cfb2ccb30d14399ae45250aa09ef7082;hb=519e5676f7a8e2ec620731adb099a66072d4f1a1;hp=59b0501f714a42b34e04bbccec1688c52cc54670;hpb=ab3010aeb7aff7581d67866819a1ec74ce36916a;p=lwext4.git diff --git a/lwext4/ext4.h b/lwext4/ext4.h index 59b0501..9679eb8 100644 --- a/lwext4/ext4.h +++ b/lwext4/ext4.h @@ -38,56 +38,68 @@ #ifndef EXT4_H_ #define EXT4_H_ -#include "ext4_config.h" -#include "ext4_types.h" -#include "ext4_blockdev.h" +#ifdef __cplusplus +extern "C" { +#endif #include +#include /********************************FILE OPEN FLAGS*****************************/ -#ifndef O_RDONLY -#define O_RDONLY 00 -#endif +#if CONFIG_HAVE_OWN_OFLAGS -#ifndef O_WRONLY -#define O_WRONLY 01 -#endif + #ifndef O_RDONLY + #define O_RDONLY 00 + #endif -#ifndef O_RDWR -#define O_RDWR 02 -#endif + #ifndef O_WRONLY + #define O_WRONLY 01 + #endif -#ifndef O_CREAT -#define O_CREAT 0100 -#endif + #ifndef O_RDWR + #define O_RDWR 02 + #endif -#ifndef O_EXCL -#define O_EXCL 0200 -#endif + #ifndef O_CREAT + #define O_CREAT 0100 + #endif -#ifndef O_TRUNC -#define O_TRUNC 01000 -#endif + #ifndef O_EXCL + #define O_EXCL 0200 + #endif -#ifndef O_APPEND -#define O_APPEND 02000 -#endif + #ifndef O_TRUNC + #define O_TRUNC 01000 + #endif + + #ifndef O_APPEND + #define O_APPEND 02000 + #endif /********************************FILE SEEK FLAGS*****************************/ -#ifndef SEEK_SET -#define SEEK_SET 0 -#endif + #ifndef SEEK_SET + #define SEEK_SET 0 + #endif -#ifndef SEEK_CUR -#define SEEK_CUR 1 -#endif + #ifndef SEEK_CUR + #define SEEK_CUR 1 + #endif -#ifndef SEEK_END -#define SEEK_END 2 + #ifndef SEEK_END + #define SEEK_END 2 + #endif + +#else + #include + #include #endif +#include "ext4_config.h" +#include "ext4_types.h" +#include "ext4_blockdev.h" + /********************************OS LOCK INFERFACE***************************/ /**@brief OS dependent lock interface.*/ @@ -122,18 +134,9 @@ typedef struct ext4_file { } ext4_file; /*****************************DIRECTORY DESCRIPTOR***************************/ -/**@brief Directory entry types. Copy from ext4_types.h*/ -enum { EXT4_DIRENTRY_UNKNOWN = 0, - EXT4_DIRENTRY_REG_FILE, - EXT4_DIRENTRY_DIR, - EXT4_DIRENTRY_CHRDEV, - EXT4_DIRENTRY_BLKDEV, - EXT4_DIRENTRY_FIFO, - EXT4_DIRENTRY_SOCK, - EXT4_DIRENTRY_SYMLINK }; /**@brief Directory entry descriptor. Copy from ext4_types.h*/ -typedef struct { +typedef struct ext4_direntry { uint32_t inode; uint16_t entry_length; uint8_t name_length; @@ -141,7 +144,7 @@ typedef struct { uint8_t name[255]; } ext4_direntry; -typedef struct { +typedef struct ext4_dir { /**@brief File descriptor*/ ext4_file f; /**@brief Current directory entry.*/ @@ -179,6 +182,16 @@ int ext4_mount(const char *dev_name, const char *mount_point); * @return standard error code */ int ext4_umount(const char *mount_point); +int ext4_journal_start(const char *mount_point); + +int ext4_journal_stop(const char *mount_point); + +/**@brief Journal recovery. + * @param mount_point mount point + * @warning Must be called after @ref ext4_mount + * @return standard error code */ +int ext4_recover(const char *mount_point); + /**@brief Some of the filesystem stats.*/ struct ext4_mount_stats { uint32_t inodes_count; @@ -258,12 +271,6 @@ int ext4_cache_write_back(const char *path, bool on); * @return standard error code */ int ext4_fremove(const char *path); -/**@brief Create symlink against target - * @param path path to file - * @param target path to target - * @return standard error code */ -int ext4_fsymlink(const char *path, const char *target); - /**@brief create a hardlink for a file. * @param path path to file * @param hardlink_path path of hardlink @@ -277,7 +284,7 @@ int ext4_flink(const char *path, const char *hardlink_path); int ext4_frename(const char *path, const char *new_path); /**@brief File open function. - * @param filename, (has to start from mount point) + * @param path filename (has to start from mount point) * /my_partition/my_file * @param flags open file flags * |---------------------------------------------------------------| @@ -302,7 +309,7 @@ int ext4_fopen(ext4_file *f, const char *path, const char *flags); * /my_partition/my_file * @param flags open file flags * @return standard error code*/ -int ext4_fopen2(ext4_file *f, const char *path, int flags, bool file_expect); +int ext4_fopen2(ext4_file *f, const char *path, int flags); /**@brief File close function. * @param f file handle @@ -310,11 +317,11 @@ int ext4_fopen2(ext4_file *f, const char *path, int flags, bool file_expect); int ext4_fclose(ext4_file *f); /**@brief Fill in the ext4_inode buffer. - * @param mount_point - * @param inode no. + * @param path fetch inode data of the path + * @param ret_ino the inode id of the path * @param ext4_inode buffer * @return standard error code*/ -int ext4_fill_raw_inode(const char *mount_point, uint32_t ino, +int ext4_fill_raw_inode(const char *path, uint32_t *ret_ino, struct ext4_inode *inode); /**@brief File truncate function. @@ -329,7 +336,7 @@ int ext4_ftruncate(ext4_file *f, uint64_t size); * @param size bytes to read * @param rcnt bytes read (may be NULL) * @return standard error code*/ -int ext4_fread(ext4_file *f, void *buf, uint32_t size, uint32_t *rcnt); +int ext4_fread(ext4_file *f, void *buf, size_t size, size_t *rcnt); /**@brief Write data to file. * @param f file handle @@ -337,7 +344,7 @@ int ext4_fread(ext4_file *f, void *buf, uint32_t size, uint32_t *rcnt); * @param size write length * @param wcnt bytes written (may be NULL) * @return standard error code*/ -int ext4_fwrite(ext4_file *f, const void *buf, uint32_t size, uint32_t *wcnt); +int ext4_fwrite(ext4_file *f, const void *buf, size_t size, size_t *wcnt); /**@brief File seek operation. * @param f file handle @@ -359,11 +366,82 @@ uint64_t ext4_ftell(ext4_file *f); * @return file size */ uint64_t ext4_fsize(ext4_file *f); -int ext4_fchmod(ext4_file *f, uint32_t mode); -int ext4_fchown(ext4_file *f, uint32_t uid, uint32_t gid); -int ext4_file_set_atime(ext4_file *f, uint32_t atime); -int ext4_file_set_mtime(ext4_file *f, uint32_t mtime); -int ext4_file_set_ctime(ext4_file *f, uint32_t ctime); +/**@brief Change file/directory/link mode bits + * @param path to file/dir/link + * @param mode new mode bits (for example 0777) + * @return standard error code*/ +int ext4_chmod(const char *path, uint32_t mode); + +/**@brief Change file owner and group + * @param path to file/dir/link + * @param uid user id + * @param gid group id + * @return standard error code*/ +int ext4_chown(const char *path, uint32_t uid, uint32_t gid); + +/**@brief Set file access time + * @param path to file/dir/link + * @param atime access timestamp + * @return standard error code*/ +int ext4_file_set_atime(const char *path, uint32_t atime); + +/**@brief Set file modify time + * @param path to file/dir/link + * @param mtime modify timestamp + * @return standard error code*/ +int ext4_file_set_mtime(const char *path, uint32_t mtime); + +/**@brief Set file change time + * @param path to file/dir/link + * @param ctime change timestamp + * @return standard error code*/ +int ext4_file_set_ctime(const char *path, uint32_t ctime); + +/**@brief Create symbolic link + * @param target destination path + * @param path source entry + * @return standard error code*/ +int ext4_fsymlink(const char *target, const char *path); + + +/**@brief Read symbolic link payload + * @param path to symlink + * @param buf output buffer + * @param bufsize output buffer max size + * @param rcnt bytes read + * @return standard error code*/ +int ext4_readlink(const char *path, char *buf, size_t bufsize, size_t *rcnt); + +/**@brief Set extended attribute + * @param path to entry + * + * TODO: write detailed description + */ +int ext4_setxattr(const char *path, const char *name, size_t name_len, + const void *data, size_t data_size, bool replace); + +/**@brief Get extended attribute + * @param path to entry + * + * TODO: write detailed description + */ +int ext4_getxattr(const char *path, const char *name, size_t name_len, + void *buf, size_t buf_size, size_t *data_size); + +/**@brief List extended attributes + * @param path to entry + * + * TODO: write detailed description + */ +int ext4_listxattr(const char *path, char *list, size_t size, size_t *ret_size); + +/**@brief Remove extended attribute + * @param path to entry + * + * TODO: write detailed description + */ +int ext4_removexattr(const char *path, const char *name, size_t name_len); + /*********************************DIRECTORY OPERATION***********************/ @@ -394,6 +472,23 @@ int ext4_dir_close(ext4_dir *d); * @return directory entry id (NULL if no entry)*/ const ext4_direntry *ext4_dir_entry_next(ext4_dir *d); +/**@brief Rewine directory entry offset. + * @param d directory handle*/ +void ext4_dir_entry_rewind(ext4_dir *d); + +/**@brief Test journal functionality + * @param mount_point mount point, for example + * - / + * - /my_partition/ + * - /my_second_partition/ + * + * @return standard error code */ +int ext4_test_journal(const char *mount_point); + +#ifdef __cplusplus +} +#endif + #endif /* EXT4_H_ */ /**