Пример #1
0
/*************************************
 *store the current checkpoint
 *increase generation number in superblock
 *update lastblock and lastentry
 *return 0 on success
 *return -1 indicating no enough space for checkpoint
 **************************************/
int StorageLog::checkpoint(int fd) {
  if(checkspace(edge_list) == -1) {
    return -1;
  }
  unsigned char* superblock_pt;
  ssize_t freeresult;
  superblock_pt = get_superblock(fd);
  Superblock* pt = (Superblock*) superblock_pt;
  if(isValid(superblock_pt)) {
    int storeresult = storegraph(pt->logsize, fd, edge_list);
    if(storeresult < 0) {
      printf("store checkpoint failed in checkpoint, too large\n");
      return -1;
    }
  }
  else {
    printf("superblock is invalid in checkpoint\n");
    exit(-1);
  }
  pt->generation++;
  update_checksum_super(superblock_pt);
  write_superblock(fd, superblock_pt); 
  lastblock = LOGSTARTBLOCK;
  lastentry = 0;

  freeresult = munmap(superblock_pt, PAGESIZE); 
  if(freeresult < 0) {
    printf("free superblock failed in checkpoint\n");
  }
  return 0;
}
Пример #2
0
int main(int argc, char *argv[])
{
	FILE *f;
	struct superblock sb;
	struct inode inode;

	if (argc < 3) {
		printf("Usage: %s <image file> <inode #>\n", argv[0]);
		return 1;
	}

	f = fopen(argv[1], "r");
	if (f == NULL) {
		perror("fopen");
		return 1;
	}

	if (get_superblock(f, &sb))
		return 1;

	// Fetch the specified inode
	if (get_inode(&sb, strtoul(argv[2], NULL, 0), &inode))
		return 1;

	// Print out the data contained in the inode
	if (print_inode_data(&sb, &inode))
		return 1;

	fclose(f);
	return 0;
}
Пример #3
0
//write the next available entry on log
//update lastblock and lastentry
//return 0 on success
//return -1 on log full
int StorageLog::update_log(uint32_t method, u64 node1, u64 node2) {
  if(lastblock >= MAXBLOCKNUM) {
    printf("maximum block num reached in update_log\n");
    return -1;
  }
  uint32_t generation;
  unsigned char* superblock_pt;
  ssize_t freeresult;
  superblock_pt = get_superblock(fd);
  Superblock* pt = (Superblock*) superblock_pt;
  if(isValid(superblock_pt)) {
    generation = pt->generation;
  }
  else {
    printf("superblock is invalid in update_log\n");
    exit(-1);
  }
  freeresult = munmap(superblock_pt, PAGESIZE); 
  if(freeresult < 0) {
    printf("free superblock failed in update_logp\n");
  }

  Requestentry entry;
  entry.method = method;
  entry.node1 = node1;
  entry.node2 = node2;
  printf("Before updating log entry: \n");
  update_log_entry(fd, lastblock, lastentry, entry, generation);
  update_tail(lastblock, lastentry);
  return 0;
}
Пример #4
0
void StorageLog::format(int fd) {
  printf("Formatted\n");
  unsigned char* superblock_pt;
  int freeresult;
  //update superblock
  superblock_pt = get_superblock(fd);
  Superblock* pt = (Superblock*) superblock_pt;
  if(isValid(superblock_pt)) {
    pt->generation++;
    pt->logstart = LOGSTARTBLOCK; // which block
    pt->logsize = MAXLOGBLOCKNUM; // which block
  }
  else {
    pt->generation = 0;
    pt->logstart = LOGSTARTBLOCK; // which block
    pt->logsize = MAXLOGBLOCKNUM; // which block
  }
  update_checksum_super(superblock_pt);
  //printf("update_checksum_super finished\n");
  write_superblock(fd, superblock_pt);
  //printf("write_super finished\n");

  //clear check point
  edge_list.clear();
  //printf("edge_list cleared\n");
  assert(edge_list.empty());
  //printf("edge_list empty asserted\n");
  storegraph(pt->logsize, fd, edge_list);
  //printf("graph stored\n");
  //free in memory superblock
  freeresult = munmap(superblock_pt, PAGESIZE); 
  if(freeresult == -1) {
    printf("free superblock memory block failed in format\n");
  }
}
Пример #5
0
int main(int argc, char *argv[])
{
	FILE *f;
	struct superblock sb;

	if (argc < 3) {
		printf("Usage: %s <image file> <block #>\n", argv[0]);
		return 1;
	}

	f = fopen(argv[1], "r");
	if (f == NULL) {
		perror("fopen");
		return 1;
	}

	if (get_superblock(f, &sb))
		return 1;

	// Print the allocation status of the given block.
	switch (is_block_free(&sb, strtoul(argv[2], NULL, 0))) {
		case 0:
			printf("allocated\n");
			break;
		case 1:
			printf("free\n");
			break;
		default:
			printf("error\n");
			return 1;
	}

	fclose(f);
	return 0;
}
Пример #6
0
int init_ext_introspection(int fd, int fs) {
	char *buf;
	int i;
	struct ext_superblock_t superblock;
	//struct sinode_t *sinode;
	// get initialized time
	time_t before, after;
	before = time(NULL);

	if (posix_memalign((void **) &buf, DOM0BLOCKSIZE, DOM0BLOCKSIZE) != 0) {
		return -1;
	}
	
	if (get_superblock(&superblock, fd, buf, DOM0BLOCKSIZE, fs)) {
		printf("get superblock error.\n");
	}

	free(buf);

	dump_superblock(&superblock);

	after = time(NULL);
	after -= before ;//prevent warning
	printf("time consumed:%lu\n", after);

	return 0;
}
Пример #7
0
/*
 * Init the fs
 */
void _fs_ext2_init(void) {

    xinu_fs = (struct ext2_filesystem*)mem_lower_bound;
    mem_lower_bound += sizeof( struct ext2_filesystem );
    xinu_fs->sb = get_superblock( VIRT_MEM_LOCATION );
    xinu_fs->base_addr = (uint32) VIRT_MEM_LOCATION;

}
Пример #8
0
IDL4_INLINE CORBA_long filesystem_mount_implementation(CORBA_Object _caller, CORBA_long objID, l4_threadid_t *msvrID, CORBA_long mobjID, idl4_server_environment *_env)

{
  handle_t bdev;  // Handle for Blockdevice
  if (mounted) return EEXISTS;
  
  bdev.svr=*msvrID;
  bdev.obj=mobjID;
  int value = get_superblock(bdev);
  mounted=true;
  return value;
}
Пример #9
0
// has a redzone
static void* custom_alloc(int size)
{
#define RZ  8
   static void* hp     = 0;    // current heap pointer
   static void* hp_lim = 0;    // maximum usable byte in current block
   int          size2  = size + RZ*2;
   void*        p;

   if (hp + size2 > hp_lim) {
      hp = get_superblock();
      hp_lim = hp + SUPERBLOCK_SIZE - 1;
   }  

   p = hp + RZ;
   hp += size2;

   VALGRIND_MALLOCLIKE_BLOCK( p, size, RZ, /*is_zeroed*/1 );
   return (void*)p;
}     
Пример #10
0
void StorageLog::on_start_up(int fd) {
  unsigned char* superblock_pt;
  ssize_t freeresult;
  superblock_pt = get_superblock(fd);
  Superblock* pt = (Superblock*) superblock_pt;
  if(isValid(superblock_pt)) {
    edge_list = readgraph(pt->logsize, fd);
    play_log(fd, pt->generation);
    print_graph(edge_list);
  }
  else {
    printf("superblock is invalid on startup\n");
    exit(-1);
  }
  printf("one_start_up, edge_list is of size: %lu\n", edge_list.size());
  freeresult = munmap(superblock_pt, PAGESIZE); 
  if(freeresult < 0) {
    printf("free superblock failed in on_start_up\n");
  }
}
Пример #11
0
int main(int argc, char *argv[])
{
	FILE *f;
	struct superblock sb;
	int i, len;
	char *block;

	if (argc < 3) {
		printf("Usage: %s <image file> <search string>\n", argv[0]);
		return 1;
	}

	f = fopen(argv[1], "r");
	if (f == NULL) {
		perror("fopen");
		return 1;
	}

	if (get_superblock(f, &sb))
		return 1;

	block = malloc(blocksize(&sb));
	if (block == NULL)
		return 1;

	// Search free blocks
	len = strlen(argv[2]);
	for (i = 0; i < sb.s_blocks_count; i++) {
		if (!is_block_free(&sb, i))
			continue;
		if (get_block_data(&sb, i, block))
			return 1;
		if (!strncmp(argv[2], block, len))
			printf("%d\n", i);
	}

	free(block);
	fclose(f);
	return 0;
}