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
,
42 unsigned long long blockno
;
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
, "%llu", &blockno
);
61 /* Badblocks isn't going to be updated for 64bit */
65 ((blockno
< fs
->super
->s_first_data_block
) ||
66 (blockno
>= ext2fs_blocks_count(fs
->super
)))) {
68 (invalid
)(fs
, (blk64_t
) blockno
, buf
, priv_data
);
71 retval
= ext2fs_badblocks_list_add(*bb_list
, (blk64_t
) blockno
);
78 struct compat_struct
{
79 void (*invalid
)(ext2_filsys
, blk_t
);
82 static void call_compat_invalid(ext2_filsys fs
, blk_t blk
,
83 char *badstr
EXT2FS_ATTR((unused
)),
86 struct compat_struct
*st
;
88 st
= (struct compat_struct
*) priv_data
;
90 (st
->invalid
)(fs
, blk
);
95 * Reads a list of bad blocks from a FILE *
97 errcode_t
ext2fs_read_bb_FILE(ext2_filsys fs
, FILE *f
,
98 ext2_badblocks_list
*bb_list
,
99 void (*invalid
)(ext2_filsys fs
, blk_t blk
))
101 struct compat_struct st
;
103 st
.invalid
= invalid
;
105 return ext2fs_read_bb_FILE2(fs
, f
, bb_list
, &st
,
106 call_compat_invalid
);