Whamcloud - gitweb
ChangeLog, Makefile.in, badblocks.c, freefs.c, tst_badblocks.c:
authorTheodore Ts'o <tytso@mit.edu>
Mon, 8 Nov 1999 22:05:04 +0000 (22:05 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 8 Nov 1999 22:05:04 +0000 (22:05 +0000)
  Makefile.in (tst_badblocks): Add freefs.o to the object list, since
  ext2fs_badblocks_list_free was moved to freefs.c.
  tst_badblocks.c: Use the newer badblocks API names.  Add duplicate
   blocks to the test inputs to test dealing with adding blocks which are
   already in the badblocks list.
  badblocks.c (ext2fs_badblocks_list_add): If appending to the end of
   the list, use a shortcut O(1) operations instead of an O(n) operation.
   (Idea suggested by David Beattie.)
  freefs.c (ext2fs_free): Use ext2fs_badblocks_list_free() instead of
   badblocks_list_free(), to save a procedure call.

lib/ext2fs/ChangeLog
lib/ext2fs/Makefile.in
lib/ext2fs/badblocks.c
lib/ext2fs/freefs.c
lib/ext2fs/tst_badblocks.c

index 7eb4bba..a13b66e 100644 (file)
@@ -1,3 +1,19 @@
+1999-11-08    <tytso@valinux.com>
+
+       * Makefile.in (tst_badblocks): Add freefs.o to the object list,
+               since ext2fs_badblocks_list_free was moved to freefs.c.
+
+       * tst_badblocks.c: Use the newer badblocks API names.  Add
+               duplicate blocks to the test inputs to test dealing with
+               adding blocks which are already in the badblocks list.
+
+       * badblocks.c (ext2fs_badblocks_list_add): If appending to the end
+               of the list, use a shortcut O(1) operations instead of an
+               O(n) operation.  (Idea suggested by David Beattie.)
+
+       * freefs.c (ext2fs_free): Use ext2fs_badblocks_list_free() instead
+               of badblocks_list_free(), to save a procedure call.
+
 1999-10-26    <tytso@valinux.com>
 
        * Release of E2fsprogs 1.17
index 093e2b2..4767521 100644 (file)
@@ -154,8 +154,8 @@ ext2_err.et: $(DEP_SUBSTITUTE) $(srcdir)/ext2_err.et.in
 ext2_err.c ext2_err.h: ext2_err.et
        $(COMPILE_ET) ext2_err.et
 
-tst_badblocks: tst_badblocks.o badblocks.o
-       $(CC) -o tst_badblocks tst_badblocks.o badblocks.o $(LIBCOM_ERR)
+tst_badblocks: tst_badblocks.o badblocks.o freefs.o
+       $(CC) -o tst_badblocks tst_badblocks.o badblocks.o freefs.o $(LIBCOM_ERR)
 
 tst_iscan: tst_iscan.o inode.o $(STATIC_LIBEXT2FS)
        $(CC) -o tst_iscan tst_iscan.o inode.o $(STATIC_LIBEXT2FS) \
index e2f46f1..8c09079 100644 (file)
@@ -116,6 +116,17 @@ errcode_t ext2fs_badblocks_list_add(ext2_badblocks_list bb, blk_t blk)
                }
        }
 
+       /*
+        * Add special case code for appending to the end of the list
+        */
+       i = bb->num-1;
+       if ((bb->num != 0) && (bb->list[i] == blk))
+               return 0;
+       if ((bb->num == 0) || (bb->list[i] < blk)) {
+               bb->list[bb->num++] = blk;
+               return 0;
+       }
+
        j = bb->num;
        for (i=0; i < bb->num; i++) {
                if (bb->list[i] == blk)
index e5db058..d595972 100644 (file)
@@ -43,7 +43,7 @@ void ext2fs_free(ext2_filsys fs)
                ext2fs_free_inode_bitmap(fs->inode_map);
 
        if (fs->badblocks)
-               badblocks_list_free(fs->badblocks);
+               ext2fs_badblocks_list_free(fs->badblocks);
        fs->badblocks = 0;
 
        if (fs->dblist)
index 49b0bbd..effcca7 100644 (file)
@@ -31,8 +31,8 @@
 #include "ext2fs.h"
 
 blk_t test1[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0 };
-blk_t test2[] = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
-blk_t test3[] = { 3, 1, 4, 5, 9, 2, 7, 10, 6, 8, 0 };
+blk_t test2[] = { 10, 9, 8, 7, 6, 5, 4, 3, 3, 2, 1, 0 };
+blk_t test3[] = { 3, 1, 4, 5, 9, 2, 7, 10, 5, 6, 10, 8, 0 };
 blk_t test4[] = { 20, 50, 12, 17, 13, 2, 66, 23, 56, 0 };
 blk_t test4a[] = {
        20, 1,
@@ -58,17 +58,17 @@ static errcode_t create_test_list(blk_t *vec, badblocks_list *ret)
        badblocks_list  bb;
        int             i;
        
-       retval = badblocks_list_create(&bb, 5);
+       retval = ext2fs_badblocks_list_create(&bb, 5);
        if (retval) {
                com_err("create_test_list", retval, "while creating list");
                return retval;
        }
        for (i=0; vec[i]; i++) {
-               retval = badblocks_list_add(bb, vec[i]);
+               retval = ext2fs_badblocks_list_add(bb, vec[i]);
                if (retval) {
                        com_err("create_test_list", retval,
                                "while adding test vector %d", i);
-                       badblocks_list_free(bb);
+                       ext2fs_badblocks_list_free(bb);
                        return retval;
                }
        }
@@ -83,18 +83,18 @@ static void print_list(badblocks_list bb, int verify)
        blk_t                   blk;
        int                     i, ok;
        
-       retval = badblocks_list_iterate_begin(bb, &iter);
+       retval = ext2fs_badblocks_list_iterate_begin(bb, &iter);
        if (retval) {
                com_err("print_list", retval, "while setting up iterator");
                return;
        }
        ok = i = 1;
-       while (badblocks_list_iterate(iter, &blk)) {
+       while (ext2fs_badblocks_list_iterate(iter, &blk)) {
                printf("%d ", blk);
                if (i++ != blk)
                        ok = 0;
        }
-       badblocks_list_iterate_end(iter);
+       ext2fs_badblocks_list_iterate_end(iter);
        if (verify) {
                if (ok)
                        printf("--- OK");
@@ -110,7 +110,7 @@ static void validate_test_seq(badblocks_list bb, blk_t *vec)
        int     i, match, ok;
 
        for (i = 0; vec[i]; i += 2) {
-               match = badblocks_list_test(bb, vec[i]);
+               match = ext2fs_badblocks_list_test(bb, vec[i]);
                if (match == vec[i+1])
                        ok = 1;
                else {
@@ -132,7 +132,7 @@ int main(int argc, char *argv)
        retval = create_test_list(test1, &bb);
        if (retval == 0) {
                print_list(bb, 1);
-               badblocks_list_free(bb);
+               ext2fs_badblocks_list_free(bb);
        }
        printf("\n");
        
@@ -140,7 +140,7 @@ int main(int argc, char *argv)
        retval = create_test_list(test2, &bb);
        if (retval == 0) {
                print_list(bb, 1);
-               badblocks_list_free(bb);
+               ext2fs_badblocks_list_free(bb);
        }
        printf("\n");
 
@@ -148,7 +148,7 @@ int main(int argc, char *argv)
        retval = create_test_list(test3, &bb);
        if (retval == 0) {
                print_list(bb, 1);
-               badblocks_list_free(bb);
+               ext2fs_badblocks_list_free(bb);
        }
        printf("\n");
        
@@ -158,7 +158,7 @@ int main(int argc, char *argv)
                print_list(bb, 0);
                printf("\n");
                validate_test_seq(bb, test4a);
-               badblocks_list_free(bb);
+               ext2fs_badblocks_list_free(bb);
        }
        printf("\n");
        if (test_fail == 0)