Whamcloud - gitweb
ChangeLog, Makefile.in, swapfs.c, unix.c:
authorTheodore Ts'o <tytso@mit.edu>
Mon, 11 Jun 2001 07:00:04 +0000 (07:00 +0000)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 11 Jun 2001 07:00:04 +0000 (07:00 +0000)
  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.

17 files changed:
e2fsck/ChangeLog
e2fsck/Makefile.in
e2fsck/swapfs.c
e2fsck/unix.c
lib/ext2fs/ChangeLog
lib/ext2fs/bitops.h
lib/ext2fs/block.c
lib/ext2fs/bmap.c
lib/ext2fs/closefs.c
lib/ext2fs/dirblock.c
lib/ext2fs/ext2fs.h
lib/ext2fs/initialize.c
lib/ext2fs/inode.c
lib/ext2fs/native.c
lib/ext2fs/openfs.c
lib/ext2fs/rw_bitmaps.c
lib/ext2fs/swapfs.c

index 28cbf55..c10b5c0 100644 (file)
@@ -1,3 +1,11 @@
+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
index a813e86..0b71fca 100644 (file)
@@ -83,6 +83,8 @@ SRCS= $(srcdir)/e2fsck.c \
        $(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)
index 620dacc..513859b 100644 (file)
@@ -16,6 +16,8 @@
 #include <et/com_err.h>
 #include "e2fsck.h"
 
+#ifdef ENABLE_SWAPFS
+
 struct swap_block_struct {
        ext2_ino_t      ino;
        int             isdir;
@@ -228,4 +230,4 @@ void swap_filesys(e2fsck_t ctx)
 #endif
 }
 
-
+#endif
index 049e273..f7ed56d 100644 (file)
@@ -572,11 +572,20 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
                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);
                }
@@ -597,7 +606,7 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_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);
@@ -605,6 +614,7 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
                }
                close(fd);
        }
+#ifdef ENABLE_SWAPFS
        if (swapfs) {
                if (cflag || bad_blocks_file) {
                        fprintf(stderr, _("Incompatible options not "
@@ -612,6 +622,7 @@ static errcode_t PRS(int argc, char *argv[], e2fsck_t *ret_ctx)
                        exit(FSCK_USAGE);
                }
        }
+#endif
 #ifdef HAVE_SIGNAL_H
        /*
         * Set up signal action
@@ -880,7 +891,7 @@ restart:
                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()) {
@@ -894,6 +905,7 @@ restart:
                if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
                        fatal_error(ctx, 0);
        }
+#endif
 
        /*
         * Mark the system as valid, 'til proven otherwise
index 4ff3df4..f26f76b 100644 (file)
@@ -1,3 +1,18 @@
+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.
index f91f564..f4b8e26 100644 (file)
@@ -156,6 +156,7 @@ _INLINE_ int ext2fs_test_bit(int nr, const void * addr)
        return oldbit;
 }
 
+#ifdef EXT2FS_ENABLE_SWAPFS
 _INLINE_ __u32 ext2fs_swab32(__u32 val)
 {
 #ifdef EXT2FS_REQUIRE_486
@@ -177,6 +178,7 @@ _INLINE_ __u16 ext2fs_swab16(__u16 val)
                :  "0" (val)); \
                return val;
 }
+#endif
 
 #undef EXT2FS_ADDR
 
@@ -337,7 +339,7 @@ _INLINE_ int ext2fs_test_bit(int nr, const void *addr)
 
 #endif /* __sparc__ */
 
-#ifndef _EXT2_HAVE_ASM_SWAB_
+#if !defined(_EXT2_HAVE_ASM_SWAB_) && defined(ENABLE_SWAPFS)
 
 _INLINE_ __u16 ext2fs_swab16(__u16 val)
 {
index 1abbf38..a0bf738 100644 (file)
@@ -69,12 +69,14 @@ static int block_iterate_ind(blk_t *ind_block, blk_t ref_block,
                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) {
@@ -106,12 +108,14 @@ static int block_iterate_ind(blk_t *ind_block, blk_t ref_block,
        }
        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)
@@ -159,12 +163,14 @@ static int block_iterate_dind(blk_t *dind_block, blk_t ref_block,
                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) {
@@ -198,12 +204,14 @@ static int block_iterate_dind(blk_t *dind_block, blk_t ref_block,
        }
        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)
@@ -251,12 +259,14 @@ static int block_iterate_tind(blk_t *tind_block, blk_t ref_block,
                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) {
@@ -290,12 +300,14 @@ static int block_iterate_tind(blk_t *tind_block, blk_t ref_block,
        }
        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)
index 6d73328..25ba695 100644 (file)
@@ -51,9 +51,11 @@ static errcode_t _BMAP_INLINE_ block_ind_bmap(ext2_filsys fs, int flags,
 
        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;
@@ -62,10 +64,12 @@ static errcode_t _BMAP_INLINE_ block_ind_bmap(ext2_filsys fs, int flags,
                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);
index 91a342a..69a769f 100644 (file)
@@ -129,6 +129,7 @@ errcode_t ext2fs_flush(ext2_filsys fs)
 
        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,
@@ -157,6 +158,10 @@ errcode_t ext2fs_flush(ext2_filsys fs)
                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
@@ -183,10 +188,12 @@ errcode_t ext2fs_flush(ext2_filsys fs)
         * 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
@@ -202,9 +209,11 @@ errcode_t ext2fs_flush(ext2_filsys fs)
                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 ) {
index d1d8ca8..846aebe 100644 (file)
@@ -31,17 +31,21 @@ errcode_t ext2fs_read_dir_block(ext2_filsys fs, blk_t block,
        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;
@@ -63,6 +67,7 @@ errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
        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);
@@ -85,6 +90,7 @@ errcode_t ext2fs_write_dir_block(ext2_filsys fs, blk_t block,
                        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:
index d0ac235..f89ccc7 100644 (file)
@@ -24,6 +24,15 @@ extern "C" {
 #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
index 8022aee..821036e 100644 (file)
@@ -77,7 +77,10 @@ errcode_t ext2fs_initialize(const char *name, int flags,
        
        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;
index 4d4911a..5b4dd2b 100644 (file)
@@ -445,21 +445,25 @@ errcode_t ext2fs_get_next_inode(ext2_inode_scan scan, ext2_ino_t *ino,
                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;
@@ -556,9 +560,11 @@ errcode_t ext2fs_read_inode (ext2_filsys fs, ext2_ino_t ino,
        } 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) %
@@ -607,10 +613,12 @@ errcode_t ext2fs_write_inode(ext2_filsys fs, ext2_ino_t ino,
        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);
index 6315a91..85d0989 100644 (file)
 #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
 }
 
        
index 2abbb2a..96ddf49 100644 (file)
@@ -119,12 +119,14 @@ errcode_t ext2fs_open(const char *name, int flags, int superblock,
        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;
@@ -216,6 +218,7 @@ errcode_t ext2fs_open(const char *name, int flags, int superblock,
                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 /
@@ -223,6 +226,7 @@ errcode_t ext2fs_open(const char *name, int flags, int superblock,
                        for (j=0; j < groups_per_block; j++)
                                ext2fs_swap_group_desc(gdp++);
                }
+#endif
                dest += fs->blocksize;
        }
 
index 559f4a6..89557db 100644 (file)
@@ -27,7 +27,7 @@
 #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
index f26f7cd..f50a795 100644 (file)
@@ -18,6 +18,7 @@
 #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);
@@ -141,4 +142,4 @@ void ext2fs_swap_inode(ext2_filsys fs, struct ext2_inode *t,
                break;
        }
 }
-       
+#endif