Exemplo n.º 1
0
static void
free_block(uint32_t blockno)
{
	/* EXERCISE: Your code here */
  //might want to add in functionality so that it skips all inode blocks
	int min_blocks = ospfs_super->os_firstinob;
	void *bitmap = ospfs_block(OSPFS_FREEMAP_BLK);
	if(blockno > min_blocks && blockno < OSPFS_MAXFILEBLKS){
		if(bitvector_test(bitmap, blockno) == 0){
			bitvector_set(bitmap, blockno);		
		}
	}
}
Exemplo n.º 2
0
static uint32_t
allocate_block(void)
{
	/* EXERCISE: Your code here */
	uint32_t i; 
	for(i = 1; i < ospfs_super->os_nblocks; i++){
		if(bitvector_test(ospfs_block(OSPFS_FREEMAP_BLK),i)){
			bitvector_clear(ospfs_block(OSPFS_FREEMAP_BLK),i);
			return i;
		}
	}
	return 0;
}
Exemplo n.º 3
0
static uint32_t
allocate_block(void)
{
	void *bitmap = ospfs_block(OSPFS_FREEMAP_BLK);

	int i; // iterate through bitmap vector and return first free block
	for (i = 0; i < ospfs_super->os_nblocks; i++) {
		if (bitvector_test(bitmap, i)) {
			bitvector_clear(bitmap, i); // mark as used (set i bit to 0)
			return i;
		}
	}

	return 0;
}
Exemplo n.º 4
0
static uint32_t
allocate_block(void)
{
	/* DONE: Your code here */
	int bits_in_bitmap = ospfs_super->os_nblocks;	// also is the number of blocks in our entire FS
	int x;
	void* bitvector = ospfs_block(OSPFS_FREEMAP_BLK);
	for (x = 0; x < bits_in_bitmap; x++) {
		if (bitvector_test(bitvector, x)) {
			bitvector_clear(bitvector, x);
			return x;
		}
	}
	return 0;
}
Exemplo n.º 5
0
static uint32_t
allocate_block(void)
{
	int i;
	/* EXERCISE: Your code here */
	void *free_map = ospfs_block(OSPFS_FREEMAP_BLK);

	for (i = OSPFS_FREEMAP_BLK; i < ospfs_super->os_nblocks; i++) {
		if (bitvector_test(free_map, i)) {
			bitvector_clear(free_map, i);
			break;
		}
	}

	return (i == ospfs_super->os_nblocks) ? 0 : i;
}
Exemplo n.º 6
0
static uint32_t
allocate_block(void)
{
	/* EXERCISE: Your code here */
	
	void *bitmap = ospfs_block(OSPFS_FREEMAP_BLK);

	//check for free blocks. 0-2 blocks are always reserved so start at 3.
	int i;
	for(i = OSPFS_FREEMAP_BLK+1; i < ospfs_super->os_nblocks; i++){
			if(bitvector_test(bitmap, i) == 1){
				bitvector_clear(bitmap, i);
				return i;					
			}
	}
	return 0;
}
Exemplo n.º 7
0
static uint32_t
allocate_block(void)
{
	/* EXERCISE: Your code here */
	int i;
	for (i = OSPFS_FREEMAP_BLK; i < ospfs_super->os_firstinob; i++) {
		char *bitvector = ospfs_block(i);
		int j = 0;
		for (j = 0; j < OSPFS_BLKBITSIZE; j++) {
			if (bitvector_test(bitvector, j)) {
				bitvector_clear(bitvector, j);
				return (i - OSPFS_FREEMAP_BLK) * OSPFS_BLKBITSIZE + j;
			}
		}
	}
	return 0;
}
Exemplo n.º 8
0
static uint32_t
allocate_block(void)
{
	/* EXERCISE: Your code here */ 
	// "First block in free block" is line 61 in ospfs.h as "OSPFS_FREEMAP_BLK 2
	void* input_bitmap = ospfs_block(OSPFS_FREEMAP_BLK);
    
	//initialize blocknumber, starting at OSPFS_FREEMAP_BLK + 1 (next block after allocation)
	int blocknumber = OSPFS_FREEMAP_BLK+1;
	int upperlimit = ospfs_super->os_nblocks; //most blocks we can go
    
	//if test(blocknumber) returns 1, then clear the corresponding blocknumber
	//do this for every blocknumber
	while (blocknumber < upperlimit) {
    	if (bitvector_test(input_bitmap, blocknumber)) {
        	bitvector_clear(input_bitmap, blocknumber);
        	return blocknumber;
    	}
    	blocknumber++;
	}
	return 0;
}
Exemplo n.º 9
0
static uint32_t
allocate_block(void)
{
	void *bitmap = ospfs_block(OSPFS_FREEMAP_BLK);
	/* EXERCISE: Your code here */
	//void *allo_block = NULL;
	int i = 2;
	while(i<ospfs_super->os_nblocks)
	{
		// bitvector_test -- Return the value of the 'i'th bit of 'vector'.
			if(bitvector_test(bitmap,i)==1)//the corresponding block is free
			{
				// bitvector_clear -- Set 'i'th bit of 'vector' to 0.
				bitvector_clear(bitmap,i);
				//allo_block = ospfs_block(i);
				return i;
				//break;
			}
		i++;
	}

	return 0;
}
Exemplo n.º 10
0
static uint32_t
allocate_block(void)
{
	//SQ allocate
	void* bitmap = &ospfs_data[OSPFS_FREEMAP_BLK];

	unsigned size_of_bitmap_bits = (ospfs_super->os_nblocks);
	//unsigned nblocks_in_bitmap = ospfs_size2nblocks(ospfs_super_t->os_nblocks/8);

	//offset to ignore superblock and boot sector block
	//OSPFS_FREEMAP_BLK= 2 where the bitmap begins
	uint32_t i;
	for(i = 0; i < size_of_bitmap_bits; i++)
	{
		if(bitvector_test(bitmap, i) == 1) {
			bitvector_clear(bitmap, i);
			return i;
		}
	}
	//end SQ allocate
	/* EXERCISE: Your code here */
	return 0;
}