VOP_LINK(9)

NAME
VOP_LINK - create a new name for a file

SYNOPSIS
#include <sys/param.h>
#include <sys/vnode.h>
int
VOP_LINK(struct vnode *dvp, struct vnode *vp, struct componentname *cnp);

DESCRIPTION
This links a new name in the specified directory to an existing file.

Its arguments are:

dvp the vnode of the directory

AT&T UNIX
    the vnode of the file to be linked

cnp pathname information about the file

The directory vnode is unlocked and released on exit.

LOCKS
The directory, dvp should be locked on entry and will be unlocked and released on exit. The file vp should not be locked.

RETURN VALUES
Zero is returned if the file was linked successfully, otherwise an error is returned.

PSEUDOCODE

    int
    vop_link(struct vnode *dvp, struct vnode *vp, struct componentname *cnp)
    {
        int error = 0;
        if (vp->v_mount != dvp->v_mount) {
    	VOP_ABORTOP(dvp, cnp);
    	error = EXDEV;
    	goto out2;
        }
        if (vp != dvp && (error = VOP_LOCK(vp))) {
    	VOP_ABORTOP(dvp, cnp);
    	goto out2;
        }
        if (vp would have too many links) {
    	VOP_ABORTOP(dvp, cnp);
    	error = EMLINK;
    	goto out1;
        }
        if (vp is immutable) {
    	VOP_ABORTOP(dvp, cnp);
    	error = EPERM;
    	goto out1;
        }
        /*
         * Increment link count of vp and write back the on-disc version of it.
         */
        ...;
        if (!error) {
    	/*
    	 * Add the new name to the directory.
    	 */
    	...;
        }
        free(cnp->cn_pnbuf, M_NAMEI);
    out1:
        if (vp != dvp)
    	VOP_UNLOCK(vp);
    out2:
        vput(dvp);
        return error;
    }

ERRORS

[EPERM]
    the file is immutable

SEE ALSO
vnode(9)

AUTHORS
This man page was written by Doug Rabson.