Whamcloud - gitweb
libext2fs: Always swab the MMP block on big-endian systems machines
[tools/e2fsprogs.git] / lib / ext2fs / ext2fs.h
index 1b9acc3..357bf60 100644 (file)
@@ -195,6 +195,7 @@ typedef struct ext2_file *ext2_file_t;
 #define EXT2_FLAG_64BITS               0x20000
 #define EXT2_FLAG_PRINT_PROGRESS       0x40000
 #define EXT2_FLAG_DIRECT_IO            0x80000
+#define EXT2_FLAG_SKIP_MMP             0x100000
 
 /*
  * Special flag in the ext2 inode i_flag field that means that this is
@@ -257,6 +258,18 @@ struct struct_ext2_filsys {
        io_channel                      image_io;
 
        /*
+        * Buffers for Multiple mount protection(MMP) block.
+        */
+       void *mmp_buf;
+       void *mmp_cmp;
+       int mmp_fd;
+
+       /*
+        * Time at which e2fsck last updated the MMP block.
+        */
+       long mmp_last_written;
+
+       /*
         * More callback functions
         */
        errcode_t (*get_alloc_block)(ext2_filsys fs, blk64_t goal,
@@ -549,6 +562,7 @@ typedef struct ext2_icount *ext2_icount_t;
                                         EXT3_FEATURE_INCOMPAT_RECOVER|\
                                         EXT3_FEATURE_INCOMPAT_EXTENTS|\
                                         EXT4_FEATURE_INCOMPAT_FLEX_BG|\
+                                        EXT4_FEATURE_INCOMPAT_MMP|\
                                         EXT4_FEATURE_INCOMPAT_64BIT)
 #else
 #define EXT2_LIB_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE|\
@@ -557,6 +571,7 @@ typedef struct ext2_icount *ext2_icount_t;
                                         EXT3_FEATURE_INCOMPAT_RECOVER|\
                                         EXT3_FEATURE_INCOMPAT_EXTENTS|\
                                         EXT4_FEATURE_INCOMPAT_FLEX_BG|\
+                                        EXT4_FEATURE_INCOMPAT_MMP|\
                                         EXT4_FEATURE_INCOMPAT_64BIT)
 #endif
 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP        (EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
@@ -586,13 +601,19 @@ typedef struct ext2_icount *ext2_icount_t;
 #define EXT2FS_NUM_B2C(fs, blks)       (((blks) + EXT2FS_CLUSTER_MASK(fs)) >> \
                                         (fs)->cluster_ratio_bits)
 
-#ifdef HAVE_OPEN64
+#if defined(HAVE_STAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED)
 typedef struct stat64 ext2fs_struct_stat;
 #else
 typedef struct stat ext2fs_struct_stat;
 #endif
 
 /*
+ * For ext2fs_close2() and ext2fs_flush2(), this flag allows you to
+ * avoid the fsync call.
+ */
+#define EXT2_FLAG_FLUSH_NO_SYNC          1
+
+/*
  * function prototypes
  */
 
@@ -876,7 +897,9 @@ extern errcode_t ext2fs_check_desc(ext2_filsys fs);
 
 /* closefs.c */
 extern errcode_t ext2fs_close(ext2_filsys fs);
+extern errcode_t ext2fs_close2(ext2_filsys fs, int flags);
 extern errcode_t ext2fs_flush(ext2_filsys fs);
+extern errcode_t ext2fs_flush2(ext2_filsys fs, int flags);
 extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
 extern errcode_t ext2fs_super_and_bgd_loc2(ext2_filsys fs,
                                    dgrp_t group,
@@ -893,8 +916,8 @@ extern int ext2fs_super_and_bgd_loc(ext2_filsys fs,
 extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
 
 /* crc32c.c */
-extern __u32 crc32c_be(__u32 crc, unsigned char const *p, size_t len);
-extern __u32 crc32c_le(__u32 crc, unsigned char const *p, size_t len);
+extern __u32 ext2fs_crc32c_be(__u32 crc, unsigned char const *p, size_t len);
+extern __u32 ext2fs_crc32c_le(__u32 crc, unsigned char const *p, size_t len);
 
 /* csum.c */
 extern void ext2fs_group_desc_csum_set(ext2_filsys fs, dgrp_t group);
@@ -1321,6 +1344,16 @@ errcode_t ext2fs_link(ext2_filsys fs, ext2_ino_t dir, const char *name,
 errcode_t ext2fs_unlink(ext2_filsys fs, ext2_ino_t dir, const char *name,
                        ext2_ino_t ino, int flags);
 
+/* mmp.c */
+errcode_t ext2fs_mmp_read(ext2_filsys fs, blk64_t mmp_blk, void *buf);
+errcode_t ext2fs_mmp_write(ext2_filsys fs, blk64_t mmp_blk, void *buf);
+errcode_t ext2fs_mmp_clear(ext2_filsys fs);
+errcode_t ext2fs_mmp_init(ext2_filsys fs);
+errcode_t ext2fs_mmp_start(ext2_filsys fs);
+errcode_t ext2fs_mmp_update(ext2_filsys fs);
+errcode_t ext2fs_mmp_stop(ext2_filsys fs);
+unsigned ext2fs_mmp_new_seq();
+
 /* read_bb.c */
 extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
                                      ext2_badblocks_list *bb_list);
@@ -1356,6 +1389,7 @@ extern void ext2fs_swap_inode_full(ext2_filsys fs, struct ext2_inode_large *t,
                                   int bufsize);
 extern void ext2fs_swap_inode(ext2_filsys fs,struct ext2_inode *t,
                              struct ext2_inode *f, int hostorder);
+extern void ext2fs_swap_mmp(struct mmp_struct *mmp);
 
 /* valid_blk.c */
 extern int ext2fs_inode_has_valid_blocks(struct ext2_inode *inode);
@@ -1403,6 +1437,7 @@ extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b);
 extern __u64 ext2fs_div64_ceil(__u64 a, __u64 b);
 extern int ext2fs_open_file(const char *pathname, int flags, ...);
 extern int ext2fs_stat(const char *path, ext2fs_struct_stat *buf);
+extern int ext2fs_fstat(int fd, ext2fs_struct_stat *buf);
 
 /*
  * The actual inlined functions definitions themselves...
@@ -1663,7 +1698,7 @@ _INLINE_ int ext2fs_open_file(const char *pathname, int flags, ...)
        va_end(args);
 
        if (mode)
-#ifdef HAVE_OPEN64
+#if defined(HAVE_OPEN64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED)
                return open64(pathname, flags, mode);
        else
                return open64(pathname, flags);
@@ -1676,10 +1711,19 @@ _INLINE_ int ext2fs_open_file(const char *pathname, int flags, ...)
 
 _INLINE_ int ext2fs_stat(const char *path, ext2fs_struct_stat *buf)
 {
-#ifdef HAVE_OPEN64
+#if defined(HAVE_STAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED)
        return stat64(path, buf);
 #else
-       return open(path, buf);
+       return stat(path, buf);
+#endif
+}
+
+_INLINE_ int ext2fs_fstat(int fd, ext2fs_struct_stat *buf)
+{
+#if defined(HAVE_STAT64) && !defined(__OSX_AVAILABLE_BUT_DEPRECATED)
+       return fstat64(fd, buf);
+#else
+       return fstat(fd, buf);
 #endif
 }