1997-04-26 17:21:57 +04:00
|
|
|
/*
|
|
|
|
* openfs.c --- open an ext2 filesystem
|
|
|
|
*
|
1997-04-29 20:17:09 +04:00
|
|
|
* Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o.
|
1997-04-26 17:58:21 +04:00
|
|
|
*
|
1997-04-29 20:17:09 +04:00
|
|
|
* %Begin-Header%
|
1997-04-26 17:58:21 +04:00
|
|
|
* This file may be redistributed under the terms of the GNU Public
|
|
|
|
* License.
|
1997-04-29 20:17:09 +04:00
|
|
|
* %End-Header%
|
1997-04-26 17:21:57 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1997-04-26 17:58:21 +04:00
|
|
|
#if HAVE_UNISTD_H
|
1997-04-26 17:21:57 +04:00
|
|
|
#include <unistd.h>
|
1997-04-26 17:58:21 +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"
|
2002-10-20 08:38:57 +04:00
|
|
|
|
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
#include "ext2fs.h"
|
2001-05-03 08:02:29 +04:00
|
|
|
#include "e2image.h"
|
1997-04-26 17:21:57 +04:00
|
|
|
|
2002-10-20 08:38:57 +04:00
|
|
|
blk_t ext2fs_descriptor_block_loc(ext2_filsys fs, blk_t group_block, dgrp_t i)
|
|
|
|
{
|
|
|
|
int bg;
|
|
|
|
int has_super = 0;
|
2002-10-31 19:45:06 +03:00
|
|
|
int ret_blk;
|
2002-10-20 08:38:57 +04:00
|
|
|
|
|
|
|
if (!(fs->super->s_feature_incompat & EXT2_FEATURE_INCOMPAT_META_BG) ||
|
|
|
|
(i < fs->super->s_first_meta_bg))
|
|
|
|
return (group_block + i + 1);
|
|
|
|
|
2007-08-30 19:38:13 +04:00
|
|
|
bg = EXT2_DESC_PER_BLOCK(fs->super) * i;
|
2002-10-20 08:38:57 +04:00
|
|
|
if (ext2fs_bg_has_super(fs, bg))
|
|
|
|
has_super = 1;
|
2007-08-30 19:31:36 +04:00
|
|
|
ret_blk = ext2fs_group_first_block(fs, bg) + has_super;
|
2002-10-31 19:45:06 +03:00
|
|
|
/*
|
|
|
|
* If group_block is not the normal value, we're trying to use
|
|
|
|
* the backup group descriptors and superblock --- so use the
|
|
|
|
* alternate location of the second block group in the
|
|
|
|
* metablock group. Ideally we should be testing each bg
|
|
|
|
* descriptor block individually for correctness, but we don't
|
|
|
|
* have the infrastructure in place to do that.
|
|
|
|
*/
|
|
|
|
if (group_block != fs->super->s_first_data_block &&
|
|
|
|
((ret_blk + fs->super->s_blocks_per_group) <
|
|
|
|
fs->super->s_blocks_count))
|
|
|
|
ret_blk += fs->super->s_blocks_per_group;
|
|
|
|
return ret_blk;
|
2002-10-20 08:38:57 +04:00
|
|
|
}
|
|
|
|
|
2004-11-30 22:07:11 +03:00
|
|
|
errcode_t ext2fs_open(const char *name, int flags, int superblock,
|
|
|
|
unsigned int block_size, io_manager manager,
|
|
|
|
ext2_filsys *ret_fs)
|
|
|
|
{
|
|
|
|
return ext2fs_open2(name, 0, flags, superblock, block_size,
|
|
|
|
manager, ret_fs);
|
|
|
|
}
|
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
/*
|
|
|
|
* Note: if superblock is non-zero, block-size must also be non-zero.
|
|
|
|
* Superblock and block_size can be zero to use the default size.
|
1997-04-29 20:17:09 +04:00
|
|
|
*
|
|
|
|
* Valid flags for ext2fs_open()
|
|
|
|
*
|
|
|
|
* EXT2_FLAG_RW - Open the filesystem for read/write.
|
|
|
|
* EXT2_FLAG_FORCE - Open the filesystem even if some of the
|
2001-05-14 03:12:10 +04:00
|
|
|
* features aren't supported.
|
|
|
|
* EXT2_FLAG_JOURNAL_DEV_OK - Open an ext3 journal device
|
1997-04-26 17:21:57 +04:00
|
|
|
*/
|
2004-11-30 22:07:11 +03:00
|
|
|
errcode_t ext2fs_open2(const char *name, const char *io_options,
|
|
|
|
int flags, int superblock,
|
|
|
|
unsigned int block_size, io_manager manager,
|
|
|
|
ext2_filsys *ret_fs)
|
1997-04-26 17:21:57 +04:00
|
|
|
{
|
|
|
|
ext2_filsys fs;
|
|
|
|
errcode_t retval;
|
2003-12-07 09:28:50 +03:00
|
|
|
unsigned long i;
|
2006-11-13 07:26:46 +03:00
|
|
|
__u32 features;
|
2008-03-18 06:17:13 +03:00
|
|
|
int groups_per_block, blocks_per_group, io_flags;
|
2002-10-20 08:38:57 +04:00
|
|
|
blk_t group_block, blk;
|
2004-11-30 22:07:11 +03:00
|
|
|
char *dest, *cp;
|
2008-03-18 06:17:13 +03:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
1997-04-26 17:58:21 +04:00
|
|
|
struct ext2_group_desc *gdp;
|
2008-03-18 06:17:13 +03:00
|
|
|
int j;
|
|
|
|
#endif
|
1997-04-26 17:21:57 +04:00
|
|
|
|
1997-04-26 17:34:30 +04:00
|
|
|
EXT2_CHECK_MAGIC(manager, EXT2_ET_MAGIC_IO_MANAGER);
|
1997-10-26 06:41:24 +03:00
|
|
|
|
2003-08-01 17:41:07 +04:00
|
|
|
retval = ext2fs_get_mem(sizeof(struct struct_ext2_filsys), &fs);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval)
|
|
|
|
return retval;
|
1997-04-26 17:21:57 +04:00
|
|
|
|
|
|
|
memset(fs, 0, sizeof(struct struct_ext2_filsys));
|
1997-04-26 17:34:30 +04:00
|
|
|
fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS;
|
1997-04-26 17:21:57 +04:00
|
|
|
fs->flags = flags;
|
2007-06-19 02:26:50 +04:00
|
|
|
/* don't overwrite sb backups unless flag is explicitly cleared */
|
|
|
|
fs->flags |= EXT2_FLAG_MASTER_SB_ONLY;
|
2001-12-24 17:40:00 +03:00
|
|
|
fs->umask = 022;
|
2004-11-30 22:07:11 +03:00
|
|
|
retval = ext2fs_get_mem(strlen(name)+1, &fs->device_name);
|
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
|
|
|
strcpy(fs->device_name, name);
|
|
|
|
cp = strchr(fs->device_name, '?');
|
|
|
|
if (!io_options && cp) {
|
|
|
|
*cp++ = 0;
|
|
|
|
io_options = cp;
|
|
|
|
}
|
|
|
|
|
2006-03-19 03:16:10 +03:00
|
|
|
io_flags = 0;
|
|
|
|
if (flags & EXT2_FLAG_RW)
|
|
|
|
io_flags |= IO_FLAG_RW;
|
|
|
|
if (flags & EXT2_FLAG_EXCLUSIVE)
|
|
|
|
io_flags |= IO_FLAG_EXCLUSIVE;
|
|
|
|
retval = manager->open(fs->device_name, io_flags, &fs->io);
|
1997-04-26 17:21:57 +04:00
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
2004-11-30 22:07:11 +03:00
|
|
|
if (io_options &&
|
|
|
|
(retval = io_channel_set_options(fs->io, io_options)))
|
|
|
|
goto cleanup;
|
2004-07-29 05:11:48 +04:00
|
|
|
fs->image_io = fs->io;
|
1997-08-24 06:57:55 +04:00
|
|
|
fs->io->app_data = fs;
|
2003-08-01 17:41:07 +04:00
|
|
|
retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &fs->super);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval)
|
1997-04-26 17:21:57 +04:00
|
|
|
goto cleanup;
|
2001-05-03 08:02:29 +04:00
|
|
|
if (flags & EXT2_FLAG_IMAGE_FILE) {
|
|
|
|
retval = ext2fs_get_mem(sizeof(struct ext2_image_hdr),
|
2003-08-01 17:41:07 +04:00
|
|
|
&fs->image_header);
|
2001-05-03 08:02:29 +04:00
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
|
|
|
retval = io_channel_read_blk(fs->io, 0,
|
2006-05-22 03:26:45 +04:00
|
|
|
-(int)sizeof(struct ext2_image_hdr),
|
2001-05-03 08:02:29 +04:00
|
|
|
fs->image_header);
|
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
|
|
|
if (fs->image_header->magic_number != EXT2_ET_MAGIC_E2IMAGE)
|
|
|
|
return EXT2_ET_MAGIC_E2IMAGE;
|
|
|
|
superblock = 1;
|
|
|
|
block_size = fs->image_header->fs_blocksize;
|
|
|
|
}
|
1997-04-26 17:21:57 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user specifies a specific block # for the
|
|
|
|
* superblock, then he/she must also specify the block size!
|
|
|
|
* Otherwise, read the master superblock located at offset
|
|
|
|
* SUPERBLOCK_OFFSET from the start of the partition.
|
2000-10-27 00:24:43 +04:00
|
|
|
*
|
|
|
|
* Note: we only save a backup copy of the superblock if we
|
|
|
|
* are reading the superblock from the primary superblock location.
|
1997-04-26 17:21:57 +04:00
|
|
|
*/
|
|
|
|
if (superblock) {
|
|
|
|
if (!block_size) {
|
1997-10-31 09:07:47 +03:00
|
|
|
retval = EXT2_ET_INVALID_ARGUMENT;
|
1997-04-26 17:21:57 +04:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
io_channel_set_blksize(fs->io, block_size);
|
2002-10-31 19:45:06 +03:00
|
|
|
group_block = superblock;
|
2000-10-27 00:24:43 +04:00
|
|
|
fs->orig_super = 0;
|
1997-04-26 17:21:57 +04:00
|
|
|
} else {
|
|
|
|
io_channel_set_blksize(fs->io, SUPERBLOCK_OFFSET);
|
|
|
|
superblock = 1;
|
1997-04-26 17:34:30 +04:00
|
|
|
group_block = 0;
|
2003-08-01 17:41:07 +04:00
|
|
|
retval = ext2fs_get_mem(SUPERBLOCK_SIZE, &fs->orig_super);
|
2000-10-27 00:24:43 +04:00
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
1997-04-26 17:21:57 +04:00
|
|
|
}
|
|
|
|
retval = io_channel_read_blk(fs->io, superblock, -SUPERBLOCK_SIZE,
|
|
|
|
fs->super);
|
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
2000-10-27 00:24:43 +04:00
|
|
|
if (fs->orig_super)
|
|
|
|
memcpy(fs->orig_super, fs->super, SUPERBLOCK_SIZE);
|
1997-04-26 17:58:21 +04:00
|
|
|
|
2007-08-11 09:56:48 +04:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
fs->flags |= EXT2_FLAG_SWAP_BYTES;
|
|
|
|
ext2fs_swap_super(fs->super);
|
|
|
|
#else
|
|
|
|
if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
|
|
|
|
retval = EXT2_ET_UNIMPLEMENTED;
|
|
|
|
goto cleanup;
|
1997-04-26 17:58:21 +04:00
|
|
|
}
|
ChangeLog, Makefile.in, swapfs.c, unix.c:
Makefile.in: Add message.c and swapfs.c to the list of source files to
build the make depend.
swapfs.c, unix.c: Only support the -s and -S options to e2fsck if
ENABLE_SWAPFS is defined.
Many files:
ext2fs.h, bitops.h, block.c, bmap.c, closefs.c, dirblock.c, inode.c,
native.c, openfs.c, rw_bitmaps.c, swapfs.c: Only include the
byte-swapping logic if ENABLE_SWAPFS is turned on or if we're on a
big-endian machine.
initialize.c (ext2fs_initialize):Use WORDS_BIGENDIAN directly to set
EXT2_FLAG_SWAP_BYTES, instead of using ext2fs_native_flag.
native.c (ext2fs_native_flag): Use WORDS_BIGENDIAN provided by
autoconf to determine whether or not return EXT2_FLAG_SWAP_BYTES.
2001-06-11 11:00:04 +04:00
|
|
|
#endif
|
1997-04-26 17:21:57 +04:00
|
|
|
|
|
|
|
if (fs->super->s_magic != EXT2_SUPER_MAGIC) {
|
|
|
|
retval = EXT2_ET_BAD_MAGIC;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
1997-04-26 17:34:30 +04:00
|
|
|
if (fs->super->s_rev_level > EXT2_LIB_CURRENT_REV) {
|
|
|
|
retval = EXT2_ET_REV_TOO_HIGH;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2001-01-01 19:17:12 +03:00
|
|
|
|
1997-04-29 20:17:09 +04:00
|
|
|
/*
|
|
|
|
* Check for feature set incompatibility
|
|
|
|
*/
|
|
|
|
if (!(flags & EXT2_FLAG_FORCE)) {
|
2006-11-13 07:26:46 +03:00
|
|
|
features = fs->super->s_feature_incompat;
|
|
|
|
#ifdef EXT2_LIB_SOFTSUPP_INCOMPAT
|
|
|
|
if (flags & EXT2_FLAG_SOFTSUPP_FEATURES)
|
|
|
|
features &= !EXT2_LIB_SOFTSUPP_INCOMPAT;
|
|
|
|
#endif
|
|
|
|
if (features & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP) {
|
1997-04-29 20:17:09 +04:00
|
|
|
retval = EXT2_ET_UNSUPP_FEATURE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2006-11-13 07:26:46 +03:00
|
|
|
|
|
|
|
features = fs->super->s_feature_ro_compat;
|
|
|
|
#ifdef EXT2_LIB_SOFTSUPP_RO_COMPAT
|
|
|
|
if (flags & EXT2_FLAG_SOFTSUPP_FEATURES)
|
|
|
|
features &= !EXT2_LIB_SOFTSUPP_RO_COMPAT;
|
|
|
|
#endif
|
1997-04-29 20:17:09 +04:00
|
|
|
if ((flags & EXT2_FLAG_RW) &&
|
2006-11-13 07:26:46 +03:00
|
|
|
(features & ~EXT2_LIB_FEATURE_RO_COMPAT_SUPP)) {
|
1997-04-29 20:17:09 +04:00
|
|
|
retval = EXT2_ET_RO_UNSUPP_FEATURE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2006-11-13 07:26:46 +03:00
|
|
|
|
ChangeLog, ext2_err.et.in, ext2fs.h, initialize.c, mkjournal.c, openfs.c:
initialize.c (ext2fs_initialize): Add support for initializing the
ext2 superblock for external journal devices. This basically means we
don't bother to allocate any block group descriptors.
openfs.c (ext2fs_open): Only open external journal devices if the new
flag EXT2_FLAG_JOURNAL_DEV_OK is passed to ext2fs_open. When opening
such devices, don't try to read the block group descriptors, since
they're not there.
ext2_err.et.in (EXT2_NO_JOURNAL_SB): Add new error code
mkjournal.c: Export a new function,
ext2fs_create_journal_superblock(), which allocates and returns a
buffer containing a journal superblock. This is needed by mke2fs to
create an external journal. Rewrote ext2fs_add_journal_device() so
that it no longer creates the external journal, but rather adds a
filesystem to an existing external journal. It handles all of the
UUID manipulation.
ext2fs.h: List the EXT3_FEATURE_JOURNAL_DEV as a flag supported by the
library. Define the EXT2_FLAG_JOURNAL_DEV_OK. Changed function
prototype for ext2fs_add_journal_device().
2001-01-16 09:56:14 +03:00
|
|
|
if (!(flags & EXT2_FLAG_JOURNAL_DEV_OK) &&
|
|
|
|
(fs->super->s_feature_incompat &
|
|
|
|
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV)) {
|
|
|
|
retval = EXT2_ET_UNSUPP_FEATURE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
1997-04-29 20:17:09 +04:00
|
|
|
}
|
|
|
|
|
1997-04-26 17:21:57 +04:00
|
|
|
fs->blocksize = EXT2_BLOCK_SIZE(fs->super);
|
1997-04-29 18:53:37 +04:00
|
|
|
if (fs->blocksize == 0) {
|
|
|
|
retval = EXT2_ET_CORRUPT_SUPERBLOCK;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2007-09-08 00:40:25 +04:00
|
|
|
if (EXT2_INODE_SIZE(fs->super) < EXT2_GOOD_OLD_INODE_SIZE) {
|
|
|
|
retval = EXT2_ET_CORRUPT_SUPERBLOCK;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
1997-04-26 17:21:57 +04:00
|
|
|
fs->fragsize = EXT2_FRAG_SIZE(fs->super);
|
1997-04-26 18:48:50 +04:00
|
|
|
fs->inode_blocks_per_group = ((fs->super->s_inodes_per_group *
|
|
|
|
EXT2_INODE_SIZE(fs->super) +
|
|
|
|
EXT2_BLOCK_SIZE(fs->super) - 1) /
|
|
|
|
EXT2_BLOCK_SIZE(fs->super));
|
1997-04-26 17:21:57 +04:00
|
|
|
if (block_size) {
|
|
|
|
if (block_size != fs->blocksize) {
|
|
|
|
retval = EXT2_ET_UNEXPECTED_BLOCK_SIZE;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Set the blocksize to the filesystem's blocksize.
|
|
|
|
*/
|
|
|
|
io_channel_set_blksize(fs->io, fs->blocksize);
|
ChangeLog, ext2_err.et.in, ext2fs.h, initialize.c, mkjournal.c, openfs.c:
initialize.c (ext2fs_initialize): Add support for initializing the
ext2 superblock for external journal devices. This basically means we
don't bother to allocate any block group descriptors.
openfs.c (ext2fs_open): Only open external journal devices if the new
flag EXT2_FLAG_JOURNAL_DEV_OK is passed to ext2fs_open. When opening
such devices, don't try to read the block group descriptors, since
they're not there.
ext2_err.et.in (EXT2_NO_JOURNAL_SB): Add new error code
mkjournal.c: Export a new function,
ext2fs_create_journal_superblock(), which allocates and returns a
buffer containing a journal superblock. This is needed by mke2fs to
create an external journal. Rewrote ext2fs_add_journal_device() so
that it no longer creates the external journal, but rather adds a
filesystem to an existing external journal. It handles all of the
UUID manipulation.
ext2fs.h: List the EXT3_FEATURE_JOURNAL_DEV as a flag supported by the
library. Define the EXT2_FLAG_JOURNAL_DEV_OK. Changed function
prototype for ext2fs_add_journal_device().
2001-01-16 09:56:14 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is an external journal device, don't try to read
|
|
|
|
* the group descriptors, because they're not there.
|
|
|
|
*/
|
|
|
|
if (fs->super->s_feature_incompat &
|
|
|
|
EXT3_FEATURE_INCOMPAT_JOURNAL_DEV) {
|
|
|
|
fs->group_desc_count = 0;
|
|
|
|
*ret_fs = fs;
|
|
|
|
return 0;
|
|
|
|
}
|
1997-04-26 17:21:57 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Read group descriptors
|
|
|
|
*/
|
2002-06-10 21:05:56 +04:00
|
|
|
blocks_per_group = EXT2_BLOCKS_PER_GROUP(fs->super);
|
|
|
|
if (blocks_per_group == 0 ||
|
|
|
|
blocks_per_group > EXT2_MAX_BLOCKS_PER_GROUP(fs->super) ||
|
|
|
|
fs->inode_blocks_per_group > EXT2_MAX_INODES_PER_GROUP(fs->super)) {
|
1999-05-30 01:48:03 +04:00
|
|
|
retval = EXT2_ET_CORRUPT_SUPERBLOCK;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2006-08-30 09:57:00 +04:00
|
|
|
fs->group_desc_count = ext2fs_div_ceil(fs->super->s_blocks_count -
|
|
|
|
fs->super->s_first_data_block,
|
|
|
|
blocks_per_group);
|
|
|
|
fs->desc_blocks = ext2fs_div_ceil(fs->group_desc_count,
|
|
|
|
EXT2_DESC_PER_BLOCK(fs->super));
|
2007-11-10 03:01:06 +03:00
|
|
|
retval = ext2fs_get_array(fs->desc_blocks, fs->blocksize,
|
2003-08-01 17:41:07 +04:00
|
|
|
&fs->group_desc);
|
1997-10-26 06:41:24 +03:00
|
|
|
if (retval)
|
1997-04-26 17:21:57 +04:00
|
|
|
goto cleanup;
|
1997-04-26 17:34:30 +04:00
|
|
|
if (!group_block)
|
2002-10-20 08:38:57 +04:00
|
|
|
group_block = fs->super->s_first_data_block;
|
1997-04-26 17:21:57 +04:00
|
|
|
dest = (char *) fs->group_desc;
|
2007-08-30 19:38:13 +04:00
|
|
|
groups_per_block = EXT2_DESC_PER_BLOCK(fs->super);
|
1997-04-26 17:21:57 +04:00
|
|
|
for (i=0 ; i < fs->desc_blocks; i++) {
|
2002-10-20 08:38:57 +04:00
|
|
|
blk = ext2fs_descriptor_block_loc(fs, group_block, i);
|
|
|
|
retval = io_channel_read_blk(fs->io, blk, 1, dest);
|
1997-04-26 17:21:57 +04:00
|
|
|
if (retval)
|
|
|
|
goto cleanup;
|
2007-08-11 09:56:48 +04:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
gdp = (struct ext2_group_desc *) dest;
|
|
|
|
for (j=0; j < groups_per_block; j++)
|
|
|
|
ext2fs_swap_group_desc(gdp++);
|
ChangeLog, Makefile.in, swapfs.c, unix.c:
Makefile.in: Add message.c and swapfs.c to the list of source files to
build the make depend.
swapfs.c, unix.c: Only support the -s and -S options to e2fsck if
ENABLE_SWAPFS is defined.
Many files:
ext2fs.h, bitops.h, block.c, bmap.c, closefs.c, dirblock.c, inode.c,
native.c, openfs.c, rw_bitmaps.c, swapfs.c: Only include the
byte-swapping logic if ENABLE_SWAPFS is turned on or if we're on a
big-endian machine.
initialize.c (ext2fs_initialize):Use WORDS_BIGENDIAN directly to set
EXT2_FLAG_SWAP_BYTES, instead of using ext2fs_native_flag.
native.c (ext2fs_native_flag): Use WORDS_BIGENDIAN provided by
autoconf to determine whether or not return EXT2_FLAG_SWAP_BYTES.
2001-06-11 11:00:04 +04:00
|
|
|
#endif
|
1997-04-26 17:21:57 +04:00
|
|
|
dest += fs->blocksize;
|
|
|
|
}
|
|
|
|
|
2007-05-19 06:06:53 +04:00
|
|
|
fs->stride = fs->super->s_raid_stride;
|
|
|
|
|
2007-10-22 06:03:25 +04:00
|
|
|
/*
|
|
|
|
* If recovery is from backup superblock, Clear _UNININT flags &
|
|
|
|
* reset bg_itable_unused to zero
|
|
|
|
*/
|
|
|
|
if (superblock > 1 && EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
|
|
|
|
EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
|
|
|
|
struct ext2_group_desc *gd;
|
|
|
|
for (i = 0, gd = fs->group_desc; i < fs->group_desc_count;
|
|
|
|
i++, gd++) {
|
|
|
|
gd->bg_flags &= ~EXT2_BG_BLOCK_UNINIT;
|
|
|
|
gd->bg_flags &= ~EXT2_BG_INODE_UNINIT;
|
|
|
|
gd->bg_itable_unused = 0;
|
|
|
|
}
|
|
|
|
ext2fs_mark_super_dirty(fs);
|
|
|
|
}
|
|
|
|
|
2008-02-27 04:45:36 +03:00
|
|
|
fs->flags &= ~EXT2_FLAG_NOFREE_ON_ERROR;
|
1997-04-26 17:21:57 +04:00
|
|
|
*ret_fs = fs;
|
|
|
|
return 0;
|
|
|
|
cleanup:
|
2008-02-27 04:45:36 +03:00
|
|
|
if (flags & EXT2_FLAG_NOFREE_ON_ERROR)
|
|
|
|
*ret_fs = fs;
|
|
|
|
else
|
|
|
|
ext2fs_free(fs);
|
1997-04-26 17:21:57 +04:00
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2004-07-29 05:11:48 +04:00
|
|
|
/*
|
|
|
|
* Set/get the filesystem data I/O channel.
|
|
|
|
*
|
|
|
|
* These functions are only valid if EXT2_FLAG_IMAGE_FILE is true.
|
|
|
|
*/
|
|
|
|
errcode_t ext2fs_get_data_io(ext2_filsys fs, io_channel *old_io)
|
|
|
|
{
|
|
|
|
if ((fs->flags & EXT2_FLAG_IMAGE_FILE) == 0)
|
|
|
|
return EXT2_ET_NOT_IMAGE_FILE;
|
|
|
|
if (old_io) {
|
|
|
|
*old_io = (fs->image_io == fs->io) ? 0 : fs->io;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
errcode_t ext2fs_set_data_io(ext2_filsys fs, io_channel new_io)
|
|
|
|
{
|
|
|
|
if ((fs->flags & EXT2_FLAG_IMAGE_FILE) == 0)
|
|
|
|
return EXT2_ET_NOT_IMAGE_FILE;
|
|
|
|
fs->io = new_io ? new_io : fs->image_io;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io)
|
|
|
|
{
|
|
|
|
if ((fs->flags & EXT2_FLAG_IMAGE_FILE) == 0)
|
|
|
|
return EXT2_ET_NOT_IMAGE_FILE;
|
|
|
|
fs->io = fs->image_io = new_io;
|
|
|
|
fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_RW |
|
|
|
|
EXT2_FLAG_BB_DIRTY | EXT2_FLAG_IB_DIRTY;
|
|
|
|
fs->flags &= ~EXT2_FLAG_IMAGE_FILE;
|
|
|
|
return 0;
|
|
|
|
}
|