Beispiel #1
0
void init_inode_store (dev_s *dev)
{
    FN;
    init_tree( &Inode_tree, &Inode_species, dev);

    init_super_block();
}
Beispiel #2
0
int fs_format()
{
  if(mb.magic == FS_MAGIC) {
    printf("Refusing to format a mounted disk\n");
    return -1;
  }

  disk_read(0, (char *)&mb);
  if(mb.magic == FS_MAGIC){
    printf("Refusing to format a formatted disk!\n");
    mb.magic = 0;
    return -1;
  }

  //Format disk
  init_super_block();
  init_empty_dir();
  
  //Flush
  disk_write(0, (char*)&mb);
  disk_write(1, (char*)dir);

  mb.magic = 0; // mark disk as unmounted

  return 0;
}
Beispiel #3
0
void init_string (tree_s *tree, log_s *log)
{
	bind_tree_log(log, TREE_SLOT);
	init_tree(tree, &String_species, log->lg_sys, log, TREE_SLOT);
	add_slot_log(log, STRING_SLOT, String_redo);

	init_super_block(tree);
}
Beispiel #4
0
static void mkfs(){
    MESSAGE message;
    
    HD_PART_INFO part_info;
    message.type=INFO_FS_IOCTL;
    message.subtype=DIOCTL_GET_PART_INFO;
    message.device=ROOT_DEVICE;//-------------需要指定到具体分区--------------------
    message.arg_pointer=(void*)&part_info;
    message.source_pid=TASK_FS;
    assert(dd_map[DRIVER(message.device)].driver_pid!=PID_INVALID,"driver not exist!");
    send_receive(BOTH,dd_map[DRIVER(message.device)].driver_pid,&message);
    
#ifdef DEBUG_FS
    printl("device=%d base=%d size=%d (in sector)\n",DEVICE(message.device),part_info.base,part_info.size);
#endif

    SUPER_BLOCK sb;
    //super block
    int super_block_first_index=get_super_block_first_index();
    init_super_block(&sb,super_block_first_index,part_info.size);
#ifdef DEBUG_FS
    printl("init_super_block ok(start_sector=%d)\n",super_block_first_index);
#endif
    //imap
    /* int imap_first_index=super_block_first_index+SUPER_SECTORS_LENGTH; */
    int imap_first_index=get_imap_first_index(sb);
    int imap_sectors_length=get_imap_length(sb)/* sb.imap_sectors_length */;
    init_imap(imap_first_index,imap_sectors_length);
#ifdef DEBUG_FS
    printl("init_imap ok(start_sector=%d)\n",imap_first_index);
#endif
    //smap
    /* int smap_first_index=imap_first_index+imap_sectors_length; */
    int smap_first_index=get_smap_first_index(sb);
    int smap_sectors_length=get_smap_length(sb)/* sb.smap_sectors_length */;
    init_smap(smap_first_index,smap_sectors_length);
#ifdef DEBUG_FS
    printl("init_smap ok(start_sector=%d)\n",smap_first_index);
#endif
    //inode
    /* int inode_first_index=smap_first_index+smap_sectors_length; */
    int inode_first_index=get_inode_first_index(sb);
    /* int inode_sectors_length=get_inode_length(sb)/\* sb.inodes_sectors_length *\/; */
    int root_dir_start_index=get_data_block_first_index(sb)/* sb.data_first_sector_index */;
    init_inode(inode_first_index,root_dir_start_index);    
#ifdef DEBUG_FS
    printl("init_inode ok(start_sector=%d)\n",inode_first_index);
#endif
    //data
    /* int data_block_first_index=inode_first_index+inode_sectors_length; */
    int data_block_first_index=get_data_block_first_index(sb);
    init_data_block(data_block_first_index);
#ifdef DEBUG_FS
    printl("init_data_block ok(start_sector=%d)\n",data_block_first_index);
#endif
}
Beispiel #5
0
void set_defaults(void) {

    char param_value[LINE_MAX + 1];
    get_param("INSTR_SLICE", param_value);
    instr_slice = atoi(param_value);

    int heads, tracks, sectors;
    char command[1000];
    get_param("NUM_HEADS", param_value);
    heads = atoi(param_value);
    get_param("NUM_TRACKS", param_value);
    tracks = atoi(param_value);
    get_param("NUM_SECTORS", param_value);
    sectors = atoi(param_value);
    FILE* check = fopen("Sim_disk", "r");
    if(check != NULL) {
        disk_file_pointer = fopen("Sim_disk", "rb+");
        read_super_block();
        init_cache();
        fclose(check);
    }
    else {
        total_blocks_virtual_mem = (heads * tracks * sectors) / 8;
        blocks_in_track = total_blocks_virtual_mem / tracks;
        prev_track = 0;
        disk_block_data = (int *) malloc(total_blocks_virtual_mem * sizeof(int));
        int i = 0;
        for (i = 0; i < total_blocks_virtual_mem; i++)
            disk_block_data[i] = -1;
        sprintf(command,
                "(dd if=/dev/zero of=Sim_disk bs=%dx%dx%db count=1) 2> /dev/zero",
                heads, tracks, sectors);
        system(command);
        disk_file_pointer = fopen("Sim_disk", "rb+");
        init_super_block();
        init_cache();
    }
}
Beispiel #6
0
static void format_disk(char *disk, struct lmfs_address *addr, int files)
{
	u32 ib_size = 0;
	u32 db_size = 0;
	u32 inode_size = 0;
	u32 sb_size = 0;
	u32 block_cnt = (MAX_SIZE / BLOCK_SIZE);
	u32 data_start_block;
	u32 free_block;

	sb_size = BLOCK_SIZE;
	ib_size = baligin((sizeof(u32) * files), BLOCK_SIZE);
	inode_size = baligin(512 *files, BLOCK_SIZE);
	db_size = block_cnt - ((ib_size + inode_size + sb_size) / BLOCK_SIZE);
	db_size = baligin(sizeof(u32) *files, BLOCK_SIZE);

	addr->p_sb = (struct lmfs_super_block *)disk;
	addr->p_ib = (u32 *)(disk + sb_size);
	addr->p_db = (u32 *)(disk + sb_size + ib_size);
	addr->p_inode = disk + sb_size + ib_size + db_size;
	addr->p_data = disk + sb_size + ib_size + db_size + inode_size;
	addr->sb_size = sb_size;
	addr->ib_size = ib_size;
	addr->db_size = db_size;
	addr->inode_size = inode_size;

	data_start_block = (addr->p_data - disk) / BLOCK_SIZE;
	free_block = block_cnt - data_start_block;

	printf("p_sb:0x%x p_ib:0x%x p_db:0x%x p_inode:0x%x p_data:0x%x\n",
	       addr->p_sb, addr->p_ib, addr->p_db, addr->p_inode, addr->p_data);
	printf("block_cnt:%d, free_block:%d data_start_block:%d\n",
			block_cnt, free_block, data_start_block);

	(void)init_super_block(addr, data_start_block, free_block, block_cnt);
}
Beispiel #7
0
void init_string (tree_s *tree, log_s *log)
{
	init_tree(tree, &String_species, log->lg_sys, log);

	init_super_block(tree);
}
int32_t ofs_create_container_nolock(const char *ct_name, uint64_t total_sectors, container_handle_t **ct)
{
    container_handle_t *tmp_ct = NULL;
    int32_t ret = 0;
    avl_index_t where = 0;

    if ((ct == NULL) || (total_sectors == 0) || (ct_name == NULL))
    {
        LOG_ERROR("Invalid parameter. ct(%p) total_sectors(%lld) ct_name(%p)\n", ct, total_sectors, ct_name);
        return -INDEX_ERR_PARAMETER;
    }
    
    if (strlen(ct_name) >= OFS_NAME_SIZE)
    {
        LOG_ERROR("file name size must < %d bytes.\n", OFS_NAME_SIZE);
        return -INDEX_ERR_PARAMETER;
    }
    
    LOG_INFO("Create the ct. ct_name(%s) total_sectors(%lld)\n", ct_name, total_sectors);

    /* already opened */
    tmp_ct = avl_find(g_container_list, (avl_find_fn_t)compare_container2, ct_name, &where);
    if (tmp_ct)
    {
        *ct = tmp_ct;
        LOG_WARN("The ct is opened already. ct_name(%s) start_lba(%lld)\n", ct_name);
        return -INDEX_ERR_IS_OPENED;
    }

    /* allocate resource */
    ret = init_container_resource(&tmp_ct, ct_name);
    if (ret < 0)
    {
        LOG_ERROR("Init ct resource failed. ct_name(%s) ret(%d)", ct_name, ret);
        return ret;
    }
    
    /* init super block */
    ret = init_super_block(&tmp_ct->sb, total_sectors, BYTES_PER_BLOCK_SHIFT);
    if (ret < 0)
    {
        LOG_ERROR("init super block failed. name(%s)\n", ct_name);
        close_container(tmp_ct);
        return ret;
    }

    ret = os_disk_create(&tmp_ct->disk_hnd, ct_name);
    if (ret < 0)
    {
        LOG_ERROR("init disk failed. ret(%d)\n", ret);
        close_container(tmp_ct);
        return ret;
    }

    ret = ofs_init_super_block(tmp_ct);
    if (ret < 0)
    {
        LOG_ERROR("Update super block failed. ct_name(%s) vbn(%lld) ret(%d)\n", ct_name, SUPER_BLOCK_VBN, ret);
        close_container(tmp_ct);
        return ret;
    }
    
    ret = create_system_objects(tmp_ct);
    if (ret < 0)
    {
        LOG_ERROR("create system objects failed. ct_name(%s) ret(%d)\n", ct_name, ret);
        close_container(tmp_ct);
        return ret;
    }
    
    ret = ofs_update_super_block(tmp_ct);
    if (ret < 0)
    {
        LOG_ERROR("Update super block failed. hnd(%p) ret(%d)\n", tmp_ct, ret);
        close_container(tmp_ct);
        return ret;
    }

    *ct = tmp_ct;

    LOG_INFO("Create the ct success. ct_name(%s) total_sectors(%lld) ct(%p)\n", ct_name, total_sectors, tmp_ct);
    
    return 0;
}