Whamcloud - gitweb
libext2fs: ext2fs_new_block2() should call alloc_block hook
[tools/e2fsprogs.git] / lib / ext2fs / closefs.c
index c2eaec1..3c7c7dc 100644 (file)
@@ -291,7 +291,7 @@ errcode_t ext2fs_flush2(ext2_filsys fs, int flags)
        dgrp_t          j;
 #endif
        char    *group_ptr;
-       int     old_desc_blocks;
+       blk64_t old_desc_blocks;
        struct ext2fs_numeric_progress_struct progress;
 
        EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
@@ -362,9 +362,11 @@ errcode_t ext2fs_flush2(ext2_filsys fs, int flags)
         * superblocks and group descriptors.
         */
        group_ptr = (char *) group_shadow;
-       if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG)
+       if (fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) {
                old_desc_blocks = fs->super->s_first_meta_bg;
-       else
+               if (old_desc_blocks > fs->desc_blocks)
+                       old_desc_blocks = fs->desc_blocks;
+       } else
                old_desc_blocks = fs->desc_blocks;
 
        if (fs->progress_ops && fs->progress_ops->init)
@@ -450,6 +452,18 @@ errout:
        return retval;
 }
 
+errcode_t ext2fs_close_free(ext2_filsys *fs_ptr)
+{
+       errcode_t ret;
+       ext2_filsys fs = *fs_ptr;
+
+       ret = ext2fs_close2(fs, 0);
+       if (ret)
+               ext2fs_free(fs);
+       *fs_ptr = NULL;
+       return ret;
+}
+
 errcode_t ext2fs_close(ext2_filsys fs)
 {
        return ext2fs_close2(fs, 0);