diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ext2fs/ChangeLog | 15 | ||||
-rw-r--r-- | lib/ext2fs/bitops.h | 4 | ||||
-rw-r--r-- | lib/ext2fs/block.c | 12 | ||||
-rw-r--r-- | lib/ext2fs/bmap.c | 4 | ||||
-rw-r--r-- | lib/ext2fs/closefs.c | 9 | ||||
-rw-r--r-- | lib/ext2fs/dirblock.c | 6 | ||||
-rw-r--r-- | lib/ext2fs/ext2fs.h | 9 | ||||
-rw-r--r-- | lib/ext2fs/initialize.c | 5 | ||||
-rw-r--r-- | lib/ext2fs/inode.c | 8 | ||||
-rw-r--r-- | lib/ext2fs/native.c | 14 | ||||
-rw-r--r-- | lib/ext2fs/openfs.c | 4 | ||||
-rw-r--r-- | lib/ext2fs/rw_bitmaps.c | 2 | ||||
-rw-r--r-- | lib/ext2fs/swapfs.c | 3 |
13 files changed, 81 insertions, 14 deletions
diff --git a/lib/ext2fs/ChangeLog b/lib/ext2fs/ChangeLog index 4ff3df46..f26f76b8 100644 --- a/lib/ext2fs/ChangeLog +++ b/lib/ext2fs/ChangeLog @@ -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. diff --git a/lib/ext2fs/bitops.h b/lib/ext2fs/bitops.h index f91f5645..f4b8e260 100644 --- a/lib/ext2fs/bitops.h +++ b/lib/ext2fs/bitops.h @@ -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) { diff --git a/lib/ext2fs/block.c b/lib/ext2fs/block.c index 1abbf382..a0bf7382 100644 --- a/lib/ext2fs/block.c +++ b/lib/ext2fs/block.c @@ -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) diff --git a/lib/ext2fs/bmap.c b/lib/ext2fs/bmap.c index 6d73328c..25ba6956 100644 --- a/lib/ext2fs/bmap.c +++ b/lib/ext2fs/bmap.c @@ -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); diff --git a/lib/ext2fs/closefs.c b/lib/ext2fs/closefs.c index 91a342a4..69a769f1 100644 --- a/lib/ext2fs/closefs.c +++ b/lib/ext2fs/closefs.c @@ -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 ) { diff --git a/lib/ext2fs/dirblock.c b/lib/ext2fs/dirblock.c index d1d8ca8d..846aebe3 100644 --- a/lib/ext2fs/dirblock.c +++ b/lib/ext2fs/dirblock.c @@ -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: diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index d0ac235b..f89ccc7e 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -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 diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index 8022aee0..821036e7 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -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; diff --git a/lib/ext2fs/inode.c b/lib/ext2fs/inode.c index 4d4911a2..5b4dd2b5 100644 --- a/lib/ext2fs/inode.c +++ b/lib/ext2fs/inode.c @@ -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); diff --git a/lib/ext2fs/native.c b/lib/ext2fs/native.c index 6315a910..85d09896 100644 --- a/lib/ext2fs/native.c +++ b/lib/ext2fs/native.c @@ -14,19 +14,13 @@ #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 } diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index 2abbb2ae..96ddf49e 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -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; } diff --git a/lib/ext2fs/rw_bitmaps.c b/lib/ext2fs/rw_bitmaps.c index 559f4a67..89557dbf 100644 --- a/lib/ext2fs/rw_bitmaps.c +++ b/lib/ext2fs/rw_bitmaps.c @@ -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 diff --git a/lib/ext2fs/swapfs.c b/lib/ext2fs/swapfs.c index f26f7cdd..f50a7950 100644 --- a/lib/ext2fs/swapfs.c +++ b/lib/ext2fs/swapfs.c @@ -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 |