示例#1
0
void do_mkdir()
{
    struct inode cur_dir,new_dir;
    char dirname[256];
    struct dir_ent ent;
    scanf("%s",dirname);
    if(strcmp(dirname,".")==0 || strcmp(dirname,"..")==0)
    {
        printf("Error directory name.\n");        
        return ;
    }
    get_inode(pwd,&cur_dir);  
        /*分配一个inode给新的目录*/
    new_dir.i_num=alloc_inode();
    new_dir.i_start_sect=alloc_data();        /*分配一个数据扇区*/
    new_dir.i_nr_sects=1;
    
    new_dir.i_pnum=pwd;
    new_dir.i_mode=2;
    new_dir.i_size=0;

        //给新目录增加默认目录项
    ent.i_num=pwd;    strcpy(ent.name,"..");
    add_entry(&new_dir,&ent);
    ent.i_num=new_dir.i_num;  strcpy(ent.name,".");
    add_entry(&new_dir,&ent);  
 
    ent.i_num=new_dir.i_num;    strcpy(ent.name,dirname);     
    add_entry(&cur_dir,&ent);
    //写入inode数组中
    write_inode(pwd,&cur_dir);
    write_inode(new_dir.i_num,&new_dir); 
}
示例#2
0
/*===========================================================================*
 *				fs_newnode				     *
 *===========================================================================*/
int fs_newnode()
{
    register int r;
    mode_t bits;
    struct minix_inode *rip;

    caller_uid = fs_m_in.REQ_UID;
    caller_gid = fs_m_in.REQ_GID;
    bits = fs_m_in.REQ_MODE;

    /* Try to allocate the inode */
    if( (rip = alloc_inode(fs_dev, bits) ) == NIL_INODE)
        return err_code;

    switch (bits & S_IFMT) {
    case S_IFBLK:
    case S_IFCHR:
        rip->i_zone[0] = fs_m_in.REQ_DEV; /* major/minor dev numbers*/
        break;
    }

    rw_inode(rip, WRITING);	/* mark inode as allocated */
    rip->i_update = ATIME | CTIME | MTIME;

    /* Fill in the fields of the response message */
    fs_m_out.RES_INODE_NR = rip->i_num;
    fs_m_out.RES_MODE = rip->i_mode;
    fs_m_out.RES_FILE_SIZE_LO = rip->i_size;
    fs_m_out.RES_UID = rip->i_uid;
    fs_m_out.RES_GID = rip->i_gid;
    fs_m_out.RES_DEV = (dev_t) rip->i_zone[0];

    return(0);
}
void
MetaDataStore::maybe_initialise_()
{
    if (not harakoon_.initialized())
    {
        LOG_INFO("Trying to initialize filesystem metadata store");
        try
        {
            harakoon_.initialize(DirectoryEntry(DirectoryEntry::Type::Directory,
                                                alloc_inode(),
                                                default_directory_permissions,
                                                UserId(::getuid()),
                                                GroupId(::getgid())));
            LOG_INFO("Initialized filesystem metadata store");
        }
        catch (ara::error_assertion_failed&)
        {
            // Another cluster node could've beaten us to it:
            if (not harakoon_.initialized())
            {
                throw;
            }
            else
            {
                LOG_INFO("Filesystem metadata store already initialized by another node");
            }
        }
    }
    else
    {
        LOG_INFO("Filesystem metadata store already initialized");
    }
}
示例#4
0
struct inode *
pipe_create_root(struct fs *fs) {
    struct inode *node;
    if ((node = alloc_inode(pipe_root)) != NULL) {
        vop_init(node, &pipe_root_ops, fs);
    }
    return node;
}
示例#5
0
/*
 * Function to create a inode for a VFS device.
 */
struct inode *
dev_create_inode(void) {
    struct inode *node;
    if ((node = alloc_inode(device)) != NULL) {
        vop_init(node, &dev_node_ops, NULL);
    }
    return node;
}
示例#6
0
文件: mkfs.c 项目: anuragpeshne/minix
/*================================================================
 *	    eat_dir  -  recursively install directory
 *===============================================================*/
void
eat_dir(ino_t parent)
{
  /* Read prototype lines and set up directory. Recurse if need be. */
  char *token[MAX_TOKENS], *p;
  char line[LINE_LEN];
  int mode, usrid, grpid, maj, min, f;
  ino_t n;
  zone_t z;
  size_t size;

  while (1) {
	get_line(line, token);
	p = token[0];
	if (*p == '$') return;
	p = token[1];
	mode = mode_con(p);
	usrid = atoi(token[2]);
	grpid = atoi(token[3]);
	n = alloc_inode(mode, usrid, grpid);

	/* Enter name in directory and update directory's size. */
	enter_dir(parent, token[0], n);
	incr_size(parent, sizeof(struct direct));

	/* Check to see if file is directory or special. */
	incr_link(n);
	if (*p == 'd') {
		/* This is a directory. */
		z = alloc_zone();	/* zone for new directory */
		add_zone(n, z, 2 * sizeof(struct direct), current_time);
		enter_dir(n, ".", n);
		enter_dir(n, "..", parent);
		incr_link(parent);
		incr_link(n);
		eat_dir(n);
	} else if (*p == 'b' || *p == 'c') {
		/* Special file. */
		maj = atoi(token[4]);
		min = atoi(token[5]);
		size = 0;
		if (token[6]) size = atoi(token[6]);
		size = block_size * size;
		add_zone(n, (zone_t) (makedev(maj,min)), size, current_time);
	} else if (*p == 's') {
		enter_symlink(n, token[4]);
	} else {
		/* Regular file. Go read it. */
		if ((f = open(token[4], O_RDONLY)) < 0) {
			fprintf(stderr, "%s: Can't open %s: %s\n",
				progname, token[4], strerror(errno));
		} else {
			eat_file(n, f);
		}
	}
  }

}
示例#7
0
//handling symlink request
void symlink_handler(Msg *msg, int sender_pid)
{

    char oldname[MAXPATHNAMELEN], newname[MAXPATHNAMELEN];
    memset(oldname,'\0',MAXPATHNAMELEN);
    memset(newname,'\0',MAXPATHNAMELEN);
    CopyFrom(sender_pid,oldname,msg->ptr1,msg->num2+1);
    CopyFrom(sender_pid,newname,msg->ptr2,msg->num3+1);

    int dir_len=msg->num3;
    char *dir_newname=newname+msg->num3;
    while((*dir_newname)!='/'&&dir_newname!=newname){
        dir_len--;
        dir_newname--;
    }

    if((*dir_newname)=='/'){
        dir_len++;
        dir_newname++;
    }
    int parent_inum=path_to_inum(newname,dir_len,msg->num1,0); 
    int sym_inum=alloc_inode(INODE_SYMLINK,parent_inum);
    if(sym_inum<=0){
        msg->type=-1;
        return;
    }

    inode_cache *parent_inode=read_inode(parent_inum);
    inode_cache *sym_inode=read_inode(sym_inum);
    int sym_bnum=alloc_block();
    block_cache *sym_block=read_block(sym_bnum);

    struct dir_entry *sym_dir_entry=search_dir_entry(parent_inum,dir_newname);
    if(sym_dir_entry!=NULL){
        msg->type=-1;
        return;
    }
    if((sym_dir_entry=empty_dir(msg->num1))==NULL){
        msg->type=-1;
        return;
    }

    sym_dir_entry->inum=sym_inum;
    memcpy(sym_dir_entry->name,dir_newname,msg->num3-dir_len);


    sym_inode->data.size=msg->num2;
    sym_inode->data.nlink=1;
    sym_inode->data.direct[0]=sym_bnum;

    sym_block->dirty=1;
    memcpy(sym_block->data,oldname,msg->num2);
    parent_inode->data.size+=sizeof(struct dir_entry);
    parent_inode->dirty=1;

}
示例#8
0
文件: extbmp.c 项目: TaylanUB/larceny
extbmp_t *create_extensible_bitmap_params( gc_t *gc, gc_param_t *info,
                                           int leaf_bytes, 
                                           int entries_per_node )
{
  /* Creates bitmap representing empty set of addresses */
  extbmp_t *ebmp;
  int depth;
  int max_leaves;
  int leaf_words = CEILDIV(leaf_bytes, sizeof(word));
  long long address_range_in_words;

  assert( (leaf_bytes % MIN_BYTES_PER_OBJECT) == 0 );
  max_leaves = SHIFTED_ADDRESS_SPACE / (BITS_PER_WORD * leaf_words);
  assert( max_leaves > 0 );
  { /* calculate max depth of tree */
    int i = 0;
    long long tot = 1;
    long long addr_range = ADDRS_PER_WORD * leaf_words;
    while (tot < max_leaves) {
      i   += 1;
      tot *= entries_per_node;
      addr_range *= entries_per_node;
    }
    depth = i;
    address_range_in_words = addr_range;
  }

  ebmp = (extbmp_t*)must_malloc( sizeof( extbmp_t ));
  ebmp->gc                = gc;
  ebmp->leaf_words        = CEILDIV(leaf_bytes,sizeof(word));
  ebmp->entries_per_inode = entries_per_node;
  ebmp->depth             = depth;
  ebmp->tree
    = alloc_inode( ebmp, 
                   address_range_in_words, 
                   0, 
                   (((long long)SHIFTED_ADDRESS_SPACE) << BIT_IDX_SHIFT));

  ebmp->mru_cache.leaf    = NULL;
  ebmp->mru_cache.first_addr_for_leaf = 0;

  ebmp->gno_count = gc->gno_count;
  ebmp->gno_to_leaf = (leaf_t**)must_malloc( sizeof(leaf_t*) * ebmp->gno_count );
  { 
    int i;
    for (i = 0; i < ebmp->gno_count; i++) {
      ebmp->gno_to_leaf[i] = NULL;
    }
  }
  ebmp->leaf_count = 0;

  annoyingmsg( "ebmp{gc,leaf_words=%d,entries_per_inode=%d,depth=%d,tree} max_leaves:%d",
               ebmp->leaf_words, ebmp->entries_per_inode, ebmp->depth, max_leaves );
  return ebmp;
}
示例#9
0
//handling mkdir request
void mkdir_handler(Msg *msg, int sender_pid)
{
    char pathname[MAXPATHNAMELEN];
    CopyFrom(sender_pid,pathname,msg->ptr1,msg->num1+1);
    char* dir_name = pathname+msg->num1;
    int direct_len = msg->num1;
    while ((*dir_name)!='/' && dir_name!=pathname) {
        dir_name--;
        direct_len--;
    }
    if ((*dir_name)=='/') {
        direct_len++;
        dir_name++;
    }
    if (strlen(dir_name)==0) {
        perror("invalid pathname when creating file!");
        msg->type = ERROR;
        return;
    }
    int direct_inum = path_to_inum(pathname,direct_len,msg->num2,0);
    if (direct_inum<=0) {
        perror("invalid pathname when creating file!");
        msg->type = ERROR;
        return;
    }
    int new_inum = check_dir(direct_inum,dir_name);
    if (new_inum<0) {
        perror("invalid pathname when creating file!");
        msg->type = ERROR;
        return;
    }

    //exist same file name in the directory
    else if (new_inum>0) {
        perror("exist a directory with same name");
        msg->type = ERROR;
        return;
    }
    else if (new_inum==0) {
        new_inum = alloc_inode(INODE_DIRECTORY,direct_inum);
        struct dir_entry *d = empty_dir(direct_inum);
        if (d==NULL) {
            perror("no empty space for new directory");
            msg->type = ERROR;
            return;
        }
        d->inum = new_inum;
        memcpy(d->name,dir_name,strlen(dir_name));
        inode_cache *n = read_inode(direct_inum);
        n->data.nlink++;
        n->data.size+=sizeof(struct dir_entry);
        n->dirty = 1;
        msg->num1 = 0;
    }
}
示例#10
0
文件: pxe.c 项目: emmericp/syslinux
/*
 * Allocate a local UDP port structure and assign it a local port number.
 * Return the inode pointer if success, or null if failure
 */
static struct inode *allocate_socket(struct fs_info *fs)
{
    struct inode *inode = alloc_inode(fs, 0, sizeof(struct pxe_pvt_inode));

    if (!inode) {
	malloc_error("socket structure");
    } else {
	inode->mode = DT_REG;	/* No other types relevant for PXE */
    }

    return inode;
}
示例#11
0
/*
 * sfs_create_inode - alloc a inode in memroy, and init din/ino/dirty/reclian_count/sem fields in sfs_inode in inode
 */
static int
sfs_create_inode(struct sfs_fs *sfs, struct sfs_disk_inode *din, uint32_t ino, struct inode **node_store) {
    struct inode *node;
    if ((node = alloc_inode(sfs_inode)) != NULL) {
        vop_init(node, sfs_get_ops(din->type), info2fs(sfs, sfs));
        struct sfs_inode *sin = vop_info(node, sfs_inode);
        sin->din = din, sin->ino = ino, sin->dirty = 0, sin->reclaim_count = 1;
        sem_init(&(sin->sem), 1);
        *node_store = node;
        return 0;
    }
    return -E_NO_MEM;
}
示例#12
0
/* 将外部文件写入到镜像中 */
void do_write()
{
    struct stat st;
    struct inode cur_dir,new_file;
    struct dir_ent ent;
    char buf[SECTOR_SIZE+10];
    int i;
    FILE *fin;
    char filename[16];
    scanf("%s",filename);
    if(stat(filename,&st)<0) {
        printf("No such file.\n");
        return ;
    }
    fin=fopen(filename,"rb");
    get_inode(pwd,&cur_dir);
    new_file.i_num=alloc_inode();
    new_file.i_pnum=pwd;
    new_file.i_size=st.st_size; 
    new_file.i_mode=1; //标示为文件
    ent.i_num=new_file.i_num;   strcpy(ent.name,filename);    
    add_entry(&cur_dir,&ent);
    
    u32 last_sector=0,cur_sector;
    u32 need=st.st_size/(SECTOR_SIZE-sizeof(u32))+1;
    new_file.i_nr_sects=need;
        //根据文件大小,逐个分配扇区来写入数据,并采用单链表方式连接各个扇区
    for(i=0;i<need;i++)
    {
        cur_sector=alloc_data();
        if(last_sector==0)  {
            new_file.i_start_sect=cur_sector;
        }else{ //上一个扇区到这个扇区的指针
            fseek(fimg,last_sector*SECTOR_SIZE+SECTOR_SIZE-sizeof(u32),SEEK_SET);
            fwrite(&cur_sector,sizeof(u32),1,fimg);
        }
        int nread=fread(buf,sizeof(char),SECTOR_SIZE-sizeof(u32),fin);
        if(nread<0)  {
            printf("Read file %s error.\n",filename );
            return ;
        }
        fseek(fimg,cur_sector*SECTOR_SIZE,SEEK_SET);
        fwrite(buf,sizeof(char),nread,fimg);
        last_sector=cur_sector;
    }
    fseek(fimg,last_sector*SECTOR_SIZE+SECTOR_SIZE-sizeof(u32),SEEK_SET);
    u32 tmp=0;
    fwrite(&tmp,sizeof(u32),1,fimg);
    write_inode(new_file.i_num,&new_file);
    write_inode(cur_dir.i_num,&cur_dir);
}
示例#13
0
文件: read.c 项目: Hooman3/minix
ssize_t fs_getdents(ino_t ino_nr, struct fsdriver_data *data, size_t bytes,
	off_t *pos)
{
	struct fsdriver_dentry fsdentry;
	struct inode *i_node, *i_node_tmp;
	size_t cur_pos, new_pos;
	int r, len;
	char *cp;

	if ((i_node = find_inode(ino_nr)) == NULL)
		return EINVAL;

	if (*pos < 0 || *pos > SSIZE_MAX)
		return EINVAL;

	fsdriver_dentry_init(&fsdentry, data, bytes, getdents_buf,
	    sizeof(getdents_buf));

	r = OK;

	for (cur_pos = (size_t)*pos; ; cur_pos = new_pos) {
		i_node_tmp = alloc_inode();
		r = read_inode(i_node_tmp, i_node->extent, cur_pos, &new_pos);
		if ((r != OK) || (new_pos >= i_node->i_stat.st_size)) {
			put_inode(i_node_tmp);
			break;
		}

		/* Compute the length of the name */
		cp = memchr(i_node_tmp->i_name, '\0', NAME_MAX);
		if (cp == NULL)
			len = NAME_MAX;
		else
			len = cp - i_node_tmp->i_name;

		r = fsdriver_dentry_add(&fsdentry, i_node_tmp->i_stat.st_ino,
		    i_node_tmp->i_name, len,
		    IFTODT(i_node_tmp->i_stat.st_mode));

		put_inode(i_node_tmp);

		if (r <= 0)
			break;
	}

	if (r >= 0 && (r = fsdriver_dentry_finish(&fsdentry)) >= 0)
		*pos = cur_pos;

	return r;
}
示例#14
0
文件: file.c 项目: HarryR/sanos
static struct inode *open_always(struct filsys *fs, char *name, int len, int mode)
{
  struct inode *dir;
  struct inode *inode;
  vfs_ino_t ino;

  dir = parse_name(fs, &name, &len);
  if (!dir) return NULL;

  ino = find_dir_entry(dir, name, len);
  if (ino == -1)
  {
    inode = alloc_inode(dir, VFS_S_IFREG | mode);
    if (!inode) 
    {
      release_inode(dir);
      return NULL;
    }

    inode->desc->linkcount++;
    mark_inode_dirty(inode);

    if (add_dir_entry(dir, name, len, inode->ino) < 0)
    {
      unlink_inode(inode);
      release_inode(inode);
      release_inode(dir);
      return NULL;
    }
  }
  else
  {
    inode = get_inode(fs, ino);
    if (!inode) 
    {
      release_inode(dir);
      return NULL;
    }

    if (VFS_S_ISDIR(inode->desc->mode))
    {
      release_inode(dir);
      release_inode(inode);
      return NULL;
    }
  }

  release_inode(dir);
  return inode;
}
示例#15
0
// return new inode number; 0 if failed
uint32_t ext2_create_file(uint8_t *fs, char *path) {
    uint32_t free_inode = alloc_inode(fs);
    DEBUG("EXT2 CREATE: Allocated node %d", free_inode);

    if (free_inode) {
        struct ext2_inode *inode_pointer = get_inode(fs, free_inode);

        // get directory path
        int num_parts = 0;
        char **parts = split_path(path, &num_parts);
        if (!num_parts) {
            return 0;
        }
        int newstring_size = 0;
        for (int i=0; i < num_parts-1; i++) {
            newstring_size += strlen(parts[i]) + 1;
        }
        char *newstring = malloc(newstring_size);
        strcpy(newstring, "/");
        for (int i=0; i < num_parts-1; i++) {
            strcat(newstring,parts[i]);
            if (i != num_parts-2) {
                strcat(newstring, "/");
            }
        }

        // get inode of directory
        char *name = parts[num_parts-1];
        int dir_num = 0;
        if(strcmp(newstring, "/")) {
            dir_num = get_inode_by_path(fs, newstring);
        }
        else {
            dir_num = EXT2_ROOT_INO;
        }

        // create dentry
        if (dir_num) {
            dentry_add(fs, dir_num, free_inode, name, 1);
            //fill in inode with stuff
            inode_pointer->i_mode = EXT2_S_IFREG;
            inode_pointer->i_size = 0;
            //set bitmap to taken
        }
        else {
            return 0;
        }
    }
    return free_inode;
}
示例#16
0
文件: pipe.c 项目: Johnwei386/Minix3
/*===========================================================================*
 *				do_pipe					     *
 *===========================================================================*/
PUBLIC int do_pipe()
{
/* Perform the pipe(fil_des) system call. */

  register struct fproc *rfp;
  register struct inode *rip;
  int r;
  struct filp *fil_ptr0, *fil_ptr1;
  int fil_des[2];		/* reply goes here */

  /* Acquire two file descriptors. */
  rfp = fp;
  if ( (r = get_fd(0, R_BIT, &fil_des[0], &fil_ptr0)) != OK) return(r);
  rfp->fp_filp[fil_des[0]] = fil_ptr0;
  fil_ptr0->filp_count = 1;
  if ( (r = get_fd(0, W_BIT, &fil_des[1], &fil_ptr1)) != OK) {
	rfp->fp_filp[fil_des[0]] = NIL_FILP;
	fil_ptr0->filp_count = 0;
	return(r);
  }
  rfp->fp_filp[fil_des[1]] = fil_ptr1;
  fil_ptr1->filp_count = 1;

  /* Make the inode on the pipe device. */
  if ( (rip = alloc_inode(root_dev, I_REGULAR) ) == NIL_INODE) {
	rfp->fp_filp[fil_des[0]] = NIL_FILP;
	fil_ptr0->filp_count = 0;
	rfp->fp_filp[fil_des[1]] = NIL_FILP;
	fil_ptr1->filp_count = 0;
	return(err_code);
  }

  if (read_only(rip) != OK) 
  	panic(__FILE__,"pipe device is read only", NO_NUM);
 
  rip->i_pipe = I_PIPE;
  rip->i_mode &= ~I_REGULAR;
  rip->i_mode |= I_NAMED_PIPE;	/* pipes and FIFOs have this bit set */
  fil_ptr0->filp_ino = rip;
  fil_ptr0->filp_flags = O_RDONLY;
  dup_inode(rip);		/* for double usage */
  fil_ptr1->filp_ino = rip;
  fil_ptr1->filp_flags = O_WRONLY;
  rw_inode(rip, WRITING);	/* mark inode as allocated */
  m_out.reply_i1 = fil_des[0];
  m_out.reply_i2 = fil_des[1];
  rip->i_update = ATIME | CTIME | MTIME;
  return(OK);
}
示例#17
0
static struct inode *ext2_iget_by_inr(struct fs_info *fs, uint32_t inr)
{
    const struct ext2_inode *e_inode;
    struct inode *inode;

    e_inode = ext2_get_inode(fs, inr);
    if (!e_inode)
	return NULL;

    if (!(inode = alloc_inode(fs, inr, sizeof(struct ext2_pvt_inode))))
	return NULL;
    fill_inode(inode, e_inode);

    return inode;
}
示例#18
0
文件: file.c 项目: HarryR/sanos
static int create_new(struct filsys *fs, char *name, ino_t ino, int mode, struct inode **retval) {
  struct inode *dir;
  struct inode *inode;
  int rc;
  int len = strlen(name);

  rc = diri(fs, &name, &len, &dir);
  if (rc < 0) return rc;

  rc = find_dir_entry(dir, name, len, NULL);
  if (rc != -ENOENT) {
    release_inode(dir);
    return rc >= 0 ? -EEXIST : rc;
  }

  if (ino == NOINODE) {
    inode = alloc_inode(dir, S_IFREG | (mode & S_IRWXUGO));
    if (!inode) rc = -ENOSPC;
  } else {
    rc = get_inode(fs, ino, &inode);
    if (rc < 0) inode = NULL;
    if (inode) {
      inode->desc->ctime = inode->desc->mtime = time(NULL);
      inode->desc->uid = inode->desc->gid = 0;
      inode->desc->mode = S_IFREG | 0700;
      inode->desc->linkcount++;
      mark_inode_dirty(inode);
    }
  }

  if (!inode) {
    release_inode(dir);
    return rc;
  }

  rc = add_dir_entry(dir, name, len, inode->ino);
  if (rc < 0) {
    unlink_inode(inode);
    release_inode(inode);
    release_inode(dir);
    return rc;
  }

  release_inode(dir);
  *retval = inode;
  return 0;
}
示例#19
0
struct inode *pipe_create_inode(struct fs *fs, const char *__name,
				struct pipe_state *state, bool readonly)
{
	char *name = NULL;
	if (__name == NULL || (name = strdup(__name)) != NULL) {
		struct inode *node;
		if ((node = alloc_inode(pipe_inode)) != NULL) {
			vop_init(node, &pipe_node_ops, fs);
			pipe_inode_init(vop_info(node, pipe_inode), name, state,
					readonly);
			return node;
		}
		if (name != NULL) {
			kfree(name);
		}
	}
	return NULL;
}
示例#20
0
文件: vfs.c 项目: FeibHwang/Hurlex-II
// 初始化VFS目录树
static void init_mount_tree(struct vfsmount *mount)
{
        // 添加根文件系统
        add_filesystem(&fs_ramfs);

        INIT_LIST_HEAD(&(fs_ramfs.fs_supers));

        // 获取根文件系统的超级块结构
        struct super_block *sb = alloc_super_block();
        bzero(sb, sizeof(struct super_block));
        
        // 将 super_block 添加到文件系统控制信息下
        list_add(&(sb->s_list), &(fs_ramfs.fs_supers));

        // 为根文件系统初始化超级块
        fs_ramfs.read_super(sb);

        // 初始化根结点 inode
        struct inode *inode = alloc_inode();
        bzero(inode, sizeof(struct inode));
        inode->i_sb = sb;

        // 初始化根结点 dentry
        struct dentry *dentry = alloc_dentry();
        atomic_set(&(dentry->d_count), 0);
        INIT_LIST_HEAD(&(dentry->d_subdirs));
        INIT_LIST_HEAD(&(dentry->d_child));

        dentry->d_status = 1;
        dentry->d_parent = NULL;
        dentry->d_sb = sb;
        dentry->d_inode = inode;
        dentry->is_mounted = 0;
        strcpy(dentry->d_name, "/");
        
        // 链接根节点 dentry
        sb->s_root = dentry;

        mount->mnt_devname = "RAM";
        mount->mnt_sb = sb;
        mount->mnt_root = dentry;
        mount->mnt_mountpoint = dentry;
        mount->mnt_parent = NULL;
}
示例#21
0
文件: file.c 项目: HarryR/sanos
static struct inode *create_new(struct filsys *fs, char *name, int len, int mode)
{
  struct inode *dir;
  struct inode *inode;
  struct inode *oldinode;
  vfs_ino_t oldino;

  dir = parse_name(fs, &name, &len);
  if (!dir) return NULL;

  inode = alloc_inode(dir, VFS_S_IFREG | mode);
  if (!inode)
  {
    release_inode(dir);
    return NULL;
  }

  inode->desc->linkcount++;
  mark_inode_dirty(inode);

  oldino = modify_dir_entry(dir, name, len, inode->ino);
  if (oldino != -1)
  {
    oldinode = get_inode(fs, oldino);
    if (oldinode)
    {
      unlink_inode(oldinode);
      release_inode(oldinode);
    }
  }
  else
  {
    if (add_dir_entry(dir, name, len, inode->ino) < 0)
    {
      unlink_inode(inode);
      release_inode(inode);
      release_inode(dir);
      return NULL;
    }
  }

  release_inode(dir);
  return inode;
}
示例#22
0
文件: file.c 项目: HarryR/sanos
static struct inode *create_always(struct filsys *fs, char *name, int len, vfs_ino_t ino, int mode)
{
  struct inode *dir;
  struct inode *inode;

  dir = parse_name(fs, &name, &len);
  if (!dir) return NULL;

  if (find_dir_entry(dir, name, len) != -1)
  {
    release_inode(dir);
    return NULL;
  }

  if (ino == -1)
    inode = alloc_inode(dir, VFS_S_IFREG | mode);
  else
  {
    inode = get_inode(fs, ino);
    if (inode->desc->ctime == 0) inode->desc->ctime = time(NULL);
    inode->desc->mode = VFS_S_IFREG | mode;
  }

  if (!inode)
  {
    release_inode(dir);
    return NULL;
  }

  inode->desc->linkcount++;
  mark_inode_dirty(inode);

  if (add_dir_entry(dir, name, len, inode->ino) < 0)
  {
    unlink_inode(inode);
    release_inode(inode);
    release_inode(dir);
    return NULL;
  }

  release_inode(dir);
  return inode;
}
示例#23
0
文件: bitmap.c 项目: bingone/fuckOS
struct m_inode * new_inode(int dev)
{
	struct m_inode * inode;
	struct super_block * sb;
	struct buffer_head * bh;
	int i,j;

	inode = alloc_inode();
	if (!inode)
		return NULL;

	if (!(sb = get_super(dev)))
		panic("new_inode with unknown device");

	j = 8192;
	for (i=0 ; i<8 ; i++) {
		if ((bh = sb->s_imap[i])) {
			if ((j=find_first_zero(bh->b_data))<8192)
				break;
		}
	}

	if (!bh || j >= 8192 || j+i*8192 > sb->s_ninodes) {
		panic("not implemented!\n");
		//iput(inode);
		return NULL;
	}

	if (test_and_set_bit(j,bh->b_data))
		panic("new_inode: bit already set");

	bh->b_dirt = 1;
	inode->i_count=1;
	inode->i_nlinks=1;
	inode->i_dev=dev;
//	inode->i_uid=current->euid;
//	inode->i_gid=current->egid;
	inode->i_dirt=1;
	inode->i_num = j + i*8192;
//	inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;

	return inode;
}
示例#24
0
文件: open.c 项目: AgamAgarwal/minix
/*===========================================================================*
 *				fs_newnode				     *
 *===========================================================================*/
int fs_newnode(message *fs_m_in, message *fs_m_out)
{
  register int r = OK;
  mode_t bits;
  struct inode *rip;
  dev_t dev;

  caller_uid = (uid_t) fs_m_in->REQ_UID;
  caller_gid = (gid_t) fs_m_in->REQ_GID;
  bits = (mode_t) fs_m_in->REQ_MODE;
  dev = (dev_t) fs_m_in->REQ_DEV;

  /* Try to allocate the inode */
  if( (rip = alloc_inode(dev, bits) ) == NULL) return(err_code);

  switch (bits & S_IFMT) {
	case S_IFBLK:
	case S_IFCHR:
		rip->i_rdev = dev;		/* Major/minor dev numbers */
		break;
	case S_IFIFO:
		if ((get_block(dev, rip->i_num)) == NULL)
			r = EIO;
		break;
	default:
		r = EIO; /* Unsupported file type */
  }

  if (r != OK) {
	free_inode(rip);
  } else {
	/* Fill in the fields of the response message */
	fs_m_out->RES_INODE_NR = rip->i_num;
	fs_m_out->RES_MODE = rip->i_mode;
	fs_m_out->RES_FILE_SIZE_LO = rip->i_size;
	fs_m_out->RES_UID = rip->i_uid;
	fs_m_out->RES_GID = rip->i_gid;
	fs_m_out->RES_DEV = dev;
  }

  return(r);
}
示例#25
0
文件: file.c 项目: HarryR/sanos
static int open_always(struct filsys *fs, char *name, int mode, struct inode **retval) {
  struct inode *dir;
  struct inode *inode;
  ino_t ino;
  int rc;
  int len = strlen(name);

  rc = diri(fs, &name, &len, &dir);
  if (rc < 0) return rc;

  rc = find_dir_entry(dir, name, len, &ino);
  if (rc < 0 && rc != -ENOENT) {
    release_inode(dir);
    return rc;
  }

  if (rc == -ENOENT) {
    inode = alloc_inode(dir, S_IFREG | (mode & S_IRWXUGO));
    if (!inode) {
      release_inode(dir);
      return -ENOSPC;
    }

    rc = add_dir_entry(dir, name, len, inode->ino);
    if (rc < 0) {
      unlink_inode(inode);
      release_inode(inode);
      release_inode(dir);
      return rc;
    }
  } else {
    rc = get_inode(fs, ino, &inode);
    if (rc < 0) {
      release_inode(dir);
      return rc;
    }
  }

  release_inode(dir);
  *retval = inode;
  return 0;
}
示例#26
0
文件: new_file.c 项目: yeonsh/Amoeba
Cache_ent *
new_file()
{
    Cache_ent *	cp;
    Inodenum	inode;

    /* Get an inode - it is locked when we get it. */
    if ((inode = alloc_inode()) < 0)
	return 0;

    /* Get a cache slot */
    if ((cp = alloc_cache_slot(inode)) == 0)
    {
	free_inode(inode,0,ANN_NEVER,SEND_CANWAIT); /* unlocks the inode */
	return 0;
    }

    cp->c_flags |= NOTCOMMITTED;
    cp->c_timeout = BS_CACHE_TIMEOUT;
    return cp;
}
示例#27
0
文件: initfs.c 项目: bmarcot/vega
struct dentry *initfs_lookup(struct inode *dir, struct dentry *target)
{
	struct initfs_inode *ii = dir->i_private;

	//FIXME: infinite loop, really?
	for (;;) {
		if (!strcmp(ii->file_name, target->d_name)) {
			struct inode *inode = alloc_inode(ii, dir);
			if (inode == NULL) {
				pr_err("cannot allocate inode");
				return NULL;
			}
			target->d_inode = inode;
			target->d_op = &initfs_dops;

			return target;
		}
		ii = get_next_inode(ii);
	}

	return NULL;
}
示例#28
0
static struct inode *newdir(struct filesys *fs, struct inode *parent)
{
	struct inode *dirnode;

	/* allocate and initialize inode */
	if(!(dirnode = malloc(sizeof *dirnode))) {
		return 0;
	}
	memset(dirnode, 0, sizeof *dirnode);

	if((dirnode->ino = alloc_inode(fs)) == -1) {
		printf("failed to allocate inode for a new directory\n");
		free(dirnode);
		return 0;
	}
	dirnode->mode = S_IFDIR;

	/* add . and .. links */
	addlink(fs, dirnode, dirnode, ".");
	addlink(fs, dirnode, parent ? parent : dirnode, "..");

	return dirnode;
}
示例#29
0
文件: ext2.c 项目: giumaug/g-os
int _open(t_ext2* ext2,const char* fullpath, int flags)
{
	u32 fd;
	u32 ret_code;
	struct t_process_context* current_process_context;
	t_inode* inode;
	t_llist_node* node;
	char path[NAME_MAX];
	char filename[NAME_MAX];

	inode=kmalloc(sizeof(t_inode));
	CURRENT_PROCESS_CONTEXT(current_process_context);
	fd=current_process_context->next_fd++;
	//current_process_context->file_desc=kmalloc(sizeof(t_hashtable));
	//hashtable_init(current_process_context->file_desc,10);

	if (flags & O_CREAT & O_RDWR)
	{
		alloc_inode(fullpath,0,system.root_fs,inode);
		hashtable_put(current_process_context->file_desc,fd,inode);
	}
	else if (flags & (O_APPEND | O_RDWR))
	{
		ret_code=lookup_inode(fullpath,ext2,inode);		
		if (ret_code==-1)
		{
			return -1;
		}
		hashtable_put(current_process_context->file_desc,fd,inode);
	}
	else 
	{
		return -1;
	}
	inode->file_offset=0;
	return fd;
}
示例#30
0
文件: inode.c 项目: Hooman3/minix
struct inode* get_inode(ino_t i)
{
	struct inode *i_node;
	struct dir_extent *extent;

	if (i == 0)
		return NULL;

	/* Try to get inode from cache. */
	i_node = find_inode(i);
	if (i_node != NULL) {
		dup_inode(i_node);
		return i_node;
	}

	/*
	 * Inode wasn't in cache, try to load it.
	 * FIXME: a fake extent of one logical block is created for
	 * read_inode(). Reading a inode this way could be problematic if
	 * additional extents are stored behind the block boundary.
	 */
	i_node = alloc_inode();
	extent = alloc_extent();
	extent->location = i / v_pri.logical_block_size_l;
	extent->length = 1;

	if (read_inode(i_node, extent, i % v_pri.logical_block_size_l,
	    NULL) != OK) {
		free_extent(extent);
		put_inode(i_node);
		return NULL;
	}

	free_extent(extent);
	return i_node;
}