Commit 57dca854 authored by Theodore Ts'o's avatar Theodore Ts'o
Browse files

Many files:

  tst_badblocks.c: Update test program to test ext2fs_read_bb_FILE2 and
  	ext2fs_write_FILE.
  write_bb_file.c (ext2fs_write_bb_FILE): New function which writes out
  	bad blocks list to a file.
  read_bb_file.c (ext2fs_read_bb_FILE2): Add new function which changes
  	the callback function to take two additional arguments; a private
  	blind pointer supplied by the caller, and pointer to a char *
  	containing a pointer to the invalid string.
  badblocks.c (ext2fs_badblocks_equal): Add new function which returns
  	true if two badblocks list are equal.
  Makefile.in: Remove explicit link of -lc in the shared library.  (It
  	shouldn't be necessary, and is harmful in some cases).
jump.funcs:
  dll/jump.funcs: Add new jumptable entries for ext2fs_write_bb_FILE,
  	ext2fs_read_bb_FILE2, and ext2fs_badblocks_equal.
parent b2420d40
2000-07-04 Theodore Ts'o <tytso@valinux.com>
* dll/jump.funcs: Add new jumptable entries for
ext2fs_write_bb_FILE, ext2fs_read_bb_FILE2, and
ext2fs_badblocks_equal.
* tst_badblocks.c: Update test program to test
ext2fs_read_bb_FILE2 and ext2fs_write_FILE.
* write_bb_file.c (ext2fs_write_bb_FILE): New function which
writes out bad blocks list to a file.
* read_bb_file.c (ext2fs_read_bb_FILE2): Add new function which
changes the callback function to take two additional
arguments; a private blind pointer supplied by the caller,
and pointer to a char * containing a pointer to the
invalid string.
* badblocks.c (ext2fs_badblocks_equal): Add new function which
returns true if two badblocks list are equal.
* Makefile.in: Remove explicit link of -lc in the shared library.
(It shouldn't be necessary, and is harmful in some cases).
2000-06-10 Theodore Ts'o <tytso@valinux.com>
* getsize.c (main): Add debugging code under #ifdef DEBUG
......
......@@ -52,7 +52,8 @@ OBJS= ext2_err.o \
unix_io.o \
unlink.o \
valid_blk.o \
version.o
version.o \
write_bb_file.o
SRCS= ext2_err.c \
$(srcdir)/alloc.c \
......@@ -99,7 +100,8 @@ SRCS= ext2_err.c \
$(srcdir)/unix_io.c \
$(srcdir)/unlink.c \
$(srcdir)/valid_blk.c \
$(srcdir)/version.c
$(srcdir)/version.c \
$(srcdir)/write_bb_file.c
HFILES= bitops.h ext2fs.h ext2_io.h
......@@ -121,7 +123,7 @@ ELF_SO_VERSION = 2
ELF_IMAGE = libext2fs
ELF_MYDIR = ext2fs
ELF_INSTALL_DIR = $(root_libdir)
ELF_OTHER_LIBS = -lc -L../.. -lcom_err
ELF_OTHER_LIBS = -L../.. -lcom_err
BSDLIB_VERSION = 2.1
BSDLIB_IMAGE = libext2fs
......@@ -154,8 +156,10 @@ 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 freefs.o
$(CC) -o tst_badblocks tst_badblocks.o badblocks.o freefs.o $(LIBCOM_ERR)
tst_badblocks: tst_badblocks.o freefs.o \
read_bb_file.o write_bb_file.o badblocks.o
$(CC) -o tst_badblocks tst_badblocks.o freefs.o \
read_bb_file.o write_bb_file.o badblocks.o $(LIBCOM_ERR)
tst_iscan: tst_iscan.o inode.o $(STATIC_LIBEXT2FS)
$(CC) -o tst_iscan tst_iscan.o inode.o $(STATIC_LIBEXT2FS) \
......
......@@ -226,3 +226,16 @@ void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter)
iter->bb = 0;
ext2fs_free_mem((void **) &iter);
}
int ext2fs_badblocks_equal(ext2_badblocks_list bb1, ext2_badblocks_list bb2)
{
EXT2_CHECK_MAGIC(bb1, EXT2_ET_MAGIC_BADBLOCKS_LIST);
EXT2_CHECK_MAGIC(bb2, EXT2_ET_MAGIC_BADBLOCKS_LIST);
if (bb1->num != bb2->num)
return 0;
if (memcmp(bb1->list, bb2->list, bb1->num * sizeof(blk_t)) != 0)
return 0;
return 1;
}
......@@ -170,3 +170,6 @@
00000000 T _ext2fs_get_mem libext2fs inline
00000000 T _ext2fs_free_mem libext2fs inline
00000000 T _ext2fs_resize_mem libext2fs inline
00000000 T _ext2fs_read_bb_FILE2 libext2fs read_bb_file
00000000 T _ext2fs_write_bb_FILE libext2fs write_bb_file
00000000 T _ext2fs_badblocks_equal libext2fs badblocks
......@@ -543,6 +543,8 @@ extern int ext2fs_badblocks_list_iterate(ext2_badblocks_iterate iter,
extern void ext2fs_badblocks_list_iterate_end(ext2_badblocks_iterate iter);
extern errcode_t ext2fs_badblocks_copy(ext2_badblocks_list src,
ext2_badblocks_list *dest);
extern int ext2fs_badblocks_equal(ext2_badblocks_list bb1,
ext2_badblocks_list bb2);
/* bb_compat */
extern errcode_t badblocks_list_create(badblocks_list *ret, int size);
......@@ -804,6 +806,13 @@ extern errcode_t ext2fs_read_bb_inode(ext2_filsys fs,
ext2_badblocks_list *bb_list);
/* read_bb_file.c */
extern errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
ext2_badblocks_list *bb_list,
void *private,
void (*invalid)(ext2_filsys fs,
blk_t blk,
char *badstr,
void *private));
extern errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
ext2_badblocks_list *bb_list,
void (*invalid)(ext2_filsys fs,
......
/*
* read_bb_file.c --- read a list of bad blocks for a FILE *
* read_bb_file.c --- read a list of bad blocks from a FILE *
*
* Copyright (C) 1994, 1995 Theodore Ts'o.
* Copyright (C) 1994, 1995, 2000 Theodore Ts'o.
*
* %Begin-Header%
* This file may be redistributed under the terms of the GNU Public
......@@ -34,16 +34,21 @@
/*
* Reads a list of bad blocks from a FILE *
*/
errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
ext2_badblocks_list *bb_list,
void (*invalid)(ext2_filsys fs, blk_t blk))
errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
ext2_badblocks_list *bb_list,
void *private,
void (*invalid)(ext2_filsys fs,
blk_t blk,
char *badstr,
void *private))
{
errcode_t retval;
blk_t blockno;
int count;
char buf[128];
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
if (fs)
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
if (!*bb_list) {
retval = ext2fs_badblocks_list_create(bb_list, 10);
......@@ -57,10 +62,11 @@ errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
count = sscanf(buf, "%u", &blockno);
if (count <= 0)
continue;
if ((blockno < fs->super->s_first_data_block) ||
(blockno >= fs->super->s_blocks_count)) {
if (fs &&
((blockno < fs->super->s_first_data_block) ||
(blockno >= fs->super->s_blocks_count))) {
if (invalid)
(invalid)(fs, blockno);
(invalid)(fs, blockno, buf, private);
continue;
}
retval = ext2fs_badblocks_list_add(*bb_list, blockno);
......@@ -70,4 +76,26 @@ errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
return 0;
}
static void call_compat_invalid(ext2_filsys fs, blk_t blk,
char *badstr, void *private)
{
void (*invalid)(ext2_filsys fs, blk_t blk);
invalid = (void (*)(ext2_filsys, blk_t)) private;
if (invalid)
invalid(fs, blk);
}
/*
* Reads a list of bad blocks from a FILE *
*/
errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
ext2_badblocks_list *bb_list,
void (*invalid)(ext2_filsys fs, blk_t blk))
{
return ext2fs_read_bb_FILE2(fs, f, bb_list, invalid,
call_compat_invalid);
}
......@@ -31,7 +31,7 @@
#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, 3, 2, 1, 0 };
blk_t test2[] = { 11, 10, 9, 8, 7, 6, 5, 4, 3, 3, 2, 1 };
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[] = {
......@@ -123,45 +123,120 @@ static void validate_test_seq(badblocks_list bb, blk_t *vec)
}
}
int file_test(badblocks_list bb)
{
char tmp_filename[20] = "#testXXXXXX";
badblocks_list new_bb = 0;
errcode_t retval;
FILE *f;
mktemp(tmp_filename);
unlink(tmp_filename);
f = fopen(tmp_filename, "w");
if (!f) {
fprintf(stderr, "Error opening temp file %s: %s\n",
tmp_filename, error_message(errno));
return 1;
}
retval = ext2fs_write_bb_FILE(bb, 0, f);
if (retval) {
com_err("file_test", retval, "while writing bad blocks");
return 1;
}
fclose(f);
f = fopen(tmp_filename, "r");
if (!f) {
fprintf(stderr, "Error re-opening temp file %s: %s\n",
tmp_filename, error_message(errno));
return 1;
}
retval = ext2fs_read_bb_FILE2(0, f, &new_bb, 0, 0);
if (retval) {
com_err("file_test", retval, "while reading bad blocks");
return 1;
}
fclose(f);
if (ext2fs_badblocks_equal(bb, new_bb)) {
printf("Block bitmap matched after reading and writing.\n");
} else {
printf("Block bitmap NOT matched.\n");
test_fail++;
}
}
int main(int argc, char *argv)
{
badblocks_list bb;
badblocks_list bb1, bb2, bb3, bb4;
int equal;
errcode_t retval;
bb1 = bb2 = bb3 = bb4 = 0;
printf("test1: ");
retval = create_test_list(test1, &bb);
if (retval == 0) {
print_list(bb, 1);
ext2fs_badblocks_list_free(bb);
}
retval = create_test_list(test1, &bb1);
if (retval == 0)
print_list(bb1, 1);
printf("\n");
printf("test2: ");
retval = create_test_list(test2, &bb);
if (retval == 0) {
print_list(bb, 1);
ext2fs_badblocks_list_free(bb);
}
retval = create_test_list(test2, &bb2);
if (retval == 0)
print_list(bb2, 1);
printf("\n");
printf("test3: ");
retval = create_test_list(test3, &bb);
if (retval == 0) {
print_list(bb, 1);
ext2fs_badblocks_list_free(bb);
}
retval = create_test_list(test3, &bb3);
if (retval == 0)
print_list(bb3, 1);
printf("\n");
printf("test4: ");
retval = create_test_list(test4, &bb);
retval = create_test_list(test4, &bb4);
if (retval == 0) {
print_list(bb, 0);
print_list(bb4, 0);
printf("\n");
validate_test_seq(bb, test4a);
ext2fs_badblocks_list_free(bb);
validate_test_seq(bb4, test4a);
}
printf("\n");
if (bb1 && bb2 && bb3 && bb4) {
printf("Comparison tests:\n");
equal = ext2fs_badblocks_equal(bb1, bb2);
printf("bb1 and bb2 are %sequal.\n", equal ? "" : "NOT ");
if (equal)
test_fail++;
equal = ext2fs_badblocks_equal(bb1, bb3);
printf("bb1 and bb3 are %sequal.\n", equal ? "" : "NOT ");
if (!equal)
test_fail++;
equal = ext2fs_badblocks_equal(bb1, bb4);
printf("bb1 and bb4 are %sequal.\n", equal ? "" : "NOT ");
if (equal)
test_fail++;
printf("\n");
}
if (test_fail == 0)
printf("ext2fs library badblocks tests checks out OK!\n");
file_test(bb4);
if (bb1)
ext2fs_badblocks_list_free(bb1);
if (bb2)
ext2fs_badblocks_list_free(bb2);
if (bb3)
ext2fs_badblocks_list_free(bb3);
if (bb4)
ext2fs_badblocks_list_free(bb4);
return test_fail;
}
/*
* write_bb_file.c --- write a list of bad blocks to a FILE *
*
* Copyright (C) 1994, 1995 Theodore Ts'o.
*
* %Begin-Header%
* This file may be redistributed under the terms of the GNU Public
* License.
* %End-Header%
*/
#include <stdio.h>
#if EXT2_FLAT_INCLUDES
#include "ext2_fs.h"
#else
#include <linux/ext2_fs.h>
#endif
#include "ext2fs.h"
errcode_t ext2fs_write_bb_FILE(ext2_badblocks_list bb_list,
unsigned int flags,
FILE *f)
{
badblocks_iterate bb_iter;
blk_t blk;
errcode_t retval;
retval = ext2fs_badblocks_list_iterate_begin(bb_list, &bb_iter);
if (retval)
return retval;
while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) {
fprintf(f, "%d\n", blk);
}
ext2fs_badblocks_list_iterate_end(bb_iter);
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment