2 * read_bb_file.c --- read a list of bad blocks from a FILE *
4 * Copyright (C) 1994, 1995, 2000 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Library
8 * General Public License, version 2.
24 #include <sys/types.h>
31 * Reads a list of bad blocks from a FILE *
33 errcode_t ext2fs_read_bb_FILE2(ext2_filsys fs, FILE *f,
34 ext2_badblocks_list *bb_list,
36 void (*invalid)(ext2_filsys fs,
47 EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
50 retval = ext2fs_badblocks_list_create(bb_list, 10);
56 if (fgets(buf, sizeof(buf), f) == NULL)
58 count = sscanf(buf, "%u", &blockno);
62 ((blockno < fs->super->s_first_data_block) ||
63 (blockno >= ext2fs_blocks_count(fs->super)))) {
65 (invalid)(fs, blockno, buf, priv_data);
68 retval = ext2fs_badblocks_list_add(*bb_list, blockno);
75 struct compat_struct {
76 void (*invalid)(ext2_filsys, blk_t);
79 static void call_compat_invalid(ext2_filsys fs, blk_t blk,
80 char *badstr EXT2FS_ATTR((unused)),
83 struct compat_struct *st;
85 st = (struct compat_struct *) priv_data;
87 (st->invalid)(fs, blk);
92 * Reads a list of bad blocks from a FILE *
94 errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f,
95 ext2_badblocks_list *bb_list,
96 void (*invalid)(ext2_filsys fs, blk_t blk))
98 struct compat_struct st;
100 st.invalid = invalid;
102 return ext2fs_read_bb_FILE2(fs, f, bb_list, &st,
103 call_compat_invalid);