*nix Documentation Project
·  Home
 +   man pages
·  Linux HOWTOs
·  FreeBSD Tips
·  *niX Forums

  man pages->FreeBSD man pages -> VOP_CREATE (9)              
Title
Content
Arch
Section
 

VOP_CREATE(9)

Contents


NAME    [Toc]    [Back]

     VOP_CREATE, VOP_MKNOD, VOP_MKDIR, VOP_SYMLINK -- create a file, socket,
     fifo, device, directory or symlink

SYNOPSIS    [Toc]    [Back]

     #include <sys/param.h>
     #include <sys/vnode.h>
     #include <sys/namei.h>

     int
     VOP_CREATE(struct vnode *dvp, struct vnode **vpp,
	 struct componentname *cnp, struct vattr *vap);

     int
     VOP_MKNOD(struct vnode *dvp, struct vnode **vpp,
	 struct componentname *cnp, struct vattr *vap);

     int
     VOP_MKDIR(struct vnode *dvp, struct vnode **vpp,
	 struct componentname *cnp, struct vattr *vap);

     int
     VOP_SYMLINK(struct vnode *dvp, struct vnode **vpp,
	 struct componentname *cnp, struct vattr *vap, char *target);

DESCRIPTION    [Toc]    [Back]

     These entry points create a new file, socket, fifo, device, directory or
     symlink in a given directory.

     The arguments are:

     dvp     the locked vnode of the directory

     vpp     the address of a variable where the resulting locked vnode should
	     be stored

     cnp     the pathname component created

     vap     the attributes that the new object should be created with

     target  the pathname of the target of the symlink

     These entry points are called after VOP_LOOKUP(9) when an object is being
     created.  Normally, VOP_LOOKUP(9) will have set the SAVENAME flag in
     cnp->cn_flags to keep the memory pointed to by cnp->cn_pnbuf valid.  If
     an error is detected when creating the file, then this memory will be
     freed.  If the file is created successfully, then it will be freed unless
     the SAVESTART flag is specified in cnp.

LOCKS    [Toc]    [Back]

     The directory, dvp will be locked on entry and must remain locked on
     return.  If the call is successful, the new object will be returned
     locked.

RETURN VALUES    [Toc]    [Back]

     If successful, the vnode for the new object is placed in *vpp and zero is
     returned.	Otherwise, an appropriate error is returned.

PSEUDOCODE    [Toc]    [Back]

     int
     vop_create(struct vnode *dvp,
		struct vnode **vpp,
		struct componentname *cnp
		struct vattr *vap)
     {
	 int mode = MAKEIMODE(vap->va_type, vap->va_mode);
	 struct vnode *vp;
	 int error;

	 *vpp = NULL;
	 if ((mode & IFMT) == 0)
	     mode |= IFREG;

	 error = SOMEFS_VALLOC(dvp, mode, cnp->cn_cred, &vp);
	 if (error) {
	     free(cnp->cn_pnbuf, M_NAMEI);
	     vput(dvp);
	     return error;
	 }

	 /*
	  * Update the permissions for the new vnode, including
	  * copying the group from the directory.
	  */
	 ...;

     #ifdef QUOTA
	 /*
	  * Possibly check quota information.
	  */
	 ...;
     #endif

	 /*
	  * Enter new vnode in directory, taking care that the vnode
	  * hits the disk before the directory contents are changed.
	  */
	 error = ...;

	 if (error)
	     goto bad;

	 if ((cnp->cn_flags & SAVESTART) == 0)
	     free(cnp->cn_pnbuf, M_NAMEI);
	 vput(dvp);
	 *vpp = vp;

	 return 0;

     bad:
	 /*
	  * Write error occurred trying to update the inode
	  * or the directory so must deallocate the inode.
	  */
	 free(cnp->cn_pnbuf, M_NAMEI);
	 vput(vp);

	 /*
	  * Deallocate file system resources for vp.
	  */
	 ...;

	 vput(dvp);

	 return error;
     }

ERRORS    [Toc]    [Back]

     [ENOSPC]		The file system is full.

     [EDQUOT]		The user's file system space or inode quota would be
			exceeded.

SEE ALSO    [Toc]    [Back]

      
      
     VOP_LOOKUP(9)

HISTORY    [Toc]    [Back]

     The function VOP_CREATE appeared in 4.3BSD.

SEE ALSO    [Toc]    [Back]

      
      
     vnode(9)

AUTHORS    [Toc]    [Back]

     This man page was written by Doug Rabson.


FreeBSD 5.2.1			 July 24, 1996			 FreeBSD 5.2.1
[ Back ]
 Similar pages
Name OS Title
mknod Tru64 Create a FIFO or special file
mkfifo Tru64 Create a FIFO
mktemp Tru64 Create a secure and uniquely named file or directory
open Linux open and possibly create a file or device
mklost+found Linux create a lost+found directory on a mounted Linux second extended file system
mac_get FreeBSD get the label of a file, socket, socket peer or process
mac_get_pid FreeBSD get the label of a file, socket, socket peer or process
mac_get_fd FreeBSD get the label of a file, socket, socket peer or process
mac_get_file FreeBSD get the label of a file, socket, socket peer or process
mac_get_proc FreeBSD get the label of a file, socket, socket peer or process
Copyright © 2004-2005 DeniX Solutions SRL
newsletter delivery service