Ejemplo n.º 1
0
void swap_init(void)
{
	swap_block = block_get_role(BLOCK_SWAP);
	swap_map = bitmap_create(block_size(swap_block)/SECTORS_PER_PAGE);
	bitmap_set_all(swap_map,SWAP_FREE);
	lock_init(&swap_lock);
}
Ejemplo n.º 2
0
struct file *filesys_open (const char *name){
	struct block *block = NULL;
	struct directory *file_desc = NULL;
	struct inode *file_ino = NULL;
	struct file *file = NULL;

	ASSERT(name != NULL);

	// look up device
	block = block_get_role (BLOCK_FILESYS);

	// look up file
	if(block != NULL)
		file_desc = dir_lookup(block,name);

	// look up inode
	if(file_desc != NULL)
		file_ino = ext2_get_inode(block,file_desc->inode);

	// open file
	if(file_ino != NULL)
		file = file_open(block,file_desc,file_ino);

	return file;
}
Ejemplo n.º 3
0
//Initialization function to allocate teh swap table and setup the BLOCK_SWAP
//space on disk to swap memory in and out.
void
swap_init (void)
{
  block_sector_t num_sectors;

  st = malloc(sizeof(struct swap_table));
  if(st == NULL)
    PANIC ("Failed to malloc swap table during swap initialization");

  lock_init(&st->swap_table_lock);

  //Get the block that contains the swap space
  st->swap_block = block_get_role(BLOCK_SWAP);
  if(st->swap_block != NULL)
    num_sectors = block_size(st->swap_block);
  else
  {
    PANIC ("Failed to get block swap space during swap initialization");
  }
  
  //bitmap_create declared in bitmap.h. Allocates correct size.
  st->map = bitmap_create((size_t)num_sectors);
  if(st->map == NULL)
  {
    free(st);
    PANIC ("Failed to create swap bitmap during swap initialization");
  }
}
Ejemplo n.º 4
0
//initialize swap slots list
void swap_init (void)
{
	// only swap once
	if (swap_initialization) {
		return;
	}
	swap_initialization = true;

	swap_block = block_get_role (BLOCK_SWAP);
	if (!swap_block)
	{
		return;
	}

	list_init(&swap_list);
	lock_init(&swap_lock);

	int i = 0;
	for(i; i<(block_size(swap_block) / SECTORS_PER_PAGE); i++)
	{
		struct swap_item * item  = malloc(sizeof(struct swap_item));
		item->available = true;
		item->index = i+1;
		if(item == NULL) return;
		list_push_back(&swap_list, &item->elem);
	}
	return;
}
Ejemplo n.º 5
0
/**
 *Initialize the page swapping related data-structures
 */
void initialize_swap_table ()
{
  swap_partition = block_get_role (BLOCK_SWAP);
  lock_init (&swap_lock);
  // Check if no swap partition is available then swapping is disabled
  if (swap_partition == NULL)
  {
    // meaning that swapping is disabled but programs should still run
    // until there is enough physical memory avaiable
    swap_sectors_btmp = bitmap_create (0);
  } else
  {
    // Create bitmap for total number of page swap sectors
    // (i.e. number of sectors rounded to per-page sectors) in swap partition
    // Total number of swap sectors = (total block-size of swap partition)
    //                                /(per page swap sectors)
    swap_sectors_btmp = bitmap_create (
        block_size (swap_partition) / NUM_OF_PER_PAGE_SECTORS);
  }
  // If unable to create swap sectors bitmap, meaning kernel memory is full - PANIL :(
  if (swap_sectors_btmp == NULL)
  {
    PANIC("Swap Sectors bitmap creation failed!!! :(");
  }
  // Reset all bits in this bitmap - to zero
  bitmap_set_all (swap_sectors_btmp, 0);
}
Ejemplo n.º 6
0
/* Initializes the file system module.
   If FORMAT is true, reformats the file system. */
void
filesys_init (bool format) 
{
  fs_device = block_get_role (BLOCK_FILESYS);
  if (fs_device == NULL)
    PANIC ("No file system device found, can't initialize file system.");
  if (!block_cache_init (&fs_cache, fs_device, FS_CACHE_SIZE,
                         FS_CACHE_IN_USERSPACE))
    PANIC ("Filesys cache could not be intialized.");
  if (!pifs_init (&fs_pifs, &fs_cache))
    PANIC ("PIFS could not be intialized.");

  if (format) 
    {
      printf ("Formatting filesystem with PIFS.\n");
      if (!pifs_format (&fs_pifs))
        PANIC ("Your device is either too big or too small.");
    }
  else
    {
    printf ("Using a PIFS filesystem.\n");
    if (!pifs_sanity_check (&fs_pifs))
      PANIC ("PIFS's basic sanity check failed.");
  }
    
  printf ("Initialized filesystem.\n");
  fs_initialized = true;
}
Ejemplo n.º 7
0
void swap_init (void)
{
  ASSERT (PGSIZE % BLOCK_SECTOR_SIZE == 0);
  blocks_per_page = DIV_ROUND_UP (PGSIZE, BLOCK_SECTOR_SIZE);
  swap_block = block_get_role (BLOCK_SWAP);
  total_swap_size = block_size (swap_block) / blocks_per_page;
  swap_bitmap = bitmap_create (total_swap_size);

  lock_init (&swap_lock);
}
Ejemplo n.º 8
0
//Initializes swap table
void start_swap (void){
  swap_block = block_get_role (BLOCK_SWAP); //Sets the swap role to block
  if (!swap_block)
      return; //Returns if swap is not blocked
  swap_map = bitmap_create( block_size(swap_block) / SECTORS_PER_PAGE ); //Makes a bitmap for swap
  if (!swap_map)
      return; //Returns if there is no swap map
  bitmap_set_all(swap_map, SWAP_FREE); //Calls bitmap with the map and free arguments for swap
  lock_init(&swap_lock); //Calls the lock intialization with the help of swap lock
}
Ejemplo n.º 9
0
void init_swap () {

	lock_init(&swap_lock);

	swap = block_get_role(BLOCK_SWAP);
	//number of sectors each sector is 512kb so we need 8 sectors for one page
	uint32_t size = block_size (swap);

	//create a bitmap that represents the swap table, each entry refers to consecutive blocks that represent one page
	swap_table = bitmap_create (size/SECPP);
}
Ejemplo n.º 10
0
void init_swap(){
	swap_blk = block_get_role(BLOCK_SWAP);
	ASSERT(swap_blk!=NULL);
	uint32_t sectors_num = block_size (swap_blk);
	// each sector is 512K, one page has 8 sectors
	uint32_t slots_num = sectors_num/8;
	size_t bm_pages = DIV_ROUND_UP (bitmap_buf_size (slots_num), PGSIZE);
	uint8_t* base = palloc_get_multiple (PAL_ZERO|PAL_ASSERT, bm_pages);
	swap_table = bitmap_create_in_buf (slots_num, base, bm_pages * PGSIZE);
	lock_init(&swap_lock);
}
Ejemplo n.º 11
0
void swaptable_init(void) {
	swap_block = block_get_role(BLOCK_SWAP);

	lock_init(&swap_lock);

	block_sector_t swapfile_numsectors = block_size(swap_block);
	uint32_t swapfile_numbytes = swapfile_numsectors * BLOCK_SECTOR_SIZE;
	uint32_t swapfile_numpages = swapfile_numbytes / PGSIZE;

	swapmap = bitmap_create(swapfile_numpages);
}
Ejemplo n.º 12
0
/*! Initialize the swap device. */
void swap_init(void) {
    swap_device = block_get_role(BLOCK_SWAP);
    lock_init(&swap_lock);
    if (swap_device == NULL) {
        PANIC("No swap device found, can't initialize the swap partition.");
    }

    /* Initialize the swap hash table. */
    if (!hash_init(&swap_table, &swap_hash_func, &swap_hash_less, NULL)) {
        PANIC("Unable to initialize swap partition hash table.");
    }
}
Ejemplo n.º 13
0
/* Initialize swap device and swap table */
bool swap_init ()
{  
  sp_device = block_get_role (BLOCK_SWAP);
  lock_init (&swap_set_lock);
  /* Bitmap for swap */
  swap_free_map = bitmap_create (block_size (sp_device));
  if (swap_free_map == NULL)
  {
     return false;
  }
  return true;
}
Ejemplo n.º 14
0
void swap_init (void)
{
  swap_block = block_get_role (BLOCK_SWAP);
  if (swap_block == NULL)
    PANIC ("Can't open the swap block");

  list_init (&slot_list);
  list_init (&free_list);
  lock_init (&swap_lock);

  slot_cnt = 0;
  max_slot_cnt = block_size (swap_block) / SECTORS_PER_SLOT;
}
Ejemplo n.º 15
0
/* Sets up swap. */
void swap_init(void) {
	//block from the swap space
	swap_device = block_get_role(BLOCK_SWAP);
	if (!swap_device) {
		return;
	}
	swap_bitmap = bitmap_create(block_size(swap_device) / SECTORS_PER_PAGE);
	if (!swap_bitmap) {
		return;
	}
	bitmap_set_all(swap_bitmap, SWAP_FREE);
	lock_init(&swap_lock);
}
Ejemplo n.º 16
0
/*! Initializes the file system module.
    If FORMAT is true, reformats the file system. */
void filesys_init(bool format) {
    fs_device = block_get_role(BLOCK_FILESYS);
    if (fs_device == NULL)
        PANIC("No file system device found, can't initialize file system.");

    inode_init();
    free_map_init();

    if (format) 
        do_format();

    free_map_open();
}
Ejemplo n.º 17
0
void swap_init(void) {
    lock_init(&swap_lock);
    swap_block = block_get_role(BLOCK_SWAP);
    num_swap_pages = block_size(swap_block) / 8;

    swap_pages = (struct swap_page *) malloc(sizeof(struct swap_page) * num_swap_pages);

    uint32_t i;
    for (i = 0; i < num_swap_pages; i++) {
        swap_pages[i].available = true;
        swap_pages[i].start_sector = i * 8;
    }
}
Ejemplo n.º 18
0
void filesys_init (bool format){
	fs_device = block_get_role(BLOCK_FILESYS);
	if(fs_device == NULL)
		PANIC("No file system device found, can't initialize file system.");

	if(is_ext2(fs_device) == false)
		PANIC("Device file system not recognised!");
	else {
		ext2_init();
		ext2_register(fs_device);
		printf("File system type: ext2.\n");
	}
}
Ejemplo n.º 19
0
void
init_swap_structures (void)
{
  /* Initialise the BLOCK_SWAP device */
  block_device = block_get_role (BLOCK_SWAP);

  /* Calculate how big we need to make the bitmap. Everything is initialised
     to false in the bitmap, which is the default behaviour in the underlying
     ADT */
  size_t size = block_size (block_device) / SECTORS_PER_PAGE;
  if ((swap_slot_map = bitmap_create (size)) == NULL)
      PANIC ("Could not allocate memory for swap table");

}
Ejemplo n.º 20
0
/* initialize swap slot */
void vm_swap_init() {
    swap_slot = block_get_role(BLOCK_SWAP);
    if (!swap_slot)
        PANIC("Swap slot is wrong\n");
    
    size_t bit_cnt = block_size(swap_slot) / SECTORS_PER_PAGE;
    swap_partition = bitmap_create(bit_cnt);
    if (!swap_partition)
        PANIC("Swap partition is wrong\n");

    bitmap_set_all(swap_partition, 0);

    lock_init(&swap_lock);
}
Ejemplo n.º 21
0
/* Initialize the swap table.
   If fail, panic the kernel. */
void 
swap_table_init () 
{
	swap_block = block_get_role (BLOCK_SWAP);
	if (swap_block == NULL)
	  PANIC ("Fail to allocate swap block");
	block_sector_t blk_size = block_size (swap_block);
	// one sector is 512KB, one swap block is 4096KB so it has 8 sectors
	int slot_size = blk_size / 8;  
	swap_table = bitmap_create (slot_size); 
	if (swap_table == NULL)
	  PANIC ("Fail to allocate swap table");
	bitmap_set_all (swap_table, false);
	lock_init (&swap_table_lock);
}
Ejemplo n.º 22
0
void
swap_init (void)
{
  lock_init (&swap_alloc_lock);
  
  swap_block = block_get_role (BLOCK_SWAP);
  if (swap_block != NULL)
    {
      uint32_t page_count = block_size (swap_block) / BLOCKS_PER_PAGE;
      free_blocks = bitmap_create (page_count);
      if (free_blocks == NULL)
        PANIC ("swap_init: unable to create free block bitmap");
      bitmap_set_all (free_blocks, true);
    }
}
Ejemplo n.º 23
0
Archivo: swap.c Proyecto: songhan/CS140
/* Initialize the swap_table */
void swap_table_init (struct swap_table *swap_table)
{
  lock_init ( &swap_table->lock_bitmap);
  lock_init ( &swap_table->lock_swap);
  swap_table->swap_block = block_get_role ( BLOCK_SWAP );
  block_print_stats ();
  if (swap_table->swap_block)
  {
    int pages_in_swap = 
      block_size (swap_table->swap_block) / SECTORS_PER_PAGE;
    swap_table->bitmap = bitmap_create (pages_in_swap);
    /* False means not occupied */
    bitmap_set_all (swap_table->bitmap, false);
    /* The first frame is reserved for stack growth */
    bitmap_set (swap_table->bitmap, 0, true);
  }
}
/* Initializes the file system module.
   If FORMAT is true, reformats the file system. */
void
filesys_init (bool format) 
{
  fs_device = block_get_role (BLOCK_FILESYS);
  if (fs_device == NULL)
    PANIC ("No file system device found, can't initialize file system.");

  inode_init ();
  // XXX Lock Initialize
  lock = (struct lock *)malloc(sizeof(struct lock));
  lock_init(lock);
  // XXX
  free_map_init ();

  if (format) 
    do_format ();

  free_map_open ();
}
Ejemplo n.º 25
0
/* Initializes the file system module.
   If FORMAT is true, reformats the file system. */
void
filesys_init (bool format) 
{
  fs_device = block_get_role (BLOCK_FILESYS);
  if (fs_device == NULL)
    PANIC ("No file system device found, can't initialize file system.");

  lock_init(&globalCacheLock);
  cache_init((struct cache_elem **) &cache);
  clock_hand = CACHE_SIZE - 1;

  inode_init ();
  free_map_init ();

  if (format) 
    do_format ();

  free_map_open ();
}
Ejemplo n.º 26
0
/* Initializes the file system module.
   If FORMAT is true, reformats the file system. */
void
filesys_init (bool format)
{
  fs_device = block_get_role (BLOCK_FILESYS);

  if (fs_device == NULL)
    PANIC ("No file system device found, can't initialize file system.");

  fs_cache = cache_create (fs_device, MAX_CACHE_SIZE);
  if (fs_cache == NULL)
    PANIC ("Cannot create cache for file system");

  inode_init ();
  free_map_init ();

  if (format)
    do_format ();

  free_map_open ();
}
Ejemplo n.º 27
0
/* Initializes the file system module.
   If FORMAT is true, reformats the file system. */
void
filesys_init (bool format)
{
    fs_device = block_get_role (BLOCK_FILESYS);
    if (fs_device == NULL)
        PANIC ("No file system device found, can't initialize file system.");

    inode_init ();
    free_map_init ();
    cache_init ();

    if (format)
        do_format ();

    free_map_open ();

    /* Couldn't add to thread_init because we need inode_init completed
       before we can get access to root directory */
    thread_current ()->cwd_sector = ROOT_DIR_SECTOR;
}
Ejemplo n.º 28
0
/* Initializes the file system module.
   If FORMAT is true, reformats the file system. */
void
filesys_init (bool format) 
{
  fs_device = block_get_role (BLOCK_FILESYS);
  if (fs_device == NULL)
    PANIC ("No file system device found, can't initialize file system.");

  filesys_lock_list = malloc(sizeof(filesys_lock_list) * block_size(fs_device));
    int i;
    for(i=0; i < block_size(fs_device); ++i) {
      lock_init(filesys_lock_list + i);
    }

    inode_init();
    free_map_init();

    if (format) 
        do_format();

  free_map_open ();
}
Ejemplo n.º 29
0
/*! Initializes the swap allocator. */
void swalloc_init(void)
{
    uint32_t i;

    swap_disk = block_get_role(BLOCK_SWAP);
    swap_slots = block_size(swap_disk) / PAGE_SECTORS;

    /* Initialize swap table */
    uint32_t num_pages_used = sizeof(struct swap) * swap_slots;
    num_pages_used = (uint32_t) pg_round_up((void *) num_pages_used) / PGSIZE;

    /* Get pages for swap table */
    swap_list = palloc_get_multiple(PAL_ASSERT | PAL_PAGING | PAL_ZERO, num_pages_used);

    /* Initialize list */
    list_init(open_swap_list);
    /* Initialize swap entries */
    for (i = 0; i < swap_slots; ++i)
    {
        swap_list[i].start_sector = i * PAGE_SECTORS;
        swap_list[i].in_use = false;
        list_push_back(open_swap_list, &(swap_list[i].open_elem));
    }
}
Ejemplo n.º 30
0
static int inode_shrink_range(uint32_t block_id, uint32_t level, uint32_t start, uint32_t end, uint32_t items_per_block,uint32_t l0, uint32_t l1, uint32_t l2, uint32_t l3){
	struct block *d = block_get_role(BLOCK_FILESYS);
	uint32_t item_start, item_end;
	uint32_t *level_data;
	uint32_t block_id2;
	int i, ret = 0;
	enum RANGE range_comparison;

	ASSERT(d != NULL);
	ASSERT(level > 0);

	level_data = ext2_read_block(d,block_id,items_per_block*sizeof(uint32_t),NULL);
	for(i = 0; i < items_per_block; i++){
		// Get Block range the item represents
		if(level == 1){
			item_start = inode_get_direct_block_idx(items_per_block,l0,i,0,0);
			item_end = inode_get_direct_block_idx(items_per_block,l0,i,items_per_block-1,items_per_block-1);
		}
		else if (level == 2){
			item_start = inode_get_direct_block_idx(items_per_block,l0,l1,i,0);
			item_end = inode_get_direct_block_idx(items_per_block,l0,l1,i,items_per_block-1);
		}
		else {
			item_start = inode_get_direct_block_idx(items_per_block,l0,l1,l2,i);
			item_end = item_start;
		}
		// Compare range
		range_comparison = inode_range_compare(item_start,item_end,start,end);
		if((range_comparison & RANGE_OVERLAP) > 0){ // In Range
			block_id2 = level_data[i];

			// If the block is cleared already.
			if(block_id2 == 0) continue;

			/* If it is a leaf node */
			if(item_start == item_end) {
				// free block and set entry to zero
				freemap_free_block(block_id2);
				level_data[i] = 0;
				continue;
			}

			/* If not a leaf node*/

			// free sub level
			if(level == 1)
				inode_shrink_range(block_id2,level+1,start,end,items_per_block,l0,i,0,0);
			else if(level == 2)
				inode_shrink_range(block_id2,level+1,start,end,items_per_block,l0,l1,i,0);
			else
				PANIC("Inode Shrink Range Reach Unexpected Level.\n");

			// if shrink range contains entire level
			if(start <= item_start){
				// free block and set entry to zero
				freemap_free_block(block_id2);
				level_data[i] = 0;
			}
		}
		else if((range_comparison & RANGE_AHEAD) > 0){ //Item Ahead of start
			continue;
		}
		else{ // Item Passed End
			break;
		}
	}
	ext2_write_block(d,block_id,items_per_block*sizeof(uint32_t),level_data);
	kfree(level_data);

	return ret;
}