Whamcloud - gitweb
db7b910775fa4922a8a02744673d904c4c6d763f
[tools/e2fsprogs.git] / lib / ext2fs / read_bb_file.c
1 /*
2  * read_bb_file.c --- read a list of bad blocks for a FILE *
3  *
4  * Copyright (C) 1994 Theodore Ts'o.  This file may be redistributed
5  * under the terms of the GNU Public License.
6  */
7
8 #include <stdio.h>
9 #include <string.h>
10 #include <unistd.h>
11 #include <stdlib.h>
12 #include <fcntl.h>
13 #include <time.h>
14 #include <sys/stat.h>
15 #include <sys/types.h>
16
17 #include <linux/fs.h>
18 #include <linux/ext2_fs.h>
19
20 #include "ext2fs.h"
21
22 /*
23  * Reads a list of bad blocks from  a FILE *
24  */
25 errcode_t ext2fs_read_bb_FILE(ext2_filsys fs, FILE *f, 
26                               badblocks_list *bb_list,
27                               void (*invalid)(ext2_filsys fs, blk_t blk))
28 {
29         errcode_t       retval;
30         blk_t           blockno;
31         int             count;
32
33         if (!*bb_list) {
34                 retval = badblocks_list_create(bb_list, 10);
35                 if (retval)
36                         return retval;
37         }
38
39         while (!feof (f)) {
40                 count = fscanf (f, "%lu", &blockno);
41                 if (count <= 0)
42                         break;
43                 if ((blockno < fs->super->s_first_data_block) ||
44                     (blockno >= fs->super->s_blocks_count)) {
45                         if (invalid)
46                                 (invalid)(fs, blockno);
47                         continue;
48                 }
49                 retval = badblocks_list_add(*bb_list, blockno);
50                 return retval;
51         }
52         return 0;
53 }
54
55