Whamcloud - gitweb
unix_io.c: Add #ifdef NO_IO_CACHE which disables all userspace
[tools/e2fsprogs.git] / lib / ext2fs / ext2fs.h
index 762b7eb..926d5af 100644 (file)
@@ -24,6 +24,15 @@ extern "C" {
 #endif
 
 /*
+ * Build in support for byte-swapping filesystems if we the feature
+ * has been configured or if we're being built on a CPU architecture
+ * with a non-native byte order.
+ */
+#if defined(ENABLE_SWAPFS) || defined(WORDS_BIGENDIAN)
+#define EXT2FS_ENABLE_SWAPFS
+#endif
+
+/*
  * Where the master copy of the superblock is located, and how big
  * superblocks are supposed to be.  We define SUPERBLOCK_SIZE because
  * the size of the superblock structure is not necessarily trustworthy
@@ -43,22 +52,15 @@ extern "C" {
 #include <sys/types.h>
 #endif
 
+#include <stdio.h>
 #include <stdlib.h>
 
 #if EXT2_FLAT_INCLUDES
 #include "e2_types.h"
+#include "ext2_fs.h"
 #else
-#include <asm/types.h>
-#if !defined(__GNUC__) || defined(__STRICT_ANSI__)  /* asm/types.h already defines __s64 and __u64 otherwise */
-#if SIZEOF_LONG == 8
-typedef __signed__ long __s64;
-typedef unsigned long __u64;
-#elif SIZEOF_LONG_LONG == 8 || \
-  defined(__GNUC__) && (((~0UL) == 0xffffffff) || defined(__i386__))
-typedef __signed__ long long __s64;
-typedef unsigned long long __u64;
-#endif /* SIZEOF_LONG == 8 */
-#endif
+#include <ext2fs/ext2_types.h>
+#include <ext2fs/ext2_fs.h>
 #endif /* EXT2_FLAT_INCLUDES */
 
 typedef __u32          ext2_ino_t;
@@ -66,6 +68,7 @@ typedef __u32         blk_t;
 typedef __u32          dgrp_t;
 typedef __u32          ext2_off_t;
 typedef __s64          e2_blkcnt_t;
+typedef __u32          ext2_dirhash_t;
 
 #if EXT2_FLAT_INCLUDES
 #include "com_err.h"
@@ -118,12 +121,15 @@ typedef struct ext2fs_struct_generic_bitmap *ext2fs_block_bitmap;
  * badblocks list definitions
  */
 
-typedef struct ext2_struct_badblocks_list *ext2_badblocks_list;
-typedef struct ext2_struct_badblocks_iterate *ext2_badblocks_iterate;
+typedef struct ext2_struct_u32_list *ext2_badblocks_list;
+typedef struct ext2_struct_u32_iterate *ext2_badblocks_iterate;
+
+typedef struct ext2_struct_u32_list *ext2_u32_list;
+typedef struct ext2_struct_u32_iterate *ext2_u32_iterate;
 
 /* old */
-typedef struct ext2_struct_badblocks_list *badblocks_list;
-typedef struct ext2_struct_badblocks_iterate *badblocks_iterate;
+typedef struct ext2_struct_u32_list *badblocks_list;
+typedef struct ext2_struct_u32_iterate *badblocks_iterate;
 
 #define BADBLOCKS_FLAG_DIRTY   1
 
@@ -210,15 +216,16 @@ struct struct_ext2_filsys {
                                struct ext2_inode *inode);
        errcode_t (*write_inode)(ext2_filsys fs, ext2_ino_t ino,
                                struct ext2_inode *inode);
-       badblocks_list                  badblocks;
+       ext2_badblocks_list             badblocks;
        ext2_dblist                     dblist;
        __u32                           stride; /* for mke2fs */
        struct ext2_super_block *       orig_super;
        struct ext2_image_hdr *         image_header;
+       __u32                           umask;
        /*
         * Reserved for future expansion
         */
-       __u32                           reserved[9];
+       __u32                           reserved[8];
 
        /*
         * Reserved for the use of the calling application.
@@ -289,6 +296,11 @@ struct struct_ext2_filsys {
 #endif
 
 /*
+ * Flags for directory block reading and writing functions
+ */
+#define EXT2_DIRBLOCK_V2_STRUCT        0x0001
+
+/*
  * Return flags for the directory iterator functions
  */
 #define DIRENT_CHANGED 1
@@ -300,11 +312,12 @@ struct struct_ext2_filsys {
  */
 
 #define DIRENT_FLAG_INCLUDE_EMPTY      1
-
+#define DIRENT_FLAG_INCLUDE_REMOVED    2
 
 #define DIRENT_DOT_FILE                1
 #define DIRENT_DOT_DOT_FILE    2
 #define DIRENT_OTHER_FILE      3
+#define DIRENT_DELETED_FILE    4
 
 /*
  * Inode scan definitions
@@ -325,6 +338,7 @@ typedef struct ext2_struct_inode_scan *ext2_inode_scan;
 #define EXT2_MF_MOUNTED                1
 #define EXT2_MF_ISROOT         2
 #define EXT2_MF_READONLY       4
+#define EXT2_MF_SWAP           8
 
 /*
  * Ext2/linux mode flags.  We define them here so that we don't need
@@ -367,6 +381,11 @@ typedef struct ext2_struct_inode_scan *ext2_inode_scan;
 #define LINUX_S_ISSOCK(m)      (((m) & LINUX_S_IFMT) == LINUX_S_IFSOCK)
 
 /*
+ * ext2 size of an inode
+ */
+#define EXT2_I_SIZE(i) ((i)->i_size | ((__u64) (i)->i_size_high << 32))
+
+/*
  * ext2_icount_t abstraction
  */
 #define EXT2_ICOUNT_OPT_INCREMENT      0x01
@@ -403,7 +422,9 @@ typedef struct ext2_icount *ext2_icount_t;
  */
 #define EXT2_LIB_FEATURE_COMPAT_SUPP   (EXT2_FEATURE_COMPAT_DIR_PREALLOC|\
                                         EXT2_FEATURE_COMPAT_IMAGIC_INODES|\
-                                        EXT3_FEATURE_COMPAT_HAS_JOURNAL)
+                                        EXT3_FEATURE_COMPAT_HAS_JOURNAL|\
+                                        EXT2_FEATURE_COMPAT_DIR_INDEX|\
+                                        EXT2_FEATURE_COMPAT_EXT_ATTR)
 
 /* This #ifdef is temporary until compression is fully supported */
 #ifdef ENABLE_COMPRESSION
@@ -416,10 +437,12 @@ typedef struct ext2_icount *ext2_icount_t;
 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
                                         EXT2_FEATURE_INCOMPAT_COMPRESSION|\
                                         EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
+                                        EXT2_FEATURE_INCOMPAT_META_BG|\
                                         EXT3_FEATURE_INCOMPAT_RECOVER)
 #else
 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
                                         EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|\
+                                        EXT2_FEATURE_INCOMPAT_META_BG|\
                                         EXT3_FEATURE_INCOMPAT_RECOVER)
 #endif
 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP        (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
@@ -440,12 +463,28 @@ extern errcode_t ext2fs_get_free_blocks(ext2_filsys fs, blk_t start,
 extern errcode_t ext2fs_alloc_block(ext2_filsys fs, blk_t goal,
                                    char *block_buf, blk_t *ret);
 
+/* alloc_stats.c */
+void ext2fs_inode_alloc_stats(ext2_filsys fs, ext2_ino_t ino, int inuse);
+void ext2fs_inode_alloc_stats2(ext2_filsys fs, ext2_ino_t ino,
+                              int inuse, int isdir);
+void ext2fs_block_alloc_stats(ext2_filsys fs, blk_t blk, int inuse);
+
 /* alloc_tables.c */
 extern errcode_t ext2fs_allocate_tables(ext2_filsys fs);
 extern errcode_t ext2fs_allocate_group_table(ext2_filsys fs, dgrp_t group,
                                             ext2fs_block_bitmap bmap);
 
 /* badblocks.c */
+extern errcode_t ext2fs_u32_list_create(ext2_u32_list *ret, int size);
+extern errcode_t ext2fs_u32_list_add(ext2_u32_list bb, __u32 blk);
+extern int ext2fs_u32_list_test(ext2_u32_list bb, blk_t blk);
+extern errcode_t ext2fs_u32_list_iterate_begin(ext2_u32_list bb,
+                                              ext2_u32_iterate *ret);
+extern int ext2fs_u32_list_iterate(ext2_u32_iterate iter, blk_t *blk);
+extern void ext2fs_u32_list_iterate_end(ext2_u32_iterate iter);
+extern errcode_t ext2fs_u32_copy(ext2_u32_list src, ext2_u32_list *dest);
+extern int ext2fs_u32_list_equal(ext2_u32_list bb1, ext2_u32_list bb2);
+
 extern errcode_t ext2fs_badblocks_list_create(ext2_badblocks_list *ret,
                                            int size);
 extern errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb,
@@ -462,6 +501,7 @@ extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
                                       ext2_badblocks_list *dest);
 extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
                                  ext2_badblocks_list bb2);
+extern int ext2fs_u32_list_count(ext2_u32_list bb);
 
 /* bb_compat */
 extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
@@ -560,6 +600,9 @@ extern errcode_t ext2fs_get_num_dirs(ext2_filsys fs, ext2_ino_t *ret_num_dirs);
 extern errcode_t ext2fs_init_dblist(ext2_filsys fs, ext2_dblist *ret_dblist);
 extern errcode_t ext2fs_add_dir_block(ext2_dblist dblist, ext2_ino_t ino,
                                      blk_t blk, int blockcnt);
+extern void ext2fs_dblist_sort(ext2_dblist dblist,
+                              EXT2_QSORT_TYPE (*sortfunc)(const void *,
+                                                          const void *));
 extern errcode_t ext2fs_dblist_iterate(ext2_dblist dblist,
        int (*func)(ext2_filsys fs, struct ext2_db_entry *db_info,
                    void        *priv_data),
@@ -587,8 +630,19 @@ extern errcode_t
 /* dirblock.c */
 extern errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
                                       void *buf);
+extern errcode_t ext2fs_read_dir_block2(ext2_filsys fs, blk_t block,
+                                       void *buf, int flags);
 extern errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
                                        void *buf);
+extern errcode_t ext2fs_write_dir_block2(ext2_filsys fs, blk_t block,
+                                        void *buf, int flags);
+
+/* dirhash.c */
+extern errcode_t ext2fs_dirhash(int version, const char *name, int len,
+                               const __u32 *seed,
+                               ext2_dirhash_t *ret_hash,
+                               ext2_dirhash_t *ret_minor_hash);
+
 
 /* dir_iterate.c */
 extern errcode_t ext2fs_dir_iterate(ext2_filsys fs, 
@@ -601,6 +655,18 @@ extern errcode_t ext2fs_dir_iterate(ext2_filsys fs,
                                          char  *buf,
                                          void  *priv_data),
                              void *priv_data);
+extern errcode_t ext2fs_dir_iterate2(ext2_filsys fs, 
+                             ext2_ino_t dir,
+                             int flags,
+                             char *block_buf,
+                             int (*func)(ext2_ino_t    dir,
+                                         int   entry,
+                                         struct ext2_dir_entry *dirent,
+                                         int   offset,
+                                         int   blocksize,
+                                         char  *buf,
+                                         void  *priv_data),
+                             void *priv_data);
 
 /* dupfs.c */
 extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
@@ -608,17 +674,30 @@ extern errcode_t ext2fs_dup_handle(ext2_filsys src, ext2_filsys *dest);
 /* expanddir.c */
 extern errcode_t ext2fs_expand_dir(ext2_filsys fs, ext2_ino_t dir);
 
+/* ext_attr.c */
+void ext2fs_swap_ext_attr(ext2_filsys fs, char *to, char *from);
+extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
+extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
+                                      void *buf);
+extern errcode_t ext2fs_adjust_ea_refcount(ext2_filsys fs, blk_t blk,
+                                          char *block_buf,
+                                          int adjust, __u32 *newcount);
+
 /* fileio.c */
 extern errcode_t ext2fs_file_open(ext2_filsys fs, ext2_ino_t ino,
                                  int flags, ext2_file_t *ret);
 extern ext2_filsys ext2fs_file_get_fs(ext2_file_t file);
 extern errcode_t ext2fs_file_close(ext2_file_t file);
+extern errcode_t ext2fs_file_flush(ext2_file_t file);
 extern errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
                                  unsigned int wanted, unsigned int *got);
-extern errcode_t ext2fs_file_write(ext2_file_t file, void *buf,
+extern errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
                                   unsigned int nbytes, unsigned int *written);
+extern errcode_t ext2fs_file_llseek(ext2_file_t file, __u64 offset,
+                                  int whence, __u64 *ret_pos);
 extern errcode_t ext2fs_file_lseek(ext2_file_t file, ext2_off_t offset,
                                   int whence, ext2_off_t *ret_pos);
+errcode_t ext2fs_file_get_lsize(ext2_file_t file, __u64 *ret_size);
 extern ext2_off_t ext2fs_file_get_size(ext2_file_t file);
 extern errcode_t ext2fs_file_set_size(ext2_file_t file, ext2_off_t size);
 
@@ -634,7 +713,8 @@ extern void ext2fs_free_generic_bitmap(ext2fs_inode_bitmap bitmap);
 extern void ext2fs_free_block_bitmap(ext2fs_block_bitmap bitmap);
 extern void ext2fs_free_inode_bitmap(ext2fs_inode_bitmap bitmap);
 extern void ext2fs_free_dblist(ext2_dblist dblist);
-extern void ext2fs_badblocks_list_free(badblocks_list bb);
+extern void ext2fs_badblocks_list_free(ext2_badblocks_list bb);
+extern void ext2fs_u32_list_free(ext2_u32_list bb);
 
 /* getsize.c */
 extern errcode_t ext2fs_get_device_size(const char *file, int blocksize,
@@ -653,6 +733,23 @@ extern errcode_t ext2fs_initialize(const char *name, int flags,
                                   struct ext2_super_block *param,
                                   io_manager manager, ext2_filsys *ret_fs);
 
+/* icount.c */
+extern void ext2fs_free_icount(ext2_icount_t icount);
+extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
+                                      ext2_icount_t hint, ext2_icount_t *ret);
+extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size,
+                                     ext2_icount_t *ret);
+extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
+                                    __u16 *ret);
+extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
+                                        __u16 *ret);
+extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
+                                        __u16 *ret);
+extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
+                                    __u16 count);
+extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
+errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
+
 /* inode.c */
 extern errcode_t ext2fs_flush_icache(ext2_filsys fs);
 extern errcode_t ext2fs_open_inode_scan(ext2_filsys fs, int buffer_blocks,
@@ -678,23 +775,11 @@ extern errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
 extern errcode_t ext2fs_get_blocks(ext2_filsys fs, ext2_ino_t ino, blk_t *blocks);
 extern errcode_t ext2fs_check_directory(ext2_filsys fs, ext2_ino_t ino);
 
-/* icount.c */
-extern void ext2fs_free_icount(ext2_icount_t icount);
-extern errcode_t ext2fs_create_icount2(ext2_filsys fs, int flags, int size,
-                                      ext2_icount_t hint, ext2_icount_t *ret);
-extern errcode_t ext2fs_create_icount(ext2_filsys fs, int flags, int size,
-                                     ext2_icount_t *ret);
-extern errcode_t ext2fs_icount_fetch(ext2_icount_t icount, ext2_ino_t ino,
-                                    __u16 *ret);
-extern errcode_t ext2fs_icount_increment(ext2_icount_t icount, ext2_ino_t ino,
-                                        __u16 *ret);
-extern errcode_t ext2fs_icount_decrement(ext2_icount_t icount, ext2_ino_t ino,
-                                        __u16 *ret);
-extern errcode_t ext2fs_icount_store(ext2_icount_t icount, ext2_ino_t ino,
-                                    __u16 count);
-extern ext2_ino_t ext2fs_get_icount_size(ext2_icount_t icount);
-errcode_t ext2fs_icount_validate(ext2_icount_t icount, FILE *);
-
+/* inode_io.c */
+extern io_manager inode_io_manager;
+extern errcode_t ext2fs_inode_io_intern(ext2_filsys fs, ext2_ino_t ino, 
+                                       char **name);
+       
 /* ismounted.c */
 extern errcode_t ext2fs_check_if_mounted(const char *file, int *mount_flags);
 extern errcode_t ext2fs_check_mount_point(const char *device, int *mount_flags,
@@ -734,6 +819,8 @@ extern errcode_t ext2fs_add_journal_inode(ext2_filsys fs, blk_t size,
 extern errcode_t ext2fs_open(const char *name, int flags, int superblock,
                             int block_size, io_manager manager,
                             ext2_filsys *ret_fs);
+extern blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, 
+                                        dgrp_t i);
 
 /* get_pathname.c */
 extern errcode_t ext2fs_get_pathname(ext2_filsys fs, ext2_ino_t dir, ext2_ino_t ino,
@@ -752,11 +839,11 @@ extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
 /* read_bb_file.c */
 extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f, 
                                      ext2_badblocks_list *bb_list,
-                                     void *private,
+                                     void *priv_data,
                                      void (*invalid)(ext2_filsys fs,
                                                      blk_t blk,
                                                      char *badstr,
-                                                     void *private));
+                                                     void *priv_data));
 extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, 
                                     ext2_badblocks_list *bb_list,
                                     void (*invalid)(ext2_filsys fs,
@@ -810,6 +897,8 @@ extern int ext2fs_test_ib_dirty(ext2_filsys fs);
 extern int ext2fs_test_bb_dirty(ext2_filsys fs);
 extern int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk);
 extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino);
+extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
+                                     struct ext2_inode *inode);
 
 /*
  * The actual inlined functions definitions themselves...
@@ -962,6 +1051,13 @@ _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino)
 {
        return (ino - 1) / fs->super->s_inodes_per_group;
 }
+
+_INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs,
+                                       struct ext2_inode *inode)
+{
+       return inode->i_blocks -
+              (inode->i_file_acl ? fs->blocksize >> 9 : 0);
+}
 #undef _INLINE_
 #endif