1997-04-26 17:21:57 +04:00
|
|
|
/*
|
|
|
|
* bb_inode.c --- routines to update the bad block inode.
|
2008-08-28 07:07:54 +04:00
|
|
|
*
|
1997-04-26 17:21:57 +04:00
|
|
|
* WARNING: This routine modifies a lot of state in the filesystem; if
|
|
|
|
* this routine returns an error, the bad block inode may be in an
|
|
|
|
* inconsistent state.
|
2008-08-28 07:07:54 +04:00
|
|
|
*
|
1997-04-29 20:15:03 +04:00
|
|
|
* Copyright (C) 1994, 1995 Theodore Ts'o.
|
2008-08-28 07:07:54 +04:00
|
|
|
*
|
1997-04-29 20:15:03 +04:00
|
|
|
* %Begin-Header%
|
2010-05-18 05:31:56 +04:00
|
|
|
* This file may be redistributed under the terms of the GNU Library
|
|
|
|
* General Public License, version 2.
|
1997-04-29 20:15:03 +04:00
|
|
|
* %End-Header%
|
1997-04-26 17:21:57 +04:00
|
|
|
*/
|
|
|
|
|
2011-09-19 01:34:37 +04:00
|
|
|
#include "config.h"
|
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
|
|
|
|
Many files:
inode.c (ext2fs_open_inode_scan): Initialize the group variables
so that we don't need to call get_next_blockgroup() the first
time around. Saves a bit of time, and prevents us from
needing to assign -1 to current_group (which is an unsigned
value).
icount.c (insert_icount_el): Cast the estimated number of inodes
from a float to an ino_t.
alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c,
bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c,
check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c,
dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c,
ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c,
icount.c, initialize.c, inline.c, inode.c, irel_ma.c,
ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c,
newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c,
rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c,
tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c,
version.c: If EXT2_FLAT_INCLUDES is defined, then assume all
of the ext2-specific header files are in a flat directory.
block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast
all assignments from void * to be compatible with C++.
closefs.c (ext2fs_flush): Add a call to io_channel_flush() to
make sure the contents of the disk are flushed to disk.
dblist.c (ext2fs_add_dir_block): Change new to be new_entry to
avoid C++ namespace clash.
bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to
avoid C++ namespace clash.
ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c,
irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c,
ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c,
unlink.c: Change private to be priv_data (to avoid C++
namespace clash)
1998-01-19 17:47:53 +03:00
|
|
|
#include "ext2_fs.h"
|
1997-04-26 17:21:57 +04:00
|
|
|
#include "ext2fs.h"
|
|
|
|
|
|
|
|
struct set_badblock_record {
|
1997-04-29 20:15:03 +04:00
|
|
|
ext2_badblocks_iterate bb_iter;
|
1997-04-26 17:21:57 +04:00
|
|
|
int bad_block_count;
|
|
|
|
blk_t *ind_blocks;
|
|
|
|
int max_ind_blocks;
|
|
|
|
int ind_blocks_size;
|
|
|
|
int ind_blocks_ptr;
|
|
|
|
char *block_buf;
|
|
|
|
errcode_t err;
|
|
|
|
};
|
|
|
|
|
Many files:
block.c (ext2fs_block_iterate3): Make the ref_offset field contain the
offset into the inode.i_blocks array when ref_block is zero. Since we
haven't done a formal release of e2fsprogs since block_iterate2 was
first introduced, I removed block_iterate2, and renamed block_iterate3
to be block_iterate2.
bb_inode.c, bmove.c, dblist_dir.c, dir_iterate.c, expanddir.c,
ext2fs.h, ext2fsP.h, read_bb.c: Change use of block_iterate and
block_iterate2 to block_iterate2 with the new prototype for the
interator function. (using blkcnt_t forr blockcount)
ChangeLog, debugfs.c, ls.c, lsdel.c:
debugfs.c, ls.c, lsdel.c: Add support for large files. (The high 32
bits share space with the i_dir_acl field.)
1998-03-24 19:17:51 +03:00
|
|
|
static int set_bad_block_proc(ext2_filsys fs, blk_t *block_nr,
|
1998-06-11 00:39:43 +04:00
|
|
|
e2_blkcnt_t blockcnt,
|
Many files:
inode.c (ext2fs_open_inode_scan): Initialize the group variables
so that we don't need to call get_next_blockgroup() the first
time around. Saves a bit of time, and prevents us from
needing to assign -1 to current_group (which is an unsigned
value).
icount.c (insert_icount_el): Cast the estimated number of inodes
from a float to an ino_t.
alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c,
bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c,
check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c,
dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c,
ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c,
icount.c, initialize.c, inline.c, inode.c, irel_ma.c,
ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c,
newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c,
rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c,
tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c,
version.c: If EXT2_FLAT_INCLUDES is defined, then assume all
of the ext2-specific header files are in a flat directory.
block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast
all assignments from void * to be compatible with C++.
closefs.c (ext2fs_flush): Add a call to io_channel_flush() to
make sure the contents of the disk are flushed to disk.
dblist.c (ext2fs_add_dir_block): Change new to be new_entry to
avoid C++ namespace clash.
bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to
avoid C++ namespace clash.
ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c,
irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c,
ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c,
unlink.c: Change private to be priv_data (to avoid C++
namespace clash)
1998-01-19 17:47:53 +03:00
|
|
|
blk_t ref_block, int ref_offset,
|
|
|
|
void *priv_data);
|
Many files:
block.c (ext2fs_block_iterate3): Make the ref_offset field contain the
offset into the inode.i_blocks array when ref_block is zero. Since we
haven't done a formal release of e2fsprogs since block_iterate2 was
first introduced, I removed block_iterate2, and renamed block_iterate3
to be block_iterate2.
bb_inode.c, bmove.c, dblist_dir.c, dir_iterate.c, expanddir.c,
ext2fs.h, ext2fsP.h, read_bb.c: Change use of block_iterate and
block_iterate2 to block_iterate2 with the new prototype for the
interator function. (using blkcnt_t forr blockcount)
ChangeLog, debugfs.c, ls.c, lsdel.c:
debugfs.c, ls.c, lsdel.c: Add support for large files. (The high 32
bits share space with the i_dir_acl field.)
1998-03-24 19:17:51 +03:00
|
|
|
static int clear_bad_block_proc(ext2_filsys fs, blk_t *block_nr,
|
1998-06-11 00:39:43 +04:00
|
|
|
e2_blkcnt_t blockcnt,
|
1997-04-29 20:15:03 +04:00
|
|
|
blk_t ref_block, int ref_offset,
|
Many files:
inode.c (ext2fs_open_inode_scan): Initialize the group variables
so that we don't need to call get_next_blockgroup() the first
time around. Saves a bit of time, and prevents us from
needing to assign -1 to current_group (which is an unsigned
value).
icount.c (insert_icount_el): Cast the estimated number of inodes
from a float to an ino_t.
alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c,
bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c,
check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c,
dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c,
ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c,
icount.c, initialize.c, inline.c, inode.c, irel_ma.c,
ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c,
newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c,
rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c,
tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c,
version.c: If EXT2_FLAT_INCLUDES is defined, then assume all
of the ext2-specific header files are in a flat directory.
block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast
all assignments from void * to be compatible with C++.
closefs.c (ext2fs_flush): Add a call to io_channel_flush() to
make sure the contents of the disk are flushed to disk.
dblist.c (ext2fs_add_dir_block): Change new to be new_entry to
avoid C++ namespace clash.
bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to
avoid C++ namespace clash.
ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c,
irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c,
ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c,
unlink.c: Change private to be priv_data (to avoid C++
namespace clash)
1998-01-19 17:47:53 +03:00
|
|
|
void *priv_data);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
/*
|
|
|
|
* Given a bad blocks bitmap, update the bad blocks inode to reflect
|
|
|
|
* the map.
|
|
|
|
*/
|
1997-04-29 20:15:03 +04:00
|
|
|
errcode_t ext2fs_update_bb_inode(ext2_filsys fs, ext2_badblocks_list bb_list)
|
1997-04-26 17:21:57 +04:00
|
|
|
{
|
|
|
|
errcode_t retval;
|
|
|
|
struct set_badblock_record rec;
|
|
|
|
struct ext2_inode inode;
|
2008-08-28 07:07:54 +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 (!fs->block_map)
|
|
|
|
return EXT2_ET_NO_BLOCK_BITMAP;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2010-12-20 18:57:29 +03:00
|
|
|
memset(&rec, 0, sizeof(rec));
|
1997-04-26 17:21:57 +04:00
|
|
|
rec.max_ind_blocks = 10;
|
2007-11-10 03:01:06 +03:00
|
|
|
retval = ext2fs_get_array(rec.max_ind_blocks, sizeof(blk_t),
|
2003-08-01 17:41:07 +04:00
|
|
|
&rec.ind_blocks);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
1997-04-26 17:21:57 +04:00
|
|
|
memset(rec.ind_blocks, 0, rec.max_ind_blocks * sizeof(blk_t));
|
2003-08-01 17:41:07 +04:00
|
|
|
retval = ext2fs_get_mem(fs->blocksize, &rec.block_buf);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval)
|
1997-04-26 17:21:57 +04:00
|
|
|
goto cleanup;
|
|
|
|
memset(rec.block_buf, 0, fs->blocksize);
|
|
|
|
rec.err = 0;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
/*
|
2008-08-28 07:07:54 +04:00
|
|
|
* First clear the old bad blocks (while saving the indirect blocks)
|
1997-04-26 17:21:57 +04:00
|
|
|
*/
|
1997-04-29 20:15:03 +04:00
|
|
|
retval = ext2fs_block_iterate2(fs, EXT2_BAD_INO,
|
|
|
|
BLOCK_FLAG_DEPTH_TRAVERSE, 0,
|
|
|
|
clear_bad_block_proc, &rec);
|
1997-04-26 17:21:57 +04:00
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
|
|
|
if (rec.err) {
|
|
|
|
retval = rec.err;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
/*
|
|
|
|
* Now set the bad blocks!
|
1997-04-26 17:34:30 +04:00
|
|
|
*
|
|
|
|
* First, mark the bad blocks as used. This prevents a bad
|
|
|
|
* block from being used as an indirecto block for the bad
|
|
|
|
* block inode (!).
|
1997-04-26 17:21:57 +04:00
|
|
|
*/
|
|
|
|
if (bb_list) {
|
1997-04-29 20:15:03 +04:00
|
|
|
retval = ext2fs_badblocks_list_iterate_begin(bb_list,
|
|
|
|
&rec.bb_iter);
|
1997-04-26 17:21:57 +04:00
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
1997-04-29 20:15:03 +04:00
|
|
|
retval = ext2fs_block_iterate2(fs, EXT2_BAD_INO,
|
|
|
|
BLOCK_FLAG_APPEND, 0,
|
|
|
|
set_bad_block_proc, &rec);
|
|
|
|
ext2fs_badblocks_list_iterate_end(rec.bb_iter);
|
2008-08-28 07:07:54 +04:00
|
|
|
if (retval)
|
1997-04-26 17:21:57 +04:00
|
|
|
goto cleanup;
|
|
|
|
if (rec.err) {
|
|
|
|
retval = rec.err;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
/*
|
|
|
|
* Update the bad block inode's mod time and block count
|
2008-08-28 07:07:54 +04:00
|
|
|
* field.
|
1997-04-26 17:21:57 +04:00
|
|
|
*/
|
|
|
|
retval = ext2fs_read_inode(fs, EXT2_BAD_INO, &inode);
|
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
2005-09-25 04:14:51 +04:00
|
|
|
inode.i_atime = inode.i_mtime = fs->now ? fs->now : time(0);
|
1997-04-26 17:21:57 +04:00
|
|
|
if (!inode.i_ctime)
|
2005-09-25 04:14:51 +04:00
|
|
|
inode.i_ctime = fs->now ? fs->now : time(0);
|
2008-04-09 19:39:11 +04:00
|
|
|
ext2fs_iblk_set(fs, &inode, rec.bad_block_count);
|
1997-04-26 17:21:57 +04:00
|
|
|
inode.i_size = rec.bad_block_count * fs->blocksize;
|
|
|
|
|
|
|
|
retval = ext2fs_write_inode(fs, EXT2_BAD_INO, &inode);
|
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
cleanup:
|
2003-08-01 17:41:07 +04:00
|
|
|
ext2fs_free_mem(&rec.ind_blocks);
|
|
|
|
ext2fs_free_mem(&rec.block_buf);
|
1997-04-26 17:21:57 +04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Helper function for update_bb_inode()
|
|
|
|
*
|
|
|
|
* Clear the bad blocks in the bad block inode, while saving the
|
|
|
|
* indirect blocks.
|
|
|
|
*/
|
1997-08-11 03:07:40 +04:00
|
|
|
#ifdef __TURBOC__
|
Many files:
alloc.c, bb_inode.c, bitmaps.c, bitops.h, block.c, bmap.c, bmove.c,
brel.h, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c,
expanddir.c, ext2fs.h, ext2fsP.h, fileio.c, finddev.c, get_pathname.c,
icount.c, inode.c, irel.h, irel_ma.c, ismounted.c, link.c, lookup.c,
mkdir.c, mkjournal.c, namei.c, newdir.c, read_bb_file.c, test_io.c,
tst_iscan.c, unix_io.c, unlink.c: Change use of ino_t to ext2_ino_t,
to protect applications that attempt to compile
-D_FILE_OFFSET_BITS=64, since this inexplicably changes ino_t(!?). So
we use ext2_ino_t to avoid an unexpected ABI change.
2001-01-11 07:54:39 +03:00
|
|
|
#pragma argsused
|
1997-08-11 03:07:40 +04:00
|
|
|
#endif
|
Many files:
block.c (ext2fs_block_iterate3): Make the ref_offset field contain the
offset into the inode.i_blocks array when ref_block is zero. Since we
haven't done a formal release of e2fsprogs since block_iterate2 was
first introduced, I removed block_iterate2, and renamed block_iterate3
to be block_iterate2.
bb_inode.c, bmove.c, dblist_dir.c, dir_iterate.c, expanddir.c,
ext2fs.h, ext2fsP.h, read_bb.c: Change use of block_iterate and
block_iterate2 to block_iterate2 with the new prototype for the
interator function. (using blkcnt_t forr blockcount)
ChangeLog, debugfs.c, ls.c, lsdel.c:
debugfs.c, ls.c, lsdel.c: Add support for large files. (The high 32
bits share space with the i_dir_acl field.)
1998-03-24 19:17:51 +03:00
|
|
|
static int clear_bad_block_proc(ext2_filsys fs, blk_t *block_nr,
|
1998-06-11 00:39:43 +04:00
|
|
|
e2_blkcnt_t blockcnt,
|
2003-12-07 09:28:50 +03:00
|
|
|
blk_t ref_block EXT2FS_ATTR((unused)),
|
|
|
|
int ref_offset EXT2FS_ATTR((unused)),
|
Many files:
inode.c (ext2fs_open_inode_scan): Initialize the group variables
so that we don't need to call get_next_blockgroup() the first
time around. Saves a bit of time, and prevents us from
needing to assign -1 to current_group (which is an unsigned
value).
icount.c (insert_icount_el): Cast the estimated number of inodes
from a float to an ino_t.
alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c,
bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c,
check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c,
dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c,
ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c,
icount.c, initialize.c, inline.c, inode.c, irel_ma.c,
ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c,
newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c,
rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c,
tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c,
version.c: If EXT2_FLAT_INCLUDES is defined, then assume all
of the ext2-specific header files are in a flat directory.
block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast
all assignments from void * to be compatible with C++.
closefs.c (ext2fs_flush): Add a call to io_channel_flush() to
make sure the contents of the disk are flushed to disk.
dblist.c (ext2fs_add_dir_block): Change new to be new_entry to
avoid C++ namespace clash.
bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to
avoid C++ namespace clash.
ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c,
irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c,
ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c,
unlink.c: Change private to be priv_data (to avoid C++
namespace clash)
1998-01-19 17:47:53 +03:00
|
|
|
void *priv_data)
|
1997-04-26 17:21:57 +04:00
|
|
|
{
|
|
|
|
struct set_badblock_record *rec = (struct set_badblock_record *)
|
Many files:
inode.c (ext2fs_open_inode_scan): Initialize the group variables
so that we don't need to call get_next_blockgroup() the first
time around. Saves a bit of time, and prevents us from
needing to assign -1 to current_group (which is an unsigned
value).
icount.c (insert_icount_el): Cast the estimated number of inodes
from a float to an ino_t.
alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c,
bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c,
check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c,
dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c,
ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c,
icount.c, initialize.c, inline.c, inode.c, irel_ma.c,
ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c,
newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c,
rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c,
tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c,
version.c: If EXT2_FLAT_INCLUDES is defined, then assume all
of the ext2-specific header files are in a flat directory.
block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast
all assignments from void * to be compatible with C++.
closefs.c (ext2fs_flush): Add a call to io_channel_flush() to
make sure the contents of the disk are flushed to disk.
dblist.c (ext2fs_add_dir_block): Change new to be new_entry to
avoid C++ namespace clash.
bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to
avoid C++ namespace clash.
ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c,
irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c,
ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c,
unlink.c: Change private to be priv_data (to avoid C++
namespace clash)
1998-01-19 17:47:53 +03:00
|
|
|
priv_data;
|
1997-10-26 06:41:24 +03:00
|
|
|
errcode_t retval;
|
1998-04-27 05:41:13 +04:00
|
|
|
unsigned long old_size;
|
1997-04-26 17:21:57 +04:00
|
|
|
|
|
|
|
if (!*block_nr)
|
|
|
|
return 0;
|
|
|
|
|
1997-04-26 17:34:30 +04:00
|
|
|
/*
|
|
|
|
* If the block number is outrageous, clear it and ignore it.
|
|
|
|
*/
|
2009-09-08 04:46:34 +04:00
|
|
|
if (*block_nr >= ext2fs_blocks_count(fs->super) ||
|
1997-04-26 17:34:30 +04:00
|
|
|
*block_nr < fs->super->s_first_data_block) {
|
|
|
|
*block_nr = 0;
|
|
|
|
return BLOCK_CHANGED;
|
|
|
|
}
|
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
if (blockcnt < 0) {
|
|
|
|
if (rec->ind_blocks_size >= rec->max_ind_blocks) {
|
1998-04-27 05:41:13 +04:00
|
|
|
old_size = rec->max_ind_blocks * sizeof(blk_t);
|
1997-04-26 17:21:57 +04:00
|
|
|
rec->max_ind_blocks += 10;
|
2008-08-28 07:07:54 +04:00
|
|
|
retval = ext2fs_resize_mem(old_size,
|
1998-04-27 05:41:13 +04:00
|
|
|
rec->max_ind_blocks * sizeof(blk_t),
|
2003-08-01 17:41:07 +04:00
|
|
|
&rec->ind_blocks);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval) {
|
1998-04-27 05:41:13 +04:00
|
|
|
rec->max_ind_blocks -= 10;
|
1997-10-26 06:41:24 +03:00
|
|
|
rec->err = retval;
|
1997-04-26 17:21:57 +04:00
|
|
|
return BLOCK_ABORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
rec->ind_blocks[rec->ind_blocks_size++] = *block_nr;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark the block as unused, and update accounting information
|
|
|
|
*/
|
2009-10-26 04:46:58 +03:00
|
|
|
ext2fs_block_alloc_stats2(fs, *block_nr, -1);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
*block_nr = 0;
|
|
|
|
return BLOCK_CHANGED;
|
|
|
|
}
|
|
|
|
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
/*
|
|
|
|
* Helper function for update_bb_inode()
|
|
|
|
*
|
|
|
|
* Set the block list in the bad block inode, using the supplied bitmap.
|
|
|
|
*/
|
1997-08-11 03:07:40 +04:00
|
|
|
#ifdef __TURBOC__
|
Many files:
alloc.c, bb_inode.c, bitmaps.c, bitops.h, block.c, bmap.c, bmove.c,
brel.h, cmp_bitmaps.c, dblist.c, dblist_dir.c, dir_iterate.c,
expanddir.c, ext2fs.h, ext2fsP.h, fileio.c, finddev.c, get_pathname.c,
icount.c, inode.c, irel.h, irel_ma.c, ismounted.c, link.c, lookup.c,
mkdir.c, mkjournal.c, namei.c, newdir.c, read_bb_file.c, test_io.c,
tst_iscan.c, unix_io.c, unlink.c: Change use of ino_t to ext2_ino_t,
to protect applications that attempt to compile
-D_FILE_OFFSET_BITS=64, since this inexplicably changes ino_t(!?). So
we use ext2_ino_t to avoid an unexpected ABI change.
2001-01-11 07:54:39 +03:00
|
|
|
#pragma argsused
|
1997-08-11 03:07:40 +04:00
|
|
|
#endif
|
1997-04-26 17:21:57 +04:00
|
|
|
static int set_bad_block_proc(ext2_filsys fs, blk_t *block_nr,
|
2003-12-07 09:28:50 +03:00
|
|
|
e2_blkcnt_t blockcnt,
|
|
|
|
blk_t ref_block EXT2FS_ATTR((unused)),
|
|
|
|
int ref_offset EXT2FS_ATTR((unused)),
|
|
|
|
void *priv_data)
|
1997-04-26 17:21:57 +04:00
|
|
|
{
|
|
|
|
struct set_badblock_record *rec = (struct set_badblock_record *)
|
Many files:
inode.c (ext2fs_open_inode_scan): Initialize the group variables
so that we don't need to call get_next_blockgroup() the first
time around. Saves a bit of time, and prevents us from
needing to assign -1 to current_group (which is an unsigned
value).
icount.c (insert_icount_el): Cast the estimated number of inodes
from a float to an ino_t.
alloc.c, alloc_tables.c, badlbocks.c, bb_compat.c, bb_inode.c,
bitmaps.c, bitops.c, block.c, bmap.c, bmove.c, brel_ma.c,
check_desc.c, closefs.c, cmp_bitmaps.c, dblist.c,
dblist_dir.c, dir_iterate.c, dirblock.c, dupfs.c, expanddir.c,
ext2fs.h, fileio.c, freefs.c, get_pathname.c, getsize.c,
icount.c, initialize.c, inline.c, inode.c, irel_ma.c,
ismounted.c, link.c, lookup.c, mkdir.c, namei.c, native.c,
newdir.c, openfs.c, read_bb.c, read_bb_file.c, rs_bitmap.c,
rw_bitmaps.c, swapfs.c, test_io.c, tst_badblocks.c,
tst_getsize.c, tst_iscan.c, unix_io.c, unlink.c, valid_blk.c,
version.c: If EXT2_FLAT_INCLUDES is defined, then assume all
of the ext2-specific header files are in a flat directory.
block.c, bmove.c, dirblock.c, fileio.c: Explicitly cast
all assignments from void * to be compatible with C++.
closefs.c (ext2fs_flush): Add a call to io_channel_flush() to
make sure the contents of the disk are flushed to disk.
dblist.c (ext2fs_add_dir_block): Change new to be new_entry to
avoid C++ namespace clash.
bitmaps.c (ext2fs_copy_bitmap): Change new to be new_map to
avoid C++ namespace clash.
ext2fs.h, bb_inode.c, block.c, bmove.c, brel.h, brel_ma.c,
irel.h, irel_ma.c, dblist.c, dblist_dir.c, dir_iterate.c,
ext2fsP.h, expanddir.c, get_pathname.c, inode.c, link.c,
unlink.c: Change private to be priv_data (to avoid C++
namespace clash)
1998-01-19 17:47:53 +03:00
|
|
|
priv_data;
|
1997-04-26 17:21:57 +04:00
|
|
|
errcode_t retval;
|
|
|
|
blk_t blk;
|
|
|
|
|
|
|
|
if (blockcnt >= 0) {
|
|
|
|
/*
|
|
|
|
* Get the next bad block.
|
|
|
|
*/
|
1997-04-29 20:15:03 +04:00
|
|
|
if (!ext2fs_badblocks_list_iterate(rec->bb_iter, &blk))
|
1997-04-26 17:21:57 +04:00
|
|
|
return BLOCK_ABORT;
|
|
|
|
rec->bad_block_count++;
|
1997-04-26 17:34:30 +04:00
|
|
|
} else {
|
1997-04-26 17:21:57 +04:00
|
|
|
/*
|
|
|
|
* An indirect block; fetch a block from the
|
1997-04-26 17:34:30 +04:00
|
|
|
* previously used indirect block list. The block
|
|
|
|
* most be not marked as used; if so, get another one.
|
|
|
|
* If we run out of reserved indirect blocks, allocate
|
|
|
|
* a new one.
|
1997-04-26 17:21:57 +04:00
|
|
|
*/
|
1997-04-26 17:34:30 +04:00
|
|
|
retry:
|
|
|
|
if (rec->ind_blocks_ptr < rec->ind_blocks_size) {
|
|
|
|
blk = rec->ind_blocks[rec->ind_blocks_ptr++];
|
2009-08-05 08:27:10 +04:00
|
|
|
if (ext2fs_test_block_bitmap2(fs->block_map, blk))
|
1997-04-26 17:34:30 +04:00
|
|
|
goto retry;
|
|
|
|
} else {
|
|
|
|
retval = ext2fs_new_block(fs, 0, 0, &blk);
|
|
|
|
if (retval) {
|
|
|
|
rec->err = retval;
|
|
|
|
return BLOCK_ABORT;
|
|
|
|
}
|
1997-04-26 17:21:57 +04:00
|
|
|
}
|
2009-09-08 05:14:24 +04:00
|
|
|
retval = io_channel_write_blk64(fs->io, blk, 1, rec->block_buf);
|
1997-04-26 17:21:57 +04:00
|
|
|
if (retval) {
|
|
|
|
rec->err = retval;
|
|
|
|
return BLOCK_ABORT;
|
|
|
|
}
|
|
|
|
}
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
/*
|
1997-04-26 17:34:30 +04:00
|
|
|
* Update block counts
|
1997-04-26 17:21:57 +04:00
|
|
|
*/
|
2009-10-26 04:46:58 +03:00
|
|
|
ext2fs_block_alloc_stats2(fs, blk, +1);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
*block_nr = blk;
|
|
|
|
return BLOCK_CHANGED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|