Exemple #1
0
static int isNameUnique (uint fsdev, dinode_t *dinode, char *name, u_int namelen)
{
   int i;
   for (i=0; i<NUM_DIRECT; i++) {
      if (dinode->directBlocks[i]) {
         struct bc_entry *buf = bc_lookup (fsdev, dinode->directBlocks[i]);
         if (buf == NULL) {
            printf ("WARN: isNameUnique fails because one of the directory blocks is not resident.\n");
         } else if (nameconflict ((char *) (KERNBASE + (((u32)buf->buf_ppn) << PGSHIFT)), name, namelen)) {
            printf ("name conflict found\n");
            return (0);
         }
      }
   }
   return (1);
}
Exemple #2
0
bool bc_read(block_sector_t sector_idx, void *buffer, off_t bytes_read, int chunck_size, int sector_ofs)
{
	/* find the buffer cache entry of which block_sector_t is equal to sector_idx */
	struct buffer_head *sector_buffer = bc_lookup(sector_idx);
	/* if can't find the buffer cache entry */
	if(sector_buffer == NULL)
	{
		sector_buffer = bc_select_victim();
		/* update buffer_head and read the data from disk */
		sector_buffer->sector    = sector_idx;
		sector_buffer->is_used   = true;
		block_read(fs_device, sector_idx, sector_buffer->data);
	}
	/* updata the clock bit */
	sector_buffer->clock_bit = true;
	/* read data from buffer cache */
	memcpy(buffer + bytes_read, sector_buffer->data + sector_ofs, chunck_size);
	return true;
}
Exemple #3
0
bool bc_write(block_sector_t sector_idx, void *buffer, off_t bytes_written, int chunck_size, int sector_ofs)
{
	/* find the buffer cache entry of which block_sector_t is equal to sector_idx */
	struct buffer_head *sector_buffer = bc_lookup(sector_idx);
	/* if can't find the buffer cache entry */
	if(sector_buffer == NULL)
	{
		sector_buffer = bc_select_victim();
		/* update buffer_head and read the data from disk */
		sector_buffer->sector  = sector_idx;
		sector_buffer->is_used = true;
		block_read(fs_device, sector_idx, sector_buffer->data);
	}
	/* write the data to buffer_cache */
	memcpy(sector_buffer->data + sector_ofs, buffer + bytes_written, chunck_size);
	/* update the */
	lock_acquire(&sector_buffer->buffer_lock);
	sector_buffer->clock_bit = true;
	sector_buffer->dirty     = true;
	lock_release(&sector_buffer->buffer_lock);
	return true;  
}
Exemple #4
0
void bc_check(char *msg, db_t db) {
	printf("msg = %s\n", msg);
	if(bc_lookup(XN_DEV, db))
		printf("db %ld: in bc %p\n", db, bc_lookup(XN_DEV, db));
}