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
read_bb_file.o \
res_gdt.o \
rw_bitmaps.o \
- sparse.o \
swapfs.o \
unix_io.o \
unlink.o \
$(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 \
$(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 \
#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,
/* 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,
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);
/*
- * 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
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;