summaryrefslogtreecommitdiff
path: root/ext2fs
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1999-10-03 10:23:26 +0000
committerRoland McGrath <roland@gnu.org>1999-10-03 10:23:26 +0000
commitebdb70eb19f10ed22d5a83f757b09b744dde32a2 (patch)
tree77801299c913646c1001fe00a257b3b4659da001 /ext2fs
parent1a47f0938f3ad432da4cca31a1a4b86af1699a70 (diff)
1999-10-03 Roland McGrath <roland@baalperazim.frob.com>
* ext2fs.h (test_bit, set_bit, clear_bit): Rewritten to operate on 32-bit words instead of bytes. * ext2fs.h (group_desc): Inline function replaced with macro. (group_desc_image): New variable. * hyper.c (get_hypermetadata): Initialize it. * ext2fs.h (sblock_block): Declare new variable. (SBLOCK_LBLOCK): Macro removed. (SBLOCK_OFFS): Define in terms of sblock_block. * ext2fs.c (options): Add --sblock/-S. (parse_opt): Parse it to set sblock_block. * hyper.c (sblock_block): New variable. (get_hypermetadata): Use sblock_block instead of constant SBLOCK_BLOCK. * hyper.c (get_hypermetadata): Use EXT2_MAX_BLOCK_SIZE instead of hard-wired 8192. Don't use ffs to compute log2_block_size, and don't check for the impossible case of non-power-of-two block size (the block size specification we start with is given as a power of two!). * ext2fs.h (block_size): Change type to unsigned int. (BLOCKSIZE_SCALE): Just use SBLOCK->s_log_block_size directly. * hyper.c (get_hypermetadata): Fix printf formats to silence warning. * dir.c (dirscanblock): Likewise.
Diffstat (limited to 'ext2fs')
-rw-r--r--ext2fs/ext2fs.h64
1 files changed, 23 insertions, 41 deletions
diff --git a/ext2fs/ext2fs.h b/ext2fs/ext2fs.h
index 7517d9a8..8e73ae0a 100644
--- a/ext2fs/ext2fs.h
+++ b/ext2fs/ext2fs.h
@@ -109,11 +109,15 @@ void pokel_inherit (struct pokel *pokel, struct pokel *from);
/* ---------------------------------------------------------------- */
/* Bitmap routines. */
+#include <stdint.h>
+
/* Returns TRUE if bit NUM is set in BITMAP. */
EXT2FS_EI int
test_bit (unsigned num, char *bitmap)
{
- return bitmap[num >> 3] & (1 << (num & 0x7));
+ const uint32_t *const bw = (uint32_t *) bitmap + (num >> 5);
+ const uint_fast32_t mask = 1 << (num & 31);
+ return *bw & mask;
}
/* Sets bit NUM in BITMAP, and returns the previous state of the bit. Unlike
@@ -121,17 +125,9 @@ test_bit (unsigned num, char *bitmap)
EXT2FS_EI int
set_bit (unsigned num, char *bitmap)
{
- char *p = bitmap + (num >> 3);
- char byte = *p;
- char mask = (1 << (num & 0x7));
-
- if (byte & mask)
- return 1;
- else
- {
- *p = byte | mask;
- return 0;
- }
+ uint32_t *const bw = (uint32_t *) bitmap + (num >> 5);
+ const uint_fast32_t mask = 1 << (num & 31);
+ return (*bw & mask) ?: (*bw |= mask, 0);
}
/* Clears bit NUM in BITMAP, and returns the previous state of the bit.
@@ -139,17 +135,9 @@ set_bit (unsigned num, char *bitmap)
EXT2FS_EI int
clear_bit (unsigned num, char *bitmap)
{
- char *p = bitmap + (num >> 3);
- char byte = *p;
- char mask = (1 << (num & 0x7));
-
- if (byte & mask)
- {
- *p = byte & ~mask;
- return 1;
- }
- else
- return 0;
+ uint32_t *const bw = (uint32_t *) bitmap + (num >> 5);
+ const uint_fast32_t mask = 1 << (num & 31);
+ return (*bw & mask) ? (*bw &= ~mask, mask) : 0;
}
/* ---------------------------------------------------------------- */
@@ -224,24 +212,24 @@ extern struct store_parsed *store_parsed;
/* Mapped image of the disk. */
extern void *disk_image;
-/* Our in-core copy of the super-block. */
+/* Our in-core copy of the super-block (pointer into the disk_image). */
struct ext2_super_block *sblock;
/* True if sblock has been modified. */
int sblock_dirty;
/* Where the super-block is located on disk (at min-block 1). */
-#define SBLOCK_BLOCK 1
-#define SBLOCK_OFFS (SBLOCK_BLOCK * EXT2_MIN_BLOCK_SIZE)
-#define SBLOCK_SIZE (sizeof (struct ext2_super_block))
-#define SBLOCK_LBLOCK (SBLOCK_BLOCK >> BLOCKSIZE_SCALE)
+#define SBLOCK_BLOCK 1 /* Default location, second 1k block. */
+#define SBLOCK_SIZE (sizeof (struct ext2_super_block))
+extern unsigned int sblock_block; /* Specified location (in 1k blocks). */
+#define SBLOCK_OFFS (sblock_block << 10) /* Byte offset of superblock. */
/* The filesystem block-size. */
-unsigned long block_size;
+unsigned int block_size;
/* The log base 2 of BLOCK_SIZE. */
-unsigned log2_block_size;
+unsigned int log2_block_size;
/* The number of bits to scale min-blocks to get filesystem blocks. */
-#define BLOCKSIZE_SCALE (log2_block_size - EXT2_MIN_BLOCK_LOG_SIZE)
+#define BLOCKSIZE_SCALE (sblock->s_log_block_size)
/* log2 of the number of device blocks in a filesystem block. */
unsigned log2_dev_blocks_per_fs_block;
@@ -299,16 +287,10 @@ unsigned long next_generation;
#define bptr_block(ptr) boffs_block(bptr_offs(ptr))
/* Get the descriptor for block group NUM. The block group descriptors are
- stored starting in the filesystem block following the super block. */
-EXT2FS_EI struct ext2_group_desc *
-group_desc(unsigned long num)
-{
- int desc_per_block = EXT2_DESC_PER_BLOCK(sblock);
- unsigned long group_desc = num / desc_per_block;
- unsigned long desc = num % desc_per_block;
- return ((struct ext2_group_desc *) bptr(SBLOCK_LBLOCK + 1 + group_desc)
- + desc);
-}
+ stored starting in the filesystem block following the super block.
+ We cache a pointer into the disk image for easy lookup. */
+#define group_desc(num) (&group_desc_image[num])
+struct ext2_group_desc *group_desc_image;
#define inode_group_num(inum) (((inum) - 1) / sblock->s_inodes_per_group)