1997-04-26 17:21:57 +04:00
|
|
|
/*
|
|
|
|
* read_bb --- read the bad blocks inode
|
|
|
|
*
|
1997-04-29 20:17:09 +04:00
|
|
|
* Copyright (C) 1994 Theodore Ts'o.
|
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the GNU Public
|
|
|
|
* License.
|
|
|
|
* %End-Header%
|
1997-04-26 17:21:57 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#if HAVE_UNISTD_H
|
1997-04-26 17:21:57 +04:00
|
|
|
#include <unistd.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#endif
|
1997-04-26 17:21:57 +04:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <time.h>
|
1997-10-20 03:00:21 +04:00
|
|
|
#if HAVE_SYS_STAT_H
|
1997-04-26 17:21:57 +04:00
|
|
|
#include <sys/stat.h>
|
1997-10-20 03:00:21 +04:00
|
|
|
#endif
|
|
|
|
#if HAVE_SYS_TYPES_H
|
1997-04-26 17:21:57 +04:00
|
|
|
#include <sys/types.h>
|
1997-10-20 03:00:21 +04:00
|
|
|
#endif
|
1997-04-26 17:21:57 +04:00
|
|
|
|
|
|
|
#include <linux/ext2_fs.h>
|
|
|
|
|
|
|
|
#include "ext2fs.h"
|
|
|
|
|
|
|
|
struct read_bb_record {
|
1997-04-29 20:17:09 +04:00
|
|
|
ext2_badblocks_list bb_list;
|
1997-04-26 17:21:57 +04:00
|
|
|
errcode_t err;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper function for ext2fs_read_bb_inode()
|
|
|
|
*/
|
Many files:
dosio.c: New file to do DOS/BIOS disk accesses.
namei.c (open_namei): Make pathlen be of type size_t.
llseek.c: Always #include stdlib.h since it's need to define
size_t.
io.h: Use errcode_t for magic numbers.
icount.c (get_icount_el), dupfs.c (ext2fs_dup_handle), dblist.c
(dir_block_cmp): Use size_t where appropriate.
read_bb.c (ext2fs_read_bb_inode), cmp_bitmaps.c
(ext2fs_compare_inode_bitmap): Use blk_t, ino_t and size_t
where appropriate.
closefs.c (ext2fs_flush): Use dgrp_t instead of int where
appropriate.
openfs.c (ext2fs_open), check_desc.c (ext2fs_check_desc): Use blk_t
instead of int where appropriate.
rw_bitmaps.c (read_bitmaps), irel_ma.c, inode.c (ext2fs_write_inode),
initialize.c (ext2fs_initialize): brel_ma.c: Fix to make be
16-bit safe.
link.c (ext2fs_link), unlink.c (ext2fs_unlink), lookup.c (lookup_proc),
ismounted.c (ext2fs_check_if_mounted), block.c (xlate_func):
Add #pragma argsused for Turbo C.
1997-08-12 00:29:22 +04:00
|
|
|
#ifdef __TURBOC__
|
|
|
|
#pragma argsused
|
|
|
|
#endif
|
1997-04-26 17:21:57 +04:00
|
|
|
static int mark_bad_block(ext2_filsys fs, blk_t *block_nr,
|
|
|
|
int blockcnt, void *private)
|
|
|
|
{
|
|
|
|
struct read_bb_record *rb = (struct read_bb_record *) private;
|
|
|
|
|
|
|
|
if (blockcnt < 0)
|
|
|
|
return 0;
|
|
|
|
|
1997-04-29 20:17:09 +04:00
|
|
|
rb->err = ext2fs_badblocks_list_add(rb->bb_list, *block_nr);
|
1997-04-26 17:21:57 +04:00
|
|
|
if (rb->err)
|
|
|
|
return BLOCK_ABORT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reads the current bad blocks from the bad blocks inode.
|
|
|
|
*/
|
1997-04-29 20:17:09 +04:00
|
|
|
errcode_t ext2fs_read_bb_inode(ext2_filsys fs, ext2_badblocks_list *bb_list)
|
1997-04-26 17:21:57 +04:00
|
|
|
{
|
|
|
|
errcode_t retval;
|
|
|
|
struct read_bb_record rb;
|
|
|
|
struct ext2_inode inode;
|
Many files:
dosio.c: New file to do DOS/BIOS disk accesses.
namei.c (open_namei): Make pathlen be of type size_t.
llseek.c: Always #include stdlib.h since it's need to define
size_t.
io.h: Use errcode_t for magic numbers.
icount.c (get_icount_el), dupfs.c (ext2fs_dup_handle), dblist.c
(dir_block_cmp): Use size_t where appropriate.
read_bb.c (ext2fs_read_bb_inode), cmp_bitmaps.c
(ext2fs_compare_inode_bitmap): Use blk_t, ino_t and size_t
where appropriate.
closefs.c (ext2fs_flush): Use dgrp_t instead of int where
appropriate.
openfs.c (ext2fs_open), check_desc.c (ext2fs_check_desc): Use blk_t
instead of int where appropriate.
rw_bitmaps.c (read_bitmaps), irel_ma.c, inode.c (ext2fs_write_inode),
initialize.c (ext2fs_initialize): brel_ma.c: Fix to make be
16-bit safe.
link.c (ext2fs_link), unlink.c (ext2fs_unlink), lookup.c (lookup_proc),
ismounted.c (ext2fs_check_if_mounted), block.c (xlate_func):
Add #pragma argsused for Turbo C.
1997-08-12 00:29:22 +04:00
|
|
|
blk_t numblocks;
|
1997-04-26 17:21:57 +04:00
|
|
|
|
1997-04-26 17:34:30 +04:00
|
|
|
EXT2_CHECK_MAGIC(fs, EXT2_ET_MAGIC_EXT2FS_FILSYS);
|
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
if (!*bb_list) {
|
|
|
|
retval = ext2fs_read_inode(fs, EXT2_BAD_INO, &inode);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
numblocks = (inode.i_blocks / (fs->blocksize / 512)) + 20;
|
1997-04-29 20:17:09 +04:00
|
|
|
retval = ext2fs_badblocks_list_create(bb_list, numblocks);
|
1997-04-26 17:21:57 +04:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb.bb_list = *bb_list;
|
|
|
|
rb.err = 0;
|
|
|
|
retval = ext2fs_block_iterate(fs, EXT2_BAD_INO, 0, 0,
|
|
|
|
mark_bad_block, &rb);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
|
|
|
|
return rb.err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|