Linux codestyle format (tabs indenation)
[lwext4.git] / lwext4 / ext4.h
index 9b2810b5d539eceeb066cfdb206cbb7e13ae4bf9..a0fae642bb5f5ceceb90be4100f125f7066d623a 100644 (file)
 #ifndef EXT4_H_\r
 #define EXT4_H_\r
 \r
-#include <ext4_config.h>\r
-#include <ext4_blockdev.h>\r
+#include "ext4_config.h"\r
+#include "ext4_types.h"\r
+#include "ext4_blockdev.h"\r
+\r
 #include <stdint.h>\r
 \r
 /********************************FILE OPEN FLAGS*****************************/\r
 \r
 #ifndef O_RDONLY\r
-#define O_RDONLY    00\r
+#define O_RDONLY 00\r
 #endif\r
 \r
 #ifndef O_WRONLY\r
-#define O_WRONLY    01\r
+#define O_WRONLY 01\r
 #endif\r
 \r
 #ifndef O_RDWR\r
-#define O_RDWR      02\r
+#define O_RDWR 02\r
 #endif\r
 \r
 #ifndef O_CREAT\r
-#define O_CREAT     0100\r
+#define O_CREAT 0100\r
 #endif\r
 \r
 #ifndef O_EXCL\r
-#define O_EXCL      0200\r
+#define O_EXCL 0200\r
 #endif\r
 \r
 #ifndef O_TRUNC\r
-#define O_TRUNC     01000\r
+#define O_TRUNC 01000\r
 #endif\r
 \r
 #ifndef O_APPEND\r
-#define O_APPEND    02000\r
+#define O_APPEND 02000\r
 #endif\r
 \r
 /********************************FILE SEEK FLAGS*****************************/\r
 \r
 #ifndef SEEK_SET\r
-#define SEEK_SET    0\r
+#define SEEK_SET 0\r
 #endif\r
 \r
 #ifndef SEEK_CUR\r
-#define SEEK_CUR    1\r
+#define SEEK_CUR 1\r
 #endif\r
 \r
 #ifndef SEEK_END\r
-#define SEEK_END    2\r
+#define SEEK_END 2\r
 #endif\r
 \r
 /********************************OS LOCK INFERFACE***************************/\r
 /**@brief   OS dependent lock interface.*/\r
 struct ext4_lock {\r
 \r
-    /**@brief   Lock access to mount point*/\r
-    void (*lock)(void);\r
+       /**@brief   Lock access to mount point*/\r
+       void (*lock)(void);\r
 \r
-    /**@brief   Unlock access to mount point*/\r
-    void (*unlock)(void);\r
+       /**@brief   Unlock access to mount point*/\r
+       void (*unlock)(void);\r
 };\r
 \r
-\r
 /********************************FILE DESCRIPTOR*****************************/\r
 \r
 /**@brief   File descriptor*/\r
 typedef struct ext4_file {\r
 \r
-    /**@brief   Mount point handle.*/\r
-    struct ext4_mountpoint *mp;\r
+       /**@brief   Mount point handle.*/\r
+       struct ext4_mountpoint *mp;\r
 \r
-    /**@brief   File inode id*/\r
-    uint32_t inode;\r
+       /**@brief   File inode id*/\r
+       uint32_t inode;\r
 \r
-    /**@brief   Open flags.*/\r
-    uint32_t flags;\r
+       /**@brief   Open flags.*/\r
+       uint32_t flags;\r
 \r
-    /**@brief   File size.*/\r
-    uint64_t fsize;\r
+       /**@brief   File size.*/\r
+       uint64_t fsize;\r
 \r
-    /**@brief   File position*/\r
-    uint64_t fpos;\r
-}ext4_file;\r
+       /**@brief   File position*/\r
+       uint64_t fpos;\r
+} ext4_file;\r
 \r
 /*****************************DIRECTORY DESCRIPTOR***************************/\r
 /**@brief   Directory entry types. Copy from ext4_types.h*/\r
-enum  {\r
-    EXT4_DIRENTRY_UNKNOWN = 0,\r
-    EXT4_DIRENTRY_REG_FILE,\r
-    EXT4_DIRENTRY_DIR,\r
-    EXT4_DIRENTRY_CHRDEV,\r
-    EXT4_DIRENTRY_BLKDEV,\r
-    EXT4_DIRENTRY_FIFO,\r
-    EXT4_DIRENTRY_SOCK,\r
-    EXT4_DIRENTRY_SYMLINK\r
-};\r
+enum { EXT4_DIRENTRY_UNKNOWN = 0,\r
+       EXT4_DIRENTRY_REG_FILE,\r
+       EXT4_DIRENTRY_DIR,\r
+       EXT4_DIRENTRY_CHRDEV,\r
+       EXT4_DIRENTRY_BLKDEV,\r
+       EXT4_DIRENTRY_FIFO,\r
+       EXT4_DIRENTRY_SOCK,\r
+       EXT4_DIRENTRY_SYMLINK };\r
 \r
 /**@brief   Directory entry descriptor. Copy from ext4_types.h*/\r
 typedef struct {\r
-    uint32_t inode;\r
-    uint16_t entry_length;\r
-    uint8_t name_length;\r
-    uint8_t inode_type;\r
-    uint8_t name[255];\r
-}ext4_direntry;\r
-\r
-typedef struct  {\r
-    /**@brief   File descriptor*/\r
-    ext4_file f;\r
-    /**@brief   Current directory entry.*/\r
-    ext4_direntry de;\r
-}ext4_dir;\r
+       uint32_t inode;\r
+       uint16_t entry_length;\r
+       uint8_t name_length;\r
+       uint8_t inode_type;\r
+       uint8_t name[255];\r
+} ext4_direntry;\r
+\r
+typedef struct {\r
+       /**@brief   File descriptor*/\r
+       ext4_file f;\r
+       /**@brief   Current directory entry.*/\r
+       ext4_direntry de;\r
+       /**@brief   Next entry offset*/\r
+       uint64_t next_off;\r
+} ext4_dir;\r
 \r
 /********************************MOUNT OPERATIONS****************************/\r
 \r
@@ -161,7 +162,7 @@ typedef struct  {
  * @param   dev_name register name\r
  * @param   standard error code*/\r
 int ext4_device_register(struct ext4_blockdev *bd, struct ext4_bcache *bc,\r
-        const char *dev_name);\r
+                        const char *dev_name);\r
 \r
 /**@brief   Mount a block device with EXT4 partition to the mount point.\r
  * @param   dev_name block device name (@ref ext4_device_register)\r
@@ -171,27 +172,26 @@ int ext4_device_register(struct ext4_blockdev *bd, struct ext4_bcache *bc,
  *          -   /my_second_partition/\r
  *\r
  * @return standard error code */\r
-int ext4_mount(const char * dev_name,  char *mount_point);\r
+int ext4_mount(const char *dev_name, const char *mount_point);\r
 \r
 /**@brief   Umount operation.\r
  * @param   mount_point mount name\r
  * @return  standard error code */\r
-int ext4_umount(char *mount_point);\r
-\r
+int ext4_umount(const char *mount_point);\r
 \r
 /**@brief   Some of the filesystem stats.*/\r
 struct ext4_mount_stats {\r
-    uint32_t inodes_count;\r
-    uint32_t free_inodes_count;\r
-    uint64_t blocks_count;\r
-    uint64_t free_blocks_count;\r
+       uint32_t inodes_count;\r
+       uint32_t free_inodes_count;\r
+       uint64_t blocks_count;\r
+       uint64_t free_blocks_count;\r
 \r
-    uint32_t block_size;\r
-    uint32_t block_group_count;\r
-    uint32_t blocks_per_group;\r
-    uint32_t inodes_per_group;\r
+       uint32_t block_size;\r
+       uint32_t block_group_count;\r
+       uint32_t blocks_per_group;\r
+       uint32_t inodes_per_group;\r
 \r
-    char volume_name[16];\r
+       char volume_name[16];\r
 };\r
 \r
 /**@brief   Get file system params.\r
@@ -199,14 +199,20 @@ struct ext4_mount_stats {
  * @param   stats ext fs stats\r
  * @return  standard error code */\r
 int ext4_mount_point_stats(const char *mount_point,\r
-    struct ext4_mount_stats *stats);\r
+                          struct ext4_mount_stats *stats);\r
 \r
 /**@brief   Setup OS lock routines.\r
  * @param   mount_point mount path\r
  * @param   locks - lock and unlock functions\r
  * @return  standard error code */\r
-int ext4_mount_setup_locks(const char * mount_point,\r
-    const struct ext4_lock *locks);\r
+int ext4_mount_setup_locks(const char *mount_point,\r
+                          const struct ext4_lock *locks);\r
+\r
+/**@brief   Acquire the filesystem superblock pointer of a mp.\r
+ * @param   mount_point mount path\r
+ * @param   superblock pointer\r
+ * @return  standard error code */\r
+int ext4_get_sblock(const char *mount_point, struct ext4_sblock **sb);\r
 \r
 /**@brief   Enable/disable write back cache mode.\r
  * @warning Default model of cache is write trough. It means that when You do:\r
@@ -252,6 +258,12 @@ int ext4_cache_write_back(const char *path, bool on);
  * @return  standard error code */\r
 int ext4_fremove(const char *path);\r
 \r
+/**@brief Rename file\r
+ * @param path source\r
+ * @param new_path destination\r
+ * @return  standard error code */\r
+int ext4_frename(const char *path, const char *new_path);\r
+\r
 /**@brief   File open function.\r
  * @param   filename, (has to start from mount point)\r
  *          /my_partition/my_file\r
@@ -271,20 +283,41 @@ int ext4_fremove(const char *path);
  *  |---------------------------------------------------------------|\r
  *\r
  * @return  standard error code*/\r
-int ext4_fopen (ext4_file *f, const char *path, const char *flags);\r
+int ext4_fopen(ext4_file *f, const char *path, const char *flags);\r
+\r
+/**@brief   Alternate file open function.\r
+ * @param   filename, (has to start from mount point)\r
+ *          /my_partition/my_file\r
+ * @param   flags open file flags\r
+ * @return  standard error code*/\r
+int ext4_fopen2(ext4_file *f, const char *path, int flags, bool file_expect);\r
 \r
 /**@brief   File close function.\r
  * @param   f file handle\r
  * @return  standard error code*/\r
 int ext4_fclose(ext4_file *f);\r
 \r
+/**@brief   Fill in the ext4_inode buffer.\r
+ * @param   mount_point\r
+ * @param   inode no.\r
+ * @param   ext4_inode buffer\r
+ * @return  standard error code*/\r
+int ext4_fill_raw_inode(const char *mount_point, uint32_t ino,\r
+                       struct ext4_inode *inode);\r
+\r
+/**@brief   File truncate function.\r
+ * @param   f file handle\r
+ * @param   new file size\r
+ * @return  standard error code*/\r
+int ext4_ftruncate(ext4_file *f, uint64_t size);\r
+\r
 /**@brief   Read data from file.\r
  * @param   f file handle\r
  * @param   buf output buffer\r
  * @param   size bytes to read\r
  * @param   rcnt bytes read (may be NULL)\r
  * @return  standard error code*/\r
-int ext4_fread (ext4_file *f, void *buf, uint32_t size, uint32_t *rcnt);\r
+int ext4_fread(ext4_file *f, void *buf, uint32_t size, uint32_t *rcnt);\r
 \r
 /**@brief   Write data to file.\r
  * @param   f file handle\r
@@ -292,7 +325,7 @@ int ext4_fread (ext4_file *f, void *buf, uint32_t size, uint32_t *rcnt);
  * @param   size write length\r
  * @param   wcnt bytes written (may be NULL)\r
  * @return  standard error code*/\r
-int ext4_fwrite(ext4_file *f, void *buf, uint32_t size, uint32_t *wcnt);\r
+int ext4_fwrite(ext4_file *f, const void *buf, uint32_t size, uint32_t *wcnt);\r
 \r
 /**@brief   File seek operation.\r
  * @param   f file handle\r
@@ -302,17 +335,23 @@ int ext4_fwrite(ext4_file *f, void *buf, uint32_t size, uint32_t *wcnt);
  *              @ref SEEK_CUR\r
  *              @ref SEEK_END\r
  * @return  standard error code*/\r
-int ext4_fseek (ext4_file *f, uint64_t offset, uint32_t origin);\r
+int ext4_fseek(ext4_file *f, uint64_t offset, uint32_t origin);\r
 \r
 /**@brief   Get file position.\r
  * @param   f file handle\r
  * @return  actual file position */\r
-uint64_t ext4_ftell (ext4_file *f);\r
+uint64_t ext4_ftell(ext4_file *f);\r
 \r
 /**@brief   Get file size.\r
  * @param   f file handle\r
  * @return  file size */\r
-uint64_t ext4_fsize (ext4_file *f);\r
+uint64_t ext4_fsize(ext4_file *f);\r
+\r
+int ext4_fchmod(ext4_file *f, uint32_t mode);\r
+int ext4_fchown(ext4_file *f, uint32_t uid, uint32_t gid);\r
+int ext4_file_set_atime(ext4_file *f, uint32_t atime);\r
+int ext4_file_set_mtime(ext4_file *f, uint32_t mtime);\r
+int ext4_file_set_ctime(ext4_file *f, uint32_t ctime);\r
 \r
 /*********************************DIRECTORY OPERATION***********************/\r
 \r
@@ -330,19 +369,18 @@ int ext4_dir_mk(const char *path);
  * @param   d directory handle\r
  * @param   path directory path\r
  * @return  standard error code*/\r
-int ext4_dir_open (ext4_dir *d, const char *path);\r
+int ext4_dir_open(ext4_dir *d, const char *path);\r
 \r
 /**@brief   Directory close.\r
  * @param   d directory handle\r
  * @return  standard error code*/\r
 int ext4_dir_close(ext4_dir *d);\r
 \r
-\r
-/**@brief   Return directory entry by id.\r
+/**@brief   Return next directory entry.\r
  * @param   d directory handle\r
  * @param   id entry id\r
- * @return  directory entry id (NULL id no entry)*/\r
-ext4_direntry* ext4_dir_entry_get(ext4_dir *d, uint32_t id);\r
+ * @return  directory entry id (NULL if no entry)*/\r
+const ext4_direntry *ext4_dir_entry_next(ext4_dir *d);\r
 \r
 #endif /* EXT4_H_ */\r
 \r