Ejemplo n.º 1
0
/*===========================================================================*
 *				get_list_used	     *
 *===========================================================================*/
int* get_list_used(bitchunk_t *bitmap, int type)
{
	/* Get a list of unused blocks/inodes from the zone/inode bitmap */
	int* list;
	int nblk;
	int tot;
	bitchunk_t *buf;
	char* chunk;
	NB_USED = 0;
	if (type == IMAP){
		nblk = N_IMAP;
		tot  = NB_INODES;
		list = malloc(sizeof(int)*NB_INODES);
		printf("Used Inodes\n");
	}
	else /* type == ZMAP */ {
		nblk = N_ZMAP;
		tot  = NB_ZONES;
		list = malloc(sizeof(int)*NB_ZONES);
		printf("Used Blocks\n");
	}
	sleep(1);
	printf("\n\n");
	/* Loop through bitchunks in bitmap */
	for (int j = 0; j < FS_BITMAP_CHUNKS(BLK_SIZE)*nblk; ++j){
		chunk = int2binstr(bitmap[j]);
		/* Loop through bits in bitchunk */
		for (int k = 0; k < strlen(chunk); ++k){
			if (chunk[k] == '1'){
				list[NB_USED] = j*FS_BITCHUNK_BITS + k;
				printf("%d, ", list[NB_USED]);
				if (NB_USED % 5 == 0){
					printf("\n");
				}
				++NB_USED;
			}
		}
	}
	if (type == IMAP)    NB_INODES_USED  = NB_USED;
	else/*(type==ZMAP)*/ NB_ZONES_USED_Z = NB_USED;
	printf("\n\n");
	printf("Used: %d / %d \n", NB_USED, tot);
	return list;
}
Ejemplo n.º 2
0
int err_code;		/* temporary storage for error number */

int cch[NR_INODES];

kipc_msg_t fs_m_in;
kipc_msg_t fs_m_out;

uid_t caller_uid;
gid_t caller_gid;
int req_nr;
int SELF_E;
int exitsignaled;
int busy;

/* Inode map. */
bitchunk_t inodemap[FS_BITMAP_CHUNKS(NR_INODES)]; 

struct pipe_inode inode[NR_INODES];

/* list of unused/free inodes */
struct unused_inodes_t unused_inodes;

/* inode hashtable */
struct inodelist hash_inodes[INODE_HASH_SIZE];

struct buf *front;	/* points to least recently used free block */
struct buf *rear;	/* points to most recently used free block */
int bufs_in_use;	/* # bufs currently in use (not on free list)*/

struct driver_endpoints driver_endpoints[NR_DEVICES];
Ejemplo n.º 3
0
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");
}