Exemplo n.º 1
0
/*
新建文件:
1.分配inode,设置imap
2.分配data_sector,设置smap
3.新建目录项,更新目录项内容(inode_index,filename)
4.新建inode,更新inode的内容
*/
static int create_file(const char *dir_name,const char *file_name,int file_type){
    int inode_index=alloc_imap_bit(0);
    if(inode_index<0){
        set_error_index(IMAP_NOT_ENOUGH);
        return -1;
    }
#ifdef DEBUG_FS
    printl("inode_index=%d(in create_file)\n",inode_index);
#endif

    int data_index=alloc_smap_bit(0,DEFAULT_FILE_SECTOR_LENGTH);//相对于数据区的sector_index
    if(data_index<0){
        set_error_index(SMAP_NOT_ENOUGH);
        return -1;
    }
#ifdef DEBUG_FS
    printl("data_index=%d(in create_file)\n",data_index);
#endif
    data_index+=get_data_block_first_index(super_block);//绝对sector_index
#ifdef DEBUG_FS
    printl("data_index=%d(in create_file)\n",data_index);
#endif


    if(!new_dir_entry(dir_name,inode_index,file_name)){
        set_error_index(DIR_CREATE_ERROR);
        return -1;
    }

    if(!new_inode(inode_index,file_type,data_index,DEFAULT_FILE_SECTOR_LENGTH)){
        set_error_index(INODE_CREATE_ERROR);
        return -1;
    }
    return inode_index;
}
Exemplo n.º 2
0
Arquivo: open.c Projeto: Zach41/OS
PRIVATE struct inode* create_file(char* path, int flags) {
    char filename[MAX_PATH];
    struct inode* dir_inode;

    if (strip_path(filename, path, &dir_inode) != 0)
	return 0;
    int inode_nr = alloc_imap_bit(dir_inode -> i_dev);

    int free_sect_nr = alloc_smap_bit(dir_inode -> i_dev, NR_DEFAULT_FILE_SECTS);

    struct inode* nd = new_inode(dir_inode -> i_dev, inode_nr, free_sect_nr);

    new_dir_entry(dir_inode, nd -> i_num, filename);

    return nd;
}
Exemplo n.º 3
0
/**************************************************************************************************
 * 					create_file
 **************************************************************************************************
 * Create a file and return it's inode pointer.
 *
 * @param path	The full path of the new file.
 * @param flags	Attributes of the new file.
 *
 * @return	Pointer to inode of the new file if successed, otherwise 0.
 *************************************************************************************************/
PRIVATE struct inode* create_file(char* path, int flags){
	char filename[MAX_PATH];
	struct inode* dir_inode;

	if(strip_path(filename, path, &dir_inode) != 0){
		return 0;
	}

	int nr_inode		= alloc_imap_bit(dir_inode->i_dev);
	/* one file at least is 1MB... */
	int nr_free_sect	= alloc_smap_bit(dir_inode->i_dev, NR_DEFAULT_FILE_SECTS);

	struct inode* newino	= new_inode(dir_inode->i_dev, nr_inode, nr_free_sect);

	new_dir_entry(dir_inode, newino->i_num, filename);

	return newino;
}
Exemplo n.º 4
0
PRIVATE struct inode *creat_file(char *path, int flags)
{
    char filename[MAX_PATH];
    struct inode *dir_inode;

    /* 准备好文件名和文件夹的 inode */
    if (strip_path(filename, path, &dir_inode) != 0)
        return 0;

    /* 分配 inode */
    int inode_nr = alloc_imap_bit(dir_inode->i_dev);

    /* 分配 sector */
    int free_sect_nr = alloc_smap_bit(dir_inode->i_dev, NR_DEFAULT_FILE_SECTS);

    /* 在 inode array 中分配一个 inode */
    struct inode *newino = new_inode(dir_inode->i_dev, inode_nr, free_sect_nr);

    /* 新建一个目录项 */
    new_dir_entry(dir_inode, newino->i_num, filename);

    return newino;
}