1997-04-26 17:58:21 +04:00
|
|
|
/*
|
|
|
|
* swapfs.c --- swap ext2 filesystem data structures
|
|
|
|
*
|
2002-10-03 06:07:17 +04:00
|
|
|
* Copyright (C) 1995, 1996, 2002 Theodore Ts'o.
|
1997-04-29 20:17:09 +04:00
|
|
|
*
|
|
|
|
* %Begin-Header%
|
|
|
|
* This file may be redistributed under the terms of the GNU Public
|
|
|
|
* License.
|
|
|
|
* %End-Header%
|
1997-04-26 17:58:21 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#if HAVE_UNISTD_H
|
1997-04-26 17:58:21 +04:00
|
|
|
#include <unistd.h>
|
1997-08-11 03:07:40 +04:00
|
|
|
#endif
|
1997-04-26 17:58:21 +04:00
|
|
|
#include <time.h>
|
|
|
|
|
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:58:21 +04:00
|
|
|
#include "ext2fs.h"
|
|
|
|
|
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
|
|
|
#ifdef EXT2FS_ENABLE_SWAPFS
|
2001-01-01 19:17:12 +03:00
|
|
|
void ext2fs_swap_super(struct ext2_super_block * sb)
|
1997-04-26 17:58:21 +04:00
|
|
|
{
|
2002-10-03 06:07:17 +04:00
|
|
|
int i;
|
2001-01-01 19:17:12 +03:00
|
|
|
sb->s_inodes_count = ext2fs_swab32(sb->s_inodes_count);
|
|
|
|
sb->s_blocks_count = ext2fs_swab32(sb->s_blocks_count);
|
|
|
|
sb->s_r_blocks_count = ext2fs_swab32(sb->s_r_blocks_count);
|
|
|
|
sb->s_free_blocks_count = ext2fs_swab32(sb->s_free_blocks_count);
|
|
|
|
sb->s_free_inodes_count = ext2fs_swab32(sb->s_free_inodes_count);
|
|
|
|
sb->s_first_data_block = ext2fs_swab32(sb->s_first_data_block);
|
|
|
|
sb->s_log_block_size = ext2fs_swab32(sb->s_log_block_size);
|
|
|
|
sb->s_log_frag_size = ext2fs_swab32(sb->s_log_frag_size);
|
|
|
|
sb->s_blocks_per_group = ext2fs_swab32(sb->s_blocks_per_group);
|
|
|
|
sb->s_frags_per_group = ext2fs_swab32(sb->s_frags_per_group);
|
|
|
|
sb->s_inodes_per_group = ext2fs_swab32(sb->s_inodes_per_group);
|
|
|
|
sb->s_mtime = ext2fs_swab32(sb->s_mtime);
|
|
|
|
sb->s_wtime = ext2fs_swab32(sb->s_wtime);
|
|
|
|
sb->s_mnt_count = ext2fs_swab16(sb->s_mnt_count);
|
|
|
|
sb->s_max_mnt_count = ext2fs_swab16(sb->s_max_mnt_count);
|
|
|
|
sb->s_magic = ext2fs_swab16(sb->s_magic);
|
|
|
|
sb->s_state = ext2fs_swab16(sb->s_state);
|
|
|
|
sb->s_errors = ext2fs_swab16(sb->s_errors);
|
|
|
|
sb->s_minor_rev_level = ext2fs_swab16(sb->s_minor_rev_level);
|
|
|
|
sb->s_lastcheck = ext2fs_swab32(sb->s_lastcheck);
|
|
|
|
sb->s_checkinterval = ext2fs_swab32(sb->s_checkinterval);
|
|
|
|
sb->s_creator_os = ext2fs_swab32(sb->s_creator_os);
|
|
|
|
sb->s_rev_level = ext2fs_swab32(sb->s_rev_level);
|
|
|
|
sb->s_def_resuid = ext2fs_swab16(sb->s_def_resuid);
|
|
|
|
sb->s_def_resgid = ext2fs_swab16(sb->s_def_resgid);
|
|
|
|
sb->s_first_ino = ext2fs_swab32(sb->s_first_ino);
|
|
|
|
sb->s_inode_size = ext2fs_swab16(sb->s_inode_size);
|
|
|
|
sb->s_block_group_nr = ext2fs_swab16(sb->s_block_group_nr);
|
|
|
|
sb->s_feature_compat = ext2fs_swab32(sb->s_feature_compat);
|
|
|
|
sb->s_feature_incompat = ext2fs_swab32(sb->s_feature_incompat);
|
|
|
|
sb->s_feature_ro_compat = ext2fs_swab32(sb->s_feature_ro_compat);
|
|
|
|
sb->s_algorithm_usage_bitmap = ext2fs_swab32(sb->s_algorithm_usage_bitmap);
|
|
|
|
sb->s_journal_inum = ext2fs_swab32(sb->s_journal_inum);
|
|
|
|
sb->s_journal_dev = ext2fs_swab32(sb->s_journal_dev);
|
|
|
|
sb->s_last_orphan = ext2fs_swab32(sb->s_last_orphan);
|
2002-10-20 08:38:57 +04:00
|
|
|
sb->s_first_meta_bg = ext2fs_swab32(sb->s_first_meta_bg);
|
2002-10-03 06:07:17 +04:00
|
|
|
for (i=0; i < 4; i++)
|
|
|
|
sb->s_hash_seed[i] = ext2fs_swab32(sb->s_hash_seed[i]);
|
1997-04-26 17:58:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ext2fs_swap_group_desc(struct ext2_group_desc *gdp)
|
|
|
|
{
|
|
|
|
gdp->bg_block_bitmap = ext2fs_swab32(gdp->bg_block_bitmap);
|
|
|
|
gdp->bg_inode_bitmap = ext2fs_swab32(gdp->bg_inode_bitmap);
|
|
|
|
gdp->bg_inode_table = ext2fs_swab32(gdp->bg_inode_table);
|
|
|
|
gdp->bg_free_blocks_count = ext2fs_swab16(gdp->bg_free_blocks_count);
|
|
|
|
gdp->bg_free_inodes_count = ext2fs_swab16(gdp->bg_free_inodes_count);
|
|
|
|
gdp->bg_used_dirs_count = ext2fs_swab16(gdp->bg_used_dirs_count);
|
|
|
|
}
|
|
|
|
|
1997-04-29 18:53:37 +04:00
|
|
|
void ext2fs_swap_inode(ext2_filsys fs, struct ext2_inode *t,
|
|
|
|
struct ext2_inode *f, int hostorder)
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
int islnk = 0;
|
1997-04-26 17:58:21 +04:00
|
|
|
|
1997-04-29 18:53:37 +04:00
|
|
|
if (hostorder && LINUX_S_ISLNK(f->i_mode))
|
|
|
|
islnk = 1;
|
|
|
|
t->i_mode = ext2fs_swab16(f->i_mode);
|
|
|
|
if (!hostorder && LINUX_S_ISLNK(t->i_mode))
|
|
|
|
islnk = 1;
|
|
|
|
t->i_uid = ext2fs_swab16(f->i_uid);
|
|
|
|
t->i_size = ext2fs_swab32(f->i_size);
|
|
|
|
t->i_atime = ext2fs_swab32(f->i_atime);
|
|
|
|
t->i_ctime = ext2fs_swab32(f->i_ctime);
|
|
|
|
t->i_mtime = ext2fs_swab32(f->i_mtime);
|
|
|
|
t->i_dtime = ext2fs_swab32(f->i_dtime);
|
|
|
|
t->i_gid = ext2fs_swab16(f->i_gid);
|
|
|
|
t->i_links_count = ext2fs_swab16(f->i_links_count);
|
|
|
|
t->i_blocks = ext2fs_swab32(f->i_blocks);
|
|
|
|
t->i_flags = ext2fs_swab32(f->i_flags);
|
|
|
|
if (!islnk || f->i_blocks) {
|
|
|
|
for (i = 0; i < EXT2_N_BLOCKS; i++)
|
|
|
|
t->i_block[i] = ext2fs_swab32(f->i_block[i]);
|
|
|
|
} else if (t != f) {
|
|
|
|
for (i = 0; i < EXT2_N_BLOCKS; i++)
|
|
|
|
t->i_block[i] = f->i_block[i];
|
|
|
|
}
|
ChangeLog, e2fsck.h, pass1.c, pass2.c, pass4.c, swapfs.c:
e2fsck.h:
pass1.c (pass1_get_blocks, pass1_read_inode, pass1_write_inode,
pass1_check_directory, e2fsck_use_inode_shortcuts): Make pass1_* be
private static functions, and create new function
e2fsck_use_inode_shortcuts which sets and clears the inode shortcut
functions in the fs structure.
e2fsck.h:
pass2.c (e2fsck_process_bad_inode): Make process_bad_inode() an
exported function.
pass4.c (e2fsck_pass4): Call e2fsck_process_bad_inode to check if a
disconnected inode has any problems before connecting it to
/lost+found. Bug and suggested fix by Pavel Machek <pavel@bug.ucw.cz>
ChangeLog, swapfs.c:
swapfs.c (ext2fs_swap_inode): Add compatibility for Linux 2.3 kernels
that use i_generation instead of i_version. Patch supplied by Jon
Bright <sircus@sircus.demon.co.uk>.
ChangeLog, mke2fs.8.in:
mke2fs.8.in: Fix typo in man page which caused the badblocks command
to not show up in the "SEE ALSO" section.
ChangeLog, expect.1, expect.2, image.gz, name:
f_recnect_bad: New test which checks the case where a disconnect inode
also bad inode fields; we need to make sure e2fsck offers to fix the
inode (or clear the inode, as necessary).
1999-06-25 19:40:18 +04:00
|
|
|
t->i_generation = ext2fs_swab32(f->i_generation);
|
1997-04-29 18:53:37 +04:00
|
|
|
t->i_file_acl = ext2fs_swab32(f->i_file_acl);
|
|
|
|
t->i_dir_acl = ext2fs_swab32(f->i_dir_acl);
|
|
|
|
t->i_faddr = ext2fs_swab32(f->i_faddr);
|
1997-04-26 17:58:21 +04:00
|
|
|
|
1997-04-29 18:53:37 +04:00
|
|
|
switch (fs->super->s_creator_os) {
|
|
|
|
case EXT2_OS_LINUX:
|
1997-04-29 20:17:09 +04:00
|
|
|
t->osd1.linux1.l_i_reserved1 =
|
|
|
|
ext2fs_swab32(f->osd1.linux1.l_i_reserved1);
|
1997-04-29 18:53:37 +04:00
|
|
|
t->osd2.linux2.l_i_frag = f->osd2.linux2.l_i_frag;
|
|
|
|
t->osd2.linux2.l_i_fsize = f->osd2.linux2.l_i_fsize;
|
|
|
|
t->osd2.linux2.i_pad1 = ext2fs_swab16(f->osd2.linux2.i_pad1);
|
ChangeLog, debugfs.c:
debugfs.c (dump_inode): Remove #ifdef for i_version vs. i_generation
since we know it will always be i_generation now.
ChangeLog, e2fsck.h, flushb.c, scantest.c:
e2fsck.h, flushb.c, scantest.c: Remove uneeded include of linux/fs.h
bmap.c:
Fix silly spelling typo.
ChangeLog, getsize.c, ismounted.c, swapfs.c:
getsize.c, ismounted.c: Remove unneeded include of linux/fs.h
swapfs.c: Remove #ifdef HAVE_EXT2_INODE_VERSION since it's not needed
any more; we know it will always be i_generation. Add support for
swapping the high bits of the uid and gid.
2000-02-02 19:19:59 +03:00
|
|
|
t->osd2.linux2.l_i_uid_high =
|
|
|
|
ext2fs_swab16 (f->osd2.linux2.l_i_uid_high);
|
|
|
|
t->osd2.linux2.l_i_gid_high =
|
|
|
|
ext2fs_swab16 (f->osd2.linux2.l_i_gid_high);
|
|
|
|
t->osd2.linux2.l_i_reserved2 =
|
|
|
|
ext2fs_swab32(f->osd2.linux2.l_i_reserved2);
|
1997-04-29 18:53:37 +04:00
|
|
|
break;
|
|
|
|
case EXT2_OS_HURD:
|
|
|
|
t->osd1.hurd1.h_i_translator =
|
|
|
|
ext2fs_swab32 (f->osd1.hurd1.h_i_translator);
|
|
|
|
t->osd2.hurd2.h_i_frag = f->osd2.hurd2.h_i_frag;
|
|
|
|
t->osd2.hurd2.h_i_fsize = f->osd2.hurd2.h_i_fsize;
|
|
|
|
t->osd2.hurd2.h_i_mode_high =
|
|
|
|
ext2fs_swab16 (f->osd2.hurd2.h_i_mode_high);
|
|
|
|
t->osd2.hurd2.h_i_uid_high =
|
|
|
|
ext2fs_swab16 (f->osd2.hurd2.h_i_uid_high);
|
|
|
|
t->osd2.hurd2.h_i_gid_high =
|
|
|
|
ext2fs_swab16 (f->osd2.hurd2.h_i_gid_high);
|
|
|
|
t->osd2.hurd2.h_i_author =
|
|
|
|
ext2fs_swab32 (f->osd2.hurd2.h_i_author);
|
|
|
|
break;
|
|
|
|
case EXT2_OS_MASIX:
|
1997-04-29 20:17:09 +04:00
|
|
|
t->osd1.masix1.m_i_reserved1 =
|
|
|
|
ext2fs_swab32(f->osd1.masix1.m_i_reserved1);
|
1997-04-29 18:53:37 +04:00
|
|
|
t->osd2.masix2.m_i_frag = f->osd2.masix2.m_i_frag;
|
|
|
|
t->osd2.masix2.m_i_fsize = f->osd2.masix2.m_i_fsize;
|
|
|
|
t->osd2.masix2.m_pad1 = ext2fs_swab16(f->osd2.masix2.m_pad1);
|
1997-04-29 20:17:09 +04:00
|
|
|
t->osd2.masix2.m_i_reserved2[0] =
|
|
|
|
ext2fs_swab32(f->osd2.masix2.m_i_reserved2[0]);
|
|
|
|
t->osd2.masix2.m_i_reserved2[1] =
|
|
|
|
ext2fs_swab32(f->osd2.masix2.m_i_reserved2[1]);
|
1997-04-29 18:53:37 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
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
|