예제 #1
0
/*
 * Create empty file.
 */
static int ramfs_create(vnode_t dvp, char *name, mode_t mode)
{
  struct ramfs_node *np;

  DPRINTF(AFSDB_CORE, ("create %s in %s\n", name, dvp->v_path));
  int type;

  if (S_ISREG(mode)) {
    type = VREG;
  } else if (S_ISBLK(mode)) {
    type = VBLK;
  } else if (S_ISCHR(mode)) {
    type = VCHR;
  } else if (S_ISSOCK(mode)) {
    type = VSOCK;
  } else if (S_ISFIFO(mode)) {
    type = VFIFO;
  } else {
    return -EINVAL;
  }

  np = ramfs_add_node(dvp->v_data, name, type, mode);
  if (np == NULL)
    return -ENOMEM;
  return 0;
}
예제 #2
0
파일: ramfs_vnops.c 프로젝트: Zabrane/osv
/*
 * Create empty file.
 */
static int
ramfs_create(struct vnode *dvp, char *name, mode_t mode)
{
	struct ramfs_node *np;

	DPRINTF(("create %s in %s\n", name, dvp->v_path));
	if (!S_ISREG(mode))
		return EINVAL;

	np = ramfs_add_node(dvp->v_data, name, VREG);
	if (np == NULL)
		return ENOMEM;
	return 0;
}
예제 #3
0
static int ramfs_mkdir(vnode_t dvp, char *name, mode_t mode)
{
  struct ramfs_node *np;

  DPRINTF(AFSDB_CORE, ("mkdir %s\n", name));
  if (!S_ISDIR(mode))
    return -EINVAL;

  np = ramfs_add_node(dvp->v_data, name, VDIR, mode);
  if (np == NULL)
    return -ENOMEM;
  np->rn_size = 0;
  return 0;
}
예제 #4
0
static s32_t ramfs_create(struct vnode_t * node, char * name, u32_t mode)
{
	struct ramfs_node * n;

	if(!S_ISREG(mode))
		return EINVAL;

	n = ramfs_add_node(node->v_data, name, VREG);
	if(n == NULL)
		return ENOMEM;

	n->mode = mode & (S_IRWXU|S_IRWXG|S_IRWXO);

	return 0;
}
예제 #5
0
static s32_t ramfs_mkdir(struct vnode_t * node, char * name, u32_t mode)
{
	struct ramfs_node *n;

	if(!S_ISDIR(mode))
		return EINVAL;

	n = ramfs_add_node(node->v_data, name, VDIR);
	if(n == NULL)
		return ENOMEM;

	n->mode = mode & (S_IRWXU|S_IRWXG|S_IRWXO);
	n->size = 0;

	return 0;
}
예제 #6
0
static s32_t ramfs_rename(struct vnode_t * dnode1, struct vnode_t * node1, char * name1, struct vnode_t *dnode2, struct vnode_t * node2, char * name2)
{
	struct ramfs_node *n, *old_n;
	s32_t error;

	if(node2)
	{
		/* remove destination file, first */
		error = ramfs_remove_node(dnode2->v_data, node2->v_data);
		if(error != 0)
			return error;
	}

	/* same directory */
	if(dnode1 == dnode2)
	{
		/* change the name of existing file */
		error = ramfs_rename_node(node1->v_data, name2);
		if(error)
			return error;
	}
	else
	{
		/* create new file or directory */
		old_n = node1->v_data;
		n = ramfs_add_node(dnode2->v_data, name2, VREG);
		if(n == NULL)
			return ENOMEM;

		if(node1->v_type == VREG)
		{
			/* copy file data */
			n->buf = old_n->buf;
			n->size = old_n->size;
			n->buf_len = old_n->buf_len;
		}

		/* remove source file */
		ramfs_remove_node(dnode1->v_data, node1->v_data);
	}

	return 0;
}
예제 #7
0
파일: ramfs_vnops.c 프로젝트: AndrewD/prex
/*
 * Create fifo.
 */
static int
ramfs_mkfifo(vnode_t dvp, char *name, mode_t mode)
{
	struct ramfs_node *node;

	DPRINTF(("mkfifo %s in %s\n", name, dvp->v_path));
	if (!S_ISFIFO(mode))
		return EINVAL;

	node = ramfs_add_node(dvp->v_data, name, VFIFO);
	if (node == NULL)
		return ENOMEM;

	node->rn_buf = malloc(PIPE_BUF);
	/* NOTE: node->bufsize node->size abused as fifo read / write counts */
	if (node->rn_buf == NULL) {
		ramfs_remove_node(dvp->v_data, node);
		return ENOMEM;
	}
	return 0;
}
예제 #8
0
파일: ramfs_vnops.c 프로젝트: Zabrane/osv
static int
ramfs_rename(struct vnode *dvp1, struct vnode *vp1, char *name1,
	     struct vnode *dvp2, struct vnode *vp2, char *name2)
{
	struct ramfs_node *np, *old_np;
	int error;

	if (vp2) {
		/* Remove destination file, first */
		error = ramfs_remove_node(dvp2->v_data, vp2->v_data);
		if (error)
			return error;
	}
	/* Same directory ? */
	if (dvp1 == dvp2) {
		/* Change the name of existing file */
		error = ramfs_rename_node(vp1->v_data, name2);
		if (error)
			return error;
	} else {
		/* Create new file or directory */
		old_np = vp1->v_data;
		np = ramfs_add_node(dvp2->v_data, name2, VREG);
		if (np == NULL)
			return ENOMEM;

		if (vp1->v_type == VREG) {
			/* Copy file data */
			np->rn_buf = old_np->rn_buf;
			np->rn_size = old_np->rn_size;
			np->rn_bufsize = old_np->rn_bufsize;
		}
		/* Remove source file */
		ramfs_remove_node(dvp1->v_data, vp1->v_data);
	}
	return 0;
}