summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2004-12-15 18:06:52 -0500
committerTheodore Ts'o <tytso@mit.edu>2004-12-15 18:06:52 -0500
commit1b4cd9c7464d5bd0f5b416c7303bcc827e312473 (patch)
treefce84c641673240e056128698d94c098d8177200 /lib
parentf581372280214bd494f4876ab39e559f3ef9f60b (diff)
downloade2fsprogs-1b4cd9c7464d5bd0f5b416c7303bcc827e312473.tar.gz
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.
Diffstat (limited to 'lib')
-rw-r--r--lib/ext2fs/ChangeLog11
-rw-r--r--lib/ext2fs/Makefile.in4
-rw-r--r--lib/ext2fs/closefs.c26
-rw-r--r--lib/ext2fs/ext2fs.h8
-rw-r--r--lib/ext2fs/res_gdt.c40
5 files changed, 77 insertions, 12 deletions
diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog
index 14664fd1..c72f3e3a 100644
--- a/lib/ext2fs/ChangeLog
+++ b/lib/ext2fs/ChangeLog
@@ -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
diff --git a/lib/ext2fs/Makefile.in b/lib/ext2fs/Makefile.in
index 6543e396..5929c704 100644
--- a/lib/ext2fs/Makefile.in
+++ b/lib/ext2fs/Makefile.in
@@ -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 \
diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c
index 6fe012ce..8539a1c2 100644
--- a/lib/ext2fs/closefs.c
+++ b/lib/ext2fs/closefs.c
@@ -19,6 +19,32 @@
#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,
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index 4904a3bd..8d358b49 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -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);
diff --git a/lib/ext2fs/res_gdt.c b/lib/ext2fs/res_gdt.c
index 727b8267..e9262429 100644
--- a/lib/ext2fs/res_gdt.c
+++ b/lib/ext2fs/res_gdt.c
@@ -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
@@ -17,6 +17,42 @@
#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;