From c3cf5b5715a5377c3798ca221b8fb5142c1f21db Mon Sep 17 00:00:00 2001 From: Miles Bader Date: Mon, 17 Apr 1995 15:37:08 +0000 Subject: Formerly ext2fs.h.~23~ --- ext2fs/ext2fs.h | 159 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 96 insertions(+), 63 deletions(-) (limited to 'ext2fs/ext2fs.h') diff --git a/ext2fs/ext2fs.h b/ext2fs/ext2fs.h index adddec72..f7d78d1a 100644 --- a/ext2fs/ext2fs.h +++ b/ext2fs/ext2fs.h @@ -62,6 +62,63 @@ void pokel_add (struct pokel *pokel, void *loc, vm_size_t length); void pokel_sync (struct pokel *pokel, int wait); /* ---------------------------------------------------------------- */ +/* Bitmap routines. */ + +/* Returns TRUE if bit NUM is set in BITMAP. */ +inline int +test_bit (unsigned num, char *bitmap) +{ + return bitmap[num >> 3] & (1 << (num & 0x7)); +} + +/* Sets bit NUM in BITMAP, and returns TRUE if it was already set. */ +inline 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; + } +} + +/* Clears bit NUM in BITMAP, and returns TRUE if it was already clear. */ +inline 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 0; + } + else + return 1; +} + +/* Counts the number of bits unset in MAP, a bitmap NUMCHARS long. */ +unsigned long count_free (char * map, unsigned int numchars); + +extern int find_first_zero_bit(void * addr, unsigned size); + +extern int find_next_zero_bit (void * addr, int size, int offset); + +extern unsigned long ffz(unsigned long word); + +/* Returns a pointer to the first occurence of CH in the buffer BUF of len + LEN, or BUF + LEN if CH doesn't occur. */ +void *memscan(void *buf, unsigned char ch, unsigned len); + +/* ---------------------------------------------------------------- */ struct disknode { @@ -214,13 +271,6 @@ dino (ino_t inum) unsigned long block = bg->bg_inode_table + (bg_num / inodes_per_block); return ((struct ext2_inode *)bptr(block)) + inum % inodes_per_block; } - -/* Sync part of the disk */ -extern inline void -sync_disk_image (void *place, size_t nbytes, int wait) -{ - pager_sync_some (disk_pager->p, bptr_offs (place), nbytes, wait); -} /* ---------------------------------------------------------------- */ @@ -236,6 +286,44 @@ void inode_init (void); /* ---------------------------------------------------------------- */ +#define trunc_block(offs) (((offs) >> log2_block_size) << log2_block_size) + +/* If the block size is less than the page size, then this bitmap is used to + record which disk blocks are actually modified, so we don't stomp on parts + of the disk which are backed by file pagers. */ +char *modified_global_blocks; + +/* This records a modification to a non-file block. */ +inline void +record_global_poke (char *image) +{ + int boffs = trunc_block(bptr_offs(image)); + if (!modified_global_blocks + || !set_bit (boffs_block (boffs), modified_global_blocks)) + pokel_add (&sblock_pokel, boffs_ptr(boffs), block_size); +} + +/* ---------------------------------------------------------------- */ + +/* Sync part of the disk */ +extern inline void +sync_disk_image (void *place, size_t nbytes, int wait) +{ + pager_sync_some (disk_pager->p, bptr_offs (place), nbytes, wait); +} + +extern inline void +sync_global_data () +{ + pokel_sync (&sblock_pokel, 1); + if (sblock_dirty) + { + sblock_dirty = 0; /* It doesn't matter if this gets stomped. */ + sync_disk_image (sblock, SBLOCK_SIZE, 1); + } + diskfs_set_hypermetadata (1, 0); +} + /* Sync all allocation information and node NP if diskfs_synchronous. */ inline void alloc_sync (struct node *np) @@ -247,8 +335,7 @@ alloc_sync (struct node *np) diskfs_node_update (np, 1); pokel_sync (&np->dn->pokel, 1); } - diskfs_set_hypermetadata (1, 0); - pokel_sync (&sblock_pokel, 1); + sync_global_data (); } } @@ -262,60 +349,6 @@ int ext2_new_block (unsigned long goal, void ext2_free_blocks (unsigned long block, unsigned long count); /* ---------------------------------------------------------------- */ -/* Bitmap routines. */ - -/* Returns TRUE if bit NUM is set in BITMAP. */ -inline int test_bit (unsigned num, char *bitmap) -{ - return bitmap[num >> 3] & (1 << (num & 0x7)); -} - -/* Sets bit NUM in BITMAP, and returns TRUE if it was already set. */ -inline 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; - } -} - -/* Clears bit NUM in BITMAP, and returns TRUE if it was already clear. */ -inline 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 0; - } - else - return 1; -} - -/* Counts the number of bits unset in MAP, a bitmap NUMCHARS long. */ -unsigned long count_free (char * map, unsigned int numchars); - -extern int find_first_zero_bit(void * addr, unsigned size); - -extern int find_next_zero_bit (void * addr, int size, int offset); - -extern unsigned long ffz(unsigned long word); - -/* Returns a pointer to the first occurence of CH in the buffer BUF of len - LEN, or BUF + LEN if CH doesn't occur. */ -void *memscan(void *buf, unsigned char ch, unsigned len); - -/* ---------------------------------------------------------------- */ /* Write disk block ADDR with DATA of LEN bytes, waiting for completion. */ error_t dev_write_sync (daddr_t addr, vm_address_t data, long len); -- cgit v1.2.3