+2001-06-11 Theodore Tso <tytso@valinux.com>
+
+ * 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.
+
2001-06-08 Theodore Tso <tytso@valinux.com>
* recover.c, revoke.c: Synchronize with ext3 0.7a
$(srcdir)/dirinfo.c \
$(srcdir)/ehandler.c \
$(srcdir)/problem.c \
+ $(srcdir)/message.c \
+ $(srcdir)/swapfs.c \
$(MTRACE_SRC)
all:: profiled $(PROGS) e2fsck.static e2fsck.shared $(MANPAGES)
#include <et/com_err.h>
#include "e2fsck.h"
+#ifdef ENABLE_SWAPFS
+
struct swap_block_struct {
ext2_ino_t ino;
int isdir;
#endif
}
-
+#endif
case 'N':
ctx->device_name = optarg;
break;
+#ifdef ENABLE_SWAPFS
case 's':
normalize_swapfs = 1;
case 'S':
swapfs = 1;
break;
+#else
+ case 's':
+ case 'S':
+ fprintf(stderr, _("Byte-swapping filesystems "
+ "not compiled in this version "
+ "of e2fsck\n"));
+ exit(1);
+#endif
default:
usage(ctx);
}
ctx->filesystem_name);
fatal_error(ctx, 0);
}
- if ((retval == ext2fs_sync_device(fd, 1))) {
+ if ((retval = ext2fs_sync_device(fd, 1))) {
com_err("ext2fs_sync_device", retval,
_("while trying to flush %s"),
ctx->filesystem_name);
}
close(fd);
}
+#ifdef ENABLE_SWAPFS
if (swapfs) {
if (cflag || bad_blocks_file) {
fprintf(stderr, _("Incompatible options not "
exit(FSCK_USAGE);
}
}
+#endif
#ifdef HAVE_SIGNAL_H
/*
* Set up signal action
test_disk(ctx);
if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
fatal_error(ctx, 0);
-
+#ifdef ENABLE_SWAPFS
if (normalize_swapfs) {
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ==
ext2fs_native_flag()) {
if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
fatal_error(ctx, 0);
}
+#endif
/*
* Mark the system as valid, 'til proven otherwise
+2001-06-11 Theodore Tso <tytso@valinux.com>
+
+ * 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-10 Theodore Tso <tytso@valinux.com>
* Makefile.in: Remove the dependence on the libe2p library.
return oldbit;
}
+#ifdef EXT2FS_ENABLE_SWAPFS
_INLINE_ __u32 ext2fs_swab32(__u32 val)
{
#ifdef EXT2FS_REQUIRE_486
: "0" (val)); \
return val;
}
+#endif
#undef EXT2FS_ADDR
#endif /* __sparc__ */
-#ifndef _EXT2_HAVE_ASM_SWAB_
+#if !defined(_EXT2_HAVE_ASM_SWAB_) && defined(ENABLE_SWAPFS)
_INLINE_ __u16 ext2fs_swab16(__u16 val)
{
ret |= BLOCK_ERROR;
return ret;
}
+#ifdef EXT2FS_ENABLE_SWAPFS
if (ctx->fs->flags & (EXT2_FLAG_SWAP_BYTES |
EXT2_FLAG_SWAP_BYTES_READ)) {
block_nr = (blk_t *) ctx->ind_buf;
for (i = 0; i < limit; i++, block_nr++)
*block_nr = ext2fs_swab32(*block_nr);
}
+#endif
block_nr = (blk_t *) ctx->ind_buf;
offset = 0;
if (ctx->flags & BLOCK_FLAG_APPEND) {
}
if (!(ctx->fs->flags & EXT2_FLAG_IMAGE_FILE) &&
(changed & BLOCK_CHANGED)) {
+#ifdef EXT2FS_ENABLE_SWAPFS
if (ctx->fs->flags & (EXT2_FLAG_SWAP_BYTES |
EXT2_FLAG_SWAP_BYTES_WRITE)) {
block_nr = (blk_t *) ctx->ind_buf;
for (i = 0; i < limit; i++, block_nr++)
*block_nr = ext2fs_swab32(*block_nr);
}
+#endif
ctx->errcode = io_channel_write_blk(ctx->fs->io, *ind_block,
1, ctx->ind_buf);
if (ctx->errcode)
ret |= BLOCK_ERROR;
return ret;
}
+#ifdef EXT2FS_ENABLE_SWAPFS
if (ctx->fs->flags & (EXT2_FLAG_SWAP_BYTES |
EXT2_FLAG_SWAP_BYTES_READ)) {
block_nr = (blk_t *) ctx->dind_buf;
for (i = 0; i < limit; i++, block_nr++)
*block_nr = ext2fs_swab32(*block_nr);
}
+#endif
block_nr = (blk_t *) ctx->dind_buf;
offset = 0;
if (ctx->flags & BLOCK_FLAG_APPEND) {
}
if (!(ctx->fs->flags & EXT2_FLAG_IMAGE_FILE) &&
(changed & BLOCK_CHANGED)) {
+#ifdef EXT2FS_ENABLE_SWAPFS
if (ctx->fs->flags & (EXT2_FLAG_SWAP_BYTES |
EXT2_FLAG_SWAP_BYTES_WRITE)) {
block_nr = (blk_t *) ctx->dind_buf;
for (i = 0; i < limit; i++, block_nr++)
*block_nr = ext2fs_swab32(*block_nr);
}
+#endif
ctx->errcode = io_channel_write_blk(ctx->fs->io, *dind_block,
1, ctx->dind_buf);
if (ctx->errcode)
ret |= BLOCK_ERROR;
return ret;
}
+#ifdef EXT2FS_ENABLE_SWAPFS
if (ctx->fs->flags & (EXT2_FLAG_SWAP_BYTES |
EXT2_FLAG_SWAP_BYTES_READ)) {
block_nr = (blk_t *) ctx->tind_buf;
for (i = 0; i < limit; i++, block_nr++)
*block_nr = ext2fs_swab32(*block_nr);
}
+#endif
block_nr = (blk_t *) ctx->tind_buf;
offset = 0;
if (ctx->flags & BLOCK_FLAG_APPEND) {
}
if (!(ctx->fs->flags & EXT2_FLAG_IMAGE_FILE) &&
(changed & BLOCK_CHANGED)) {
+#ifdef EXT2FS_ENABLE_SWAPFS
if (ctx->fs->flags & (EXT2_FLAG_SWAP_BYTES |
EXT2_FLAG_SWAP_BYTES_WRITE)) {
block_nr = (blk_t *) ctx->tind_buf;
for (i = 0; i < limit; i++, block_nr++)
*block_nr = ext2fs_swab32(*block_nr);
}
+#endif
ctx->errcode = io_channel_write_blk(ctx->fs->io, *tind_block,
1, ctx->tind_buf);
if (ctx->errcode)
b = ((blk_t *) block_buf)[nr];
+#ifdef EXT2FS_ENABLE_SWAPFS
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
b = ext2fs_swab32(b);
+#endif
if (!b && (flags & BMAP_ALLOC)) {
b = nr ? ((blk_t *) block_buf)[nr-1] : 0;
if (retval)
return retval;
+#ifdef EXT2FS_ENABLE_SWAPFS
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE))
((blk_t *) block_buf)[nr] = ext2fs_swab32(b);
else
+#endif
((blk_t *) block_buf)[nr] = b;
retval = io_channel_write_blk(fs->io, ind, 1, block_buf);
fs->super->s_wtime = time(NULL);
fs->super->s_block_group_nr = 0;
+#ifdef EXT2FS_ENABLE_SWAPFS
if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
retval = EXT2_ET_NO_MEMORY;
retval = ext2fs_get_mem(SUPERBLOCK_SIZE,
super_shadow = fs->super;
group_shadow = fs->group_desc;
}
+#else
+ super_shadow = fs->super;
+ group_shadow = fs->group_desc;
+#endif
/*
* Write out master superblock. This has to be done
* we exit.)
*/
fs->super->s_state &= ~EXT2_VALID_FS;
+#ifdef EXT2FS_ENABLE_SWAPFS
if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
*super_shadow = *fs->super;
ext2fs_swap_super(super_shadow);
}
+#endif
/*
* Write out the master group descriptors, and the backup
sgrp = i;
if (sgrp > ((1 << 16) - 1))
sgrp = (1 << 16) - 1;
+#ifdef EXT2FS_ENABLE_SWAPFS
if (fs->flags & EXT2_FLAG_SWAP_BYTES)
super_shadow->s_block_group_nr = ext2fs_swab16(sgrp);
else
+#endif
fs->super->s_block_group_nr = sgrp;
if (i !=0 ) {
retval = io_channel_read_blk(fs->io, block, 1, buf);
if (retval)
return retval;
+#ifdef EXT2FS_ENABLE_SWAPFS
do_swap = (fs->flags & (EXT2_FLAG_SWAP_BYTES|
EXT2_FLAG_SWAP_BYTES_READ)) != 0;
+#endif
p = (char *) buf;
end = (char *) buf + fs->blocksize;
while (p < end-8) {
dirent = (struct ext2_dir_entry *) p;
+#ifdef EXT2FS_ENABLE_SWAPFS
if (do_swap) {
dirent->inode = ext2fs_swab32(dirent->inode);
dirent->rec_len = ext2fs_swab16(dirent->rec_len);
dirent->name_len = ext2fs_swab16(dirent->name_len);
}
+#endif
rec_len = dirent->rec_len;
if ((rec_len < 8) || (rec_len % 4)) {
rec_len = 8;
char *buf = 0;
struct ext2_dir_entry *dirent;
+#ifdef EXT2FS_ENABLE_SWAPFS
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)) {
retval = ext2fs_get_mem(fs->blocksize, (void **) &buf);
dirent->name_len = ext2fs_swab16(dirent->name_len);
}
} else
+#endif
write_buf = (char *) inbuf;
retval = io_channel_write_blk(fs->io, block, 1, write_buf);
errout:
#endif
/*
+ * Build in support for byte-swapping filesystems if we the feature
+ * has been configured or if we're being built on a CPU architecture
+ * with a non-native byte order.
+ */
+#if defined(ENABLE_SWAPFS) || defined(WORDS_BIGENDIAN)
+#define EXT2FS_ENABLE_SWAPFS
+#endif
+
+/*
* Where the master copy of the superblock is located, and how big
* superblocks are supposed to be. We define SUPERBLOCK_SIZE because
* the size of the superblock structure is not necessarily trustworthy
memset(fs, 0, sizeof(struct struct_ext2_filsys));
fs->magic = EXT2_ET_MAGIC_EXT2FS_FILSYS;
- fs->flags = flags | EXT2_FLAG_RW | ext2fs_native_flag();
+ fs->flags = flags | EXT2_FLAG_RW;
+#ifdef WORDS_BIGENDIAN
+ fs->flags |= EXT2_FLAG_SWAP_BYTES;
+#endif
retval = manager->open(name, IO_FLAG_RW, &fs->io);
if (retval)
goto cleanup;
scan->ptr += scan->inode_size - extra_bytes;
scan->bytes_left -= scan->inode_size - extra_bytes;
+#ifdef EXT2FS_ENABLE_SWAPFS
if ((scan->fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(scan->fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
ext2fs_swap_inode(scan->fs, inode,
(struct ext2_inode *) scan->temp_buffer, 0);
else
+#endif
*inode = *((struct ext2_inode *) scan->temp_buffer);
if (scan->scan_flags & EXT2_SF_BAD_EXTRA_BYTES)
retval = EXT2_ET_BAD_BLOCK_IN_INODE_TABLE;
scan->scan_flags &= ~EXT2_SF_BAD_EXTRA_BYTES;
} else {
+#ifdef EXT2FS_ENABLE_SWAPFS
if ((scan->fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(scan->fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
ext2fs_swap_inode(scan->fs, inode,
(struct ext2_inode *) scan->ptr, 0);
else
+#endif
*inode = *((struct ext2_inode *) scan->ptr);
scan->ptr += scan->inode_size;
scan->bytes_left -= scan->inode_size;
} else
memcpy((char *) inode, ptr, length);
+#ifdef EXT2FS_ENABLE_SWAPFS
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES_READ))
ext2fs_swap_inode(fs, inode, inode, 0);
+#endif
/* Update the inode cache */
fs->icache->cache_last = (fs->icache->cache_last + 1) %
if ((ino == 0) || (ino > fs->super->s_inodes_count))
return EXT2_ET_BAD_INODE_NUM;
+#ifdef EXT2FS_ENABLE_SWAPFS
if ((fs->flags & EXT2_FLAG_SWAP_BYTES) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE))
ext2fs_swap_inode(fs, &temp_inode, inode, 1);
else
+#endif
memcpy(&temp_inode, inode, sizeof(struct ext2_inode));
group = (ino - 1) / EXT2_INODES_PER_GROUP(fs->super);
#include "ext2_fs.h"
#include "ext2fs.h"
-static int i386_byteorder(void)
-{
- int one = 1;
- char *cp = (char *) &one;
-
- return (*cp == 1);
-}
-
int ext2fs_native_flag(void)
{
- if (i386_byteorder())
- return 0;
+#ifdef WORDS_BIGENDIAN
return EXT2_FLAG_SWAP_BYTES;
+#else
+ return 0;
+#endif
}
if (fs->orig_super)
memcpy(fs->orig_super, fs->super, SUPERBLOCK_SIZE);
+#ifdef EXT2FS_ENABLE_SWAPFS
if ((fs->super->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC)) ||
(fs->flags & EXT2_FLAG_SWAP_BYTES)) {
fs->flags |= EXT2_FLAG_SWAP_BYTES;
ext2fs_swap_super(fs->super);
}
+#endif
if (fs->super->s_magic != EXT2_SUPER_MAGIC) {
retval = EXT2_ET_BAD_MAGIC;
if (retval)
goto cleanup;
group_block++;
+#ifdef EXT2FS_ENABLE_SWAPFS
if (fs->flags & EXT2_FLAG_SWAP_BYTES) {
gdp = (struct ext2_group_desc *) dest;
groups_per_block = fs->blocksize /
for (j=0; j < groups_per_block; j++)
ext2fs_swap_group_desc(gdp++);
}
+#endif
dest += fs->blocksize;
}
#include "ext2fs.h"
#include "e2image.h"
-#ifdef __powerpc__
+#if defined(__powerpc__) && defined(EXT2FS_ENABLE_SWAPFS)
/*
* On the PowerPC, the big-endian variant of the ext2 filesystem
* has its bitmaps stored as 32-bit words with bit 0 as the LSB
#include "ext2_fs.h"
#include "ext2fs.h"
+#ifdef EXT2FS_ENABLE_SWAPFS
void ext2fs_swap_super(struct ext2_super_block * sb)
{
sb->s_inodes_count = ext2fs_swab32(sb->s_inodes_count);
break;
}
}
-
+#endif