/* Insert one bit into the bitmap */ void insert_bit(block_t map, bit_t bit) { int boff, w, s; unsigned int bits_per_block; block_t map_block; bitchunk_t *buf; buf = alloc_block(); bits_per_block = FS_BITS_PER_BLOCK(block_size); map_block = map + bit / bits_per_block; if (map_block >= inode_offset) pexit("insertbit invades inodes area - this cannot happen"); boff = bit % bits_per_block; assert(boff >=0); assert(boff < FS_BITS_PER_BLOCK(block_size)); get_block(map_block, buf); w = boff / FS_BITCHUNK_BITS; s = boff % FS_BITCHUNK_BITS; buf[w] |= (1 << s); put_block(map_block, buf); free(buf); }
/* The above comment doesn't all apply now bit_t is long. Overflow is now * unlikely, but negative bit counts are now possible (though unlikely) * and give silly results. */ int bitmapsize(u32 nr_bits, int block_size) { int nr_blocks; nr_blocks = (int) (nr_bits / FS_BITS_PER_BLOCK(block_size)); if (((u32) nr_blocks * FS_BITS_PER_BLOCK(block_size)) < nr_bits) ++nr_blocks; return(nr_blocks); }
/* * copied from fslib */ static int bitmapsize(bit_t nr_bits, size_t blk_size) { block_t nr_blocks; nr_blocks = nr_bits / FS_BITS_PER_BLOCK(blk_size); if (nr_blocks * FS_BITS_PER_BLOCK(blk_size) < nr_bits) ++nr_blocks; return(nr_blocks); }
int grsIntFrag() { printf("\n======================================================\n"); printf("\n System Call Invoked : grsIntFrag \n"); struct super_block* sp; unsigned int in_numbs[100] = {0}; struct inode *rip; block_t start_block; /* first bit block */ block_t block; bit_t map_bits; /* how many bits are there in the bit map? */ short bit_blocks; /* how many blocks are there in the bit map? */ bit_t origin = 1; /* number of bit to start searching at */ int c = 0, n = 0, d = 0, count =0, j=0, frag_cnt =0 , scale =0; unsigned word, bcount; struct buf *bp; bitchunk_t *wptr, *wlim, k; bit_t i, b; sp = get_super(fs_dev); c = read_super(sp); printf("The block sz currently in use : %d\n",sp->s_block_size); if(sp->s_log_zone_size == 0) { printf("One block/zone on this filesystem. So no external fragmentation\n"); return 0; } start_block = START_BLOCK; map_bits = (bit_t) (sp->s_ninodes + 1); bit_blocks = sp->s_imap_blocks; /* Locate the starting place. */ block = (block_t) (origin / FS_BITS_PER_BLOCK(sp->s_block_size)); word = (origin % FS_BITS_PER_BLOCK(sp->s_block_size)) / FS_BITCHUNK_BITS; bcount = bit_blocks; while(bcount > 0) { bp = get_block(sp->s_dev, start_block + block, NORMAL); assert(bp); wlim = &bp->b_bitmap[FS_BITMAP_CHUNKS(sp->s_block_size)]; /* Iterate over the words in block. */ for (wptr = &bp->b_bitmap[word]; wptr < wlim; wptr++) { /* Does this word contain a free bit? */ if (*wptr == (bitchunk_t) 0) continue; k = (bitchunk_t) conv4(sp->s_native, (int) *wptr); for (i = 0; i < 8*sizeof(k); ++i) { /* Bit number from the start of the bit map. */ b = ((bit_t) block * FS_BITS_PER_BLOCK(sp->s_block_size)) + (wptr - &bp->b_bitmap[0]) * FS_BITCHUNK_BITS + i; /* Don't count bits beyond the end of the map. */ if (b >= map_bits) { break; } if ((k & (1 << i)) == 1) { in_numbs[n++] = b; } } if (b >= map_bits) break; } ++block; word = 0; --bcount; } for(n=0;in_numbs[n]!=0;n++) { rip = get_inode(fs_dev, in_numbs[n]); scale = rip->i_sp->s_log_zone_size; for(j=0;j<7;j++) { b = (block_t)rip->i_zone[7] << scale; bp = get_block(rip->i_dev,b,NORMAL); count = (rip->i_sp->s_block_size)/32; for(d=0;d<count;d++) { if(bp->b_v1_ind[d] == NO_ZONE) { frag_cnt = get_internal_frag(bp->b_v1_ind[d],scale); } } } } print_internal_frag_report(); return 0; printf("\n======================================================\n"); }