Whamcloud - gitweb
sparse.c (ext2fs_list_backups, ext2fs_bg_has_super),
authorTheodore Ts'o <tytso@mit.edu>
Wed, 15 Dec 2004 23:06:52 +0000 (18:06 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 15 Dec 2004 23:06:52 +0000 (18:06 -0500)
res_gdt.c (list_backups), closefs.c (ext2fs_bg_has_super),
ext2fs.h: Move ext2fs_list_backups() to res_gdt.c, and
ext2fs_bg_has_super() back to closefs.c.  There's no
reason for the new file, since list_backups() isn't being
used by any other functions, and can be made static, and
all users of the ext2fs filesystem will have to call
ext2fs_close() anyway.

lib/ext2fs/ChangeLog
lib/ext2fs/Makefile.in
lib/ext2fs/closefs.c
lib/ext2fs/ext2fs.h
lib/ext2fs/res_gdt.c

index 14664fd..c72f3e3 100644 (file)
@@ -1,5 +1,16 @@
 2004-12-15  Theodore Ts'o  <tytso@mit.edu>
 
+       * sparse.c (ext2fs_list_backups, ext2fs_bg_has_super),
+               res_gdt.c (list_backups), closefs.c (ext2fs_bg_has_super),
+               ext2fs.h: Move ext2fs_list_backups() to res_gdt.c, and
+               ext2fs_bg_has_super() back to closefs.c.  There's no
+               reason for the new file, since list_backups() isn't being
+               used by any other functions, and can be made static, and
+               all users of the ext2fs filesystem will have to call
+               ext2fs_close() anyway.
+
+2004-12-15  Theodore Ts'o  <tytso@mit.edu>
+
        * Applied resize inode patch from Andreas Dilger
 
        * res_gdt.c (ext2fs_create_resize_inode): New function that
index 6543e39..5929c70 100644 (file)
@@ -60,7 +60,6 @@ OBJS= $(DEBUGFS_LIB_OBJS) $(RESIZE_LIB_OBJS) $(E2IMAGE_LIB_OBJS) \
        read_bb_file.o \
        res_gdt.o \
        rw_bitmaps.o \
-       sparse.o \
        swapfs.o \
        unix_io.o \
        unlink.o \
@@ -120,7 +119,6 @@ SRCS= ext2_err.c \
        $(srcdir)/res_gdt.c \
        $(srcdir)/rs_bitmap.c \
        $(srcdir)/rw_bitmaps.c \
-       $(srcdir)/sparse.c \
        $(srcdir)/swapfs.c \
        $(srcdir)/test_io.c \
        $(srcdir)/unix_io.c \
@@ -476,8 +474,6 @@ rw_bitmaps.o: $(srcdir)/rw_bitmaps.c $(srcdir)/ext2_fs.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \
  $(srcdir)/ext2_fs.h $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \
  $(top_builddir)/lib/ext2fs/ext2_err.h $(srcdir)/bitops.h $(srcdir)/e2image.h
-sparse.o: $(srcdir)/sparse.c $(srcdir)/ext2_fs.h \
- $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h
 swapfs.o: $(srcdir)/swapfs.c $(srcdir)/ext2_fs.h \
  $(top_builddir)/lib/ext2fs/ext2_types.h $(srcdir)/ext2fs.h \
  $(srcdir)/ext2_fs.h $(top_srcdir)/lib/et/com_err.h $(srcdir)/ext2_io.h \
index 6fe012c..8539a1c 100644 (file)
 #include "ext2_fs.h"
 #include "ext2fsP.h"
 
+static int test_root(int a, int b)
+{
+       if (a == 0)
+               return 1;
+       while (1) {
+               if (a == 1)
+                       return 1;
+               if (a % b)
+                       return 0;
+               a = a / b;
+       }
+}
+
+int ext2fs_bg_has_super(ext2_filsys fs, int group_block)
+{
+       if (!(fs->super->s_feature_ro_compat &
+             EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER))
+               return 1;
+
+       if (test_root(group_block, 3) || (test_root(group_block, 5)) ||
+           test_root(group_block, 7))
+               return 1;
+
+       return 0;
+}
+
 int ext2fs_super_and_bgd_loc(ext2_filsys fs, 
                             dgrp_t group,
                             blk_t *ret_super_blk,
index 4904a3b..8d358b4 100644 (file)
@@ -601,12 +601,14 @@ extern errcode_t ext2fs_check_desc(ext2_filsys fs);
 /* closefs.c */
 extern errcode_t ext2fs_close(ext2_filsys fs);
 extern errcode_t ext2fs_flush(ext2_filsys fs);
+extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
 extern int ext2fs_super_and_bgd_loc(ext2_filsys fs, 
                                    dgrp_t group,
                                    blk_t *ret_super_blk,
                                    blk_t *ret_old_desc_blk,
                                    blk_t *ret_new_desc_blk,
                                    int *ret_meta_bg);
+extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
 
 /* cmp_bitmaps.c */
 extern errcode_t ext2fs_compare_block_bitmap(ext2fs_block_bitmap bm1,
@@ -901,12 +903,6 @@ extern errcode_t ext2fs_resize_block_bitmap(__u32 new_end, __u32 new_real_end,
 extern errcode_t ext2fs_copy_bitmap(ext2fs_generic_bitmap src,
                                    ext2fs_generic_bitmap *dest);
 
-/* sparse.c */
-extern int ext2fs_bg_has_super(ext2_filsys fs, int group_block);
-extern void ext2fs_update_dynamic_rev(ext2_filsys fs);
-extern unsigned int ext2fs_list_backups(ext2_filsys fs, unsigned *three,
-                                       unsigned *five, unsigned *seven);
-
 /* swapfs.c */
 extern void ext2fs_swap_super(struct ext2_super_block * super);
 extern void ext2fs_swap_group_desc(struct ext2_group_desc *gdp);
index 727b826..e926242 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * res_gdt.h --- reserve blocks for growing the group descriptor table
+ * res_gdt.c --- reserve blocks for growing the group descriptor table
  *               during online resizing.
  *
  * Copyright (C) 2002 Andreas Dilger
 #include "ext2fs.h"
 
 /*
+ * Iterate through the groups which hold BACKUP superblock/GDT copies in an
+ * ext3 filesystem.  The counters should be initialized to 1, 5, and 7 before
+ * calling this for the first time.  In a sparse filesystem it will be the
+ * sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ...
+ * For a non-sparse filesystem it will be every group: 1, 2, 3, 4, ...
+ */
+static unsigned int list_backups(ext2_filsys fs, unsigned int *three,
+                                unsigned int *five, unsigned int *seven)
+{
+       unsigned int *min = three;
+       int mult = 3;
+       unsigned int ret;
+
+       if (!(fs->super->s_feature_ro_compat &
+             EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER)) {
+               ret = *min;
+               *min += 1;
+               return ret;
+       }
+
+       if (*five < *min) {
+               min = five;
+               mult = 5;
+       }
+       if (*seven < *min) {
+               min = seven;
+               mult = 7;
+       }
+
+       ret = *min;
+       *min *= mult;
+
+       return ret;
+}
+
+/*
  * This code assumes that the reserved blocks have already been marked in-use
  * during ext2fs_initialize(), so that they are not allocated for other
  * uses before we can add them to the resize inode (which has to come
@@ -124,7 +160,7 @@ errcode_t ext2fs_create_resize_inode(ext2_filsys fs)
                        goto out_dindir;
                }
 
-               while ((grp = ext2fs_list_backups(fs, &three, &five, &seven)) <
+               while ((grp = list_backups(fs, &three, &five, &seven)) <
                       fs->group_desc_count) {
                        blk_t expect = gdt_blk + grp * sb->s_blocks_per_group;