Refactor the workflow of ext4_link to prepare for METADATA_CSUM.
[lwext4.git] / lwext4 / ext4.h
index 6b76d053b692f153ffee664a39a2c06c58207248..abf6a3583f7003cdb2e9702d108df4a6f8f4c74f 100644 (file)
 
 /********************************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 <unistd.h>
+ #include <fcntl.h>
 #endif
 
 /********************************OS LOCK INFERFACE***************************/
@@ -123,15 +130,6 @@ 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 {
@@ -297,7 +295,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
@@ -305,11 +303,12 @@ 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.
@@ -354,14 +353,24 @@ 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);
+int ext4_chmod(const char *path, uint32_t mode);
+int ext4_chown(const char *path, uint32_t uid, uint32_t gid);
+int ext4_file_set_atime(const char *path, uint32_t atime);
+int ext4_file_set_mtime(const char *path, uint32_t mtime);
+int ext4_file_set_ctime(const char *path, uint32_t ctime);
 
 int ext4_fsymlink(const char *target, const char *path);
 
+int ext4_readlink(const char *path, char *buf, size_t bufsize, size_t *rcnt);
+
+int ext4_setxattr(const char *path, const char *name, size_t name_len,
+                 const void *data, size_t data_size, bool replace);
+int ext4_getxattr(const char *path, const char *name, size_t name_len,
+                 void *buf, size_t buf_size, size_t *data_size);
+int ext4_listxattr(const char *path, char *list, size_t size, size_t *ret_size);
+int ext4_removexattr(const char *path, const char *name, size_t name_len);
+
+
 /*********************************DIRECTORY OPERATION***********************/
 
 /**@brief   Recursive directory remove.
@@ -391,6 +400,10 @@ 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);
+
 #endif /* EXT4_H_ */
 
 /**