X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lib%2Fext2fs%2Fread_bb_file.c;h=8d1ad1a53ef4836bd5ac0f85df3112464a740f1d;hb=afaf6db69fb5830e6c6d5652bc0689ee257e971f;hp=32a80838cf49b061adefe8298ef622209d9f84a8;hpb=4cbe8af4b0d0c72fb28bb500c1bd8a46b00fdde3;p=tools%2Fe2fsprogs.git diff --git a/lib/ext2fs/read_bb_file.c b/lib/ext2fs/read_bb_file.c index 32a8083..8d1ad1a 100644 --- a/lib/ext2fs/read_bb_file.c +++ b/lib/ext2fs/read_bb_file.c @@ -1,42 +1,50 @@ /* - * 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 - * License. + * This file may be redistributed under the terms of the GNU Library + * General Public License, version 2. * %End-Header% */ +#include "config.h" #include #include #if HAVE_UNISTD_H #include #endif -#include #include #include +#if HAVE_SYS_STAT_H #include +#endif +#if HAVE_SYS_TYPES_H #include +#endif -#include - +#include "ext2_fs.h" #include "ext2fs.h" /* * 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 *priv_data, + void (*invalid)(ext2_filsys fs, + blk_t blk, + char *badstr, + void *priv_data)) { errcode_t retval; - blk_t blockno; + blk64_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); @@ -47,13 +55,17 @@ errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, while (!feof (f)) { if (fgets(buf, sizeof(buf), f) == NULL) break; - count = sscanf(buf, "%u", &blockno); + count = sscanf(buf, "%llu", &blockno); if (count <= 0) continue; - if ((blockno < fs->super->s_first_data_block) || - (blockno >= fs->super->s_blocks_count)) { + /* Badblocks isn't going to be updated for 64bit */ + if (blockno >> 32) + return EOVERFLOW; + if (fs && + ((blockno < fs->super->s_first_data_block) || + (blockno >= ext2fs_blocks_count(fs->super)))) { if (invalid) - (invalid)(fs, blockno); + (invalid)(fs, blockno, buf, priv_data); continue; } retval = ext2fs_badblocks_list_add(*bb_list, blockno); @@ -63,4 +75,35 @@ errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, return 0; } +struct compat_struct { + void (*invalid)(ext2_filsys, blk_t); +}; + +static void call_compat_invalid(ext2_filsys fs, blk_t blk, + char *badstr EXT2FS_ATTR((unused)), + void *priv_data) +{ + struct compat_struct *st; + + st = (struct compat_struct *) priv_data; + if (st->invalid) + (st->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)) +{ + struct compat_struct st; + + st.invalid = invalid; + + return ext2fs_read_bb_FILE2(fs, f, bb_list, &st, + call_compat_invalid); +} +