2000-08-20 21:34:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
* Copyright (c) 2000
|
|
|
|
* Poul-Henning Kamp. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software donated to Berkeley by
|
|
|
|
* Jan-Simon Pendry.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)kernfs_vnops.c 8.15 (Berkeley) 5/21/95
|
|
|
|
* From: FreeBSD: src/sys/miscfs/kernfs/kernfs_vnops.c 1.43
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
2001-05-23 17:48:20 +00:00
|
|
|
/*
|
|
|
|
* TODO:
|
|
|
|
* remove empty directories
|
|
|
|
* mknod: hunt down DE_DELETED, compare name, reinstantiate.
|
|
|
|
* mkdir: want it ?
|
|
|
|
*/
|
|
|
|
|
2001-05-13 20:52:40 +00:00
|
|
|
#include <opt_devfs.h>
|
|
|
|
#ifndef NODEVFS
|
|
|
|
|
2000-08-20 21:34:39 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/conf.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/dirent.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/lock.h>
|
2000-08-20 21:34:39 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/namei.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/time.h>
|
2001-11-25 21:00:38 +00:00
|
|
|
#include <sys/unistd.h>
|
2001-05-01 08:13:21 +00:00
|
|
|
#include <sys/vnode.h>
|
2000-08-20 21:34:39 +00:00
|
|
|
|
|
|
|
#include <fs/devfs/devfs.h>
|
|
|
|
|
2002-03-19 22:20:14 +00:00
|
|
|
static int devfs_access(struct vop_access_args *ap);
|
|
|
|
static int devfs_getattr(struct vop_getattr_args *ap);
|
|
|
|
static int devfs_lookupx(struct vop_lookup_args *ap);
|
|
|
|
static int devfs_mknod(struct vop_mknod_args *ap);
|
|
|
|
static int devfs_pathconf(struct vop_pathconf_args *ap);
|
|
|
|
static int devfs_print(struct vop_print_args *ap);
|
|
|
|
static int devfs_read(struct vop_read_args *ap);
|
|
|
|
static int devfs_readdir(struct vop_readdir_args *ap);
|
|
|
|
static int devfs_readlink(struct vop_readlink_args *ap);
|
|
|
|
static int devfs_reclaim(struct vop_reclaim_args *ap);
|
|
|
|
static int devfs_remove(struct vop_remove_args *ap);
|
|
|
|
static int devfs_revoke(struct vop_revoke_args *ap);
|
|
|
|
static int devfs_setattr(struct vop_setattr_args *ap);
|
|
|
|
static int devfs_symlink(struct vop_symlink_args *ap);
|
2000-08-20 21:34:39 +00:00
|
|
|
|
2001-05-23 17:48:20 +00:00
|
|
|
/*
|
|
|
|
* Construct the fully qualified path name relative to the mountpoint
|
|
|
|
*/
|
|
|
|
static char *
|
|
|
|
devfs_fqpn(char *buf, struct vnode *dvp, struct componentname *cnp)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct devfs_dirent *de, *dd;
|
|
|
|
struct devfs_mount *dmp;
|
|
|
|
|
|
|
|
dmp = VFSTODEVFS(dvp->v_mount);
|
|
|
|
dd = dvp->v_data;
|
|
|
|
i = SPECNAMELEN;
|
|
|
|
buf[i] = '\0';
|
|
|
|
i -= cnp->cn_namelen;
|
|
|
|
if (i < 0)
|
|
|
|
return (NULL);
|
|
|
|
bcopy(cnp->cn_nameptr, buf + i, cnp->cn_namelen);
|
|
|
|
de = dd;
|
|
|
|
while (de != dmp->dm_basedir) {
|
|
|
|
i--;
|
|
|
|
if (i < 0)
|
|
|
|
return (NULL);
|
|
|
|
buf[i] = '/';
|
|
|
|
i -= de->de_dirent->d_namlen;
|
|
|
|
if (i < 0)
|
|
|
|
return (NULL);
|
|
|
|
bcopy(de->de_dirent->d_name, buf + i,
|
|
|
|
de->de_dirent->d_namlen);
|
|
|
|
de = TAILQ_FIRST(&de->de_dlist); /* "." */
|
|
|
|
de = TAILQ_NEXT(de, de_list); /* ".." */
|
|
|
|
de = de->de_dir;
|
|
|
|
}
|
|
|
|
return (buf + i);
|
|
|
|
}
|
|
|
|
|
2000-08-27 14:46:36 +00:00
|
|
|
int
|
2001-09-12 08:38:13 +00:00
|
|
|
devfs_allocv(struct devfs_dirent *de, struct mount *mp, struct vnode **vpp, struct thread *td)
|
2000-08-20 21:34:39 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct vnode *vp;
|
2000-09-06 11:26:43 +00:00
|
|
|
dev_t dev;
|
2000-08-20 21:34:39 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
if (td == NULL)
|
|
|
|
td = curthread; /* XXX */
|
2000-08-20 21:34:39 +00:00
|
|
|
loop:
|
|
|
|
vp = de->de_vnode;
|
|
|
|
if (vp != NULL) {
|
2001-09-12 08:38:13 +00:00
|
|
|
if (vget(vp, LK_EXCLUSIVE, td ? td : curthread))
|
2000-08-20 21:34:39 +00:00
|
|
|
goto loop;
|
|
|
|
*vpp = vp;
|
|
|
|
return (0);
|
|
|
|
}
|
2000-09-06 11:26:43 +00:00
|
|
|
if (de->de_dirent->d_type == DT_CHR) {
|
|
|
|
dev = *devfs_itod(de->de_inode);
|
|
|
|
if (dev == NULL)
|
|
|
|
return (ENOENT);
|
|
|
|
} else {
|
|
|
|
dev = NODEV;
|
|
|
|
}
|
2000-08-20 21:34:39 +00:00
|
|
|
error = getnewvnode(VT_DEVFS, mp, devfs_vnodeop_p, &vp);
|
|
|
|
if (error != 0) {
|
|
|
|
printf("devfs_allocv: failed to allocate new vnode\n");
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (de->de_dirent->d_type == DT_CHR) {
|
|
|
|
vp->v_type = VCHR;
|
2000-09-06 11:26:43 +00:00
|
|
|
vp = addaliasu(vp, dev->si_udev);
|
2000-08-20 21:34:39 +00:00
|
|
|
vp->v_op = devfs_specop_p;
|
|
|
|
} else if (de->de_dirent->d_type == DT_DIR) {
|
|
|
|
vp->v_type = VDIR;
|
|
|
|
} else if (de->de_dirent->d_type == DT_LNK) {
|
|
|
|
vp->v_type = VLNK;
|
|
|
|
} else {
|
|
|
|
vp->v_type = VBAD;
|
|
|
|
}
|
2000-08-24 15:36:55 +00:00
|
|
|
vp->v_data = de;
|
2000-08-20 21:34:39 +00:00
|
|
|
de->de_vnode = vp;
|
2001-09-12 08:38:13 +00:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
|
2000-08-20 21:34:39 +00:00
|
|
|
*vpp = vp;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
devfs_access(ap)
|
|
|
|
struct vop_access_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_mode;
|
|
|
|
struct ucred *a_cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
2000-08-20 21:34:39 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
2000-08-21 14:45:19 +00:00
|
|
|
struct devfs_dirent *de;
|
2000-08-20 21:34:39 +00:00
|
|
|
|
2000-08-24 15:36:55 +00:00
|
|
|
de = vp->v_data;
|
|
|
|
if (vp->v_type == VDIR)
|
|
|
|
de = de->de_dir;
|
2000-08-20 21:34:39 +00:00
|
|
|
|
|
|
|
return (vaccess(vp->v_type, de->de_mode, de->de_uid, de->de_gid,
|
2000-08-29 14:45:49 +00:00
|
|
|
ap->a_mode, ap->a_cred, NULL));
|
2000-08-20 21:34:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
devfs_getattr(ap)
|
|
|
|
struct vop_getattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
struct ucred *a_cred;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *a_td;
|
2000-08-20 21:34:39 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct vattr *vap = ap->a_vap;
|
|
|
|
int error = 0;
|
|
|
|
struct devfs_dirent *de;
|
2000-08-24 15:36:55 +00:00
|
|
|
dev_t dev;
|
2000-08-20 21:34:39 +00:00
|
|
|
|
2000-08-24 15:36:55 +00:00
|
|
|
de = vp->v_data;
|
2000-10-09 14:18:07 +00:00
|
|
|
if (vp->v_type == VDIR)
|
2000-08-24 15:36:55 +00:00
|
|
|
de = de->de_dir;
|
2000-08-20 21:34:39 +00:00
|
|
|
bzero((caddr_t) vap, sizeof(*vap));
|
|
|
|
vattr_null(vap);
|
|
|
|
vap->va_uid = de->de_uid;
|
|
|
|
vap->va_gid = de->de_gid;
|
|
|
|
vap->va_mode = de->de_mode;
|
2001-01-30 08:39:52 +00:00
|
|
|
if (vp->v_type == VLNK)
|
|
|
|
vap->va_size = de->de_dirent->d_namlen;
|
2001-11-25 21:00:38 +00:00
|
|
|
else if (vp->v_type == VDIR)
|
|
|
|
vap->va_size = vap->va_bytes = DEV_BSIZE;
|
2001-01-30 08:39:52 +00:00
|
|
|
else
|
|
|
|
vap->va_size = 0;
|
2001-11-25 21:00:38 +00:00
|
|
|
if (vp->v_type != VDIR)
|
|
|
|
vap->va_bytes = 0;
|
2000-08-20 21:34:39 +00:00
|
|
|
vap->va_blocksize = DEV_BSIZE;
|
2000-09-06 11:26:43 +00:00
|
|
|
vap->va_type = vp->v_type;
|
2001-02-02 22:54:41 +00:00
|
|
|
|
|
|
|
#define fix(aa) \
|
|
|
|
do { \
|
|
|
|
if ((aa).tv_sec == 0) { \
|
|
|
|
(aa).tv_sec = boottime.tv_sec; \
|
|
|
|
(aa).tv_nsec = boottime.tv_usec * 1000; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2000-08-24 15:36:55 +00:00
|
|
|
if (vp->v_type != VCHR) {
|
2001-02-02 22:54:41 +00:00
|
|
|
fix(de->de_atime);
|
2000-08-24 15:36:55 +00:00
|
|
|
vap->va_atime = de->de_atime;
|
2001-02-02 22:54:41 +00:00
|
|
|
fix(de->de_mtime);
|
2000-08-24 15:36:55 +00:00
|
|
|
vap->va_mtime = de->de_mtime;
|
2001-02-02 22:54:41 +00:00
|
|
|
fix(de->de_ctime);
|
2000-08-24 15:36:55 +00:00
|
|
|
vap->va_ctime = de->de_ctime;
|
|
|
|
} else {
|
|
|
|
dev = vp->v_rdev;
|
2001-02-02 22:54:41 +00:00
|
|
|
fix(dev->si_atime);
|
2000-08-24 15:36:55 +00:00
|
|
|
vap->va_atime = dev->si_atime;
|
2001-02-02 22:54:41 +00:00
|
|
|
fix(dev->si_mtime);
|
2000-08-24 15:36:55 +00:00
|
|
|
vap->va_mtime = dev->si_mtime;
|
2001-02-02 22:54:41 +00:00
|
|
|
fix(dev->si_ctime);
|
2000-08-24 15:36:55 +00:00
|
|
|
vap->va_ctime = dev->si_ctime;
|
2000-09-06 11:26:43 +00:00
|
|
|
vap->va_rdev = dev->si_udev;
|
2000-08-24 15:36:55 +00:00
|
|
|
}
|
2000-08-20 21:34:39 +00:00
|
|
|
vap->va_gen = 0;
|
|
|
|
vap->va_flags = 0;
|
2000-08-24 15:36:55 +00:00
|
|
|
vap->va_nlink = de->de_links;
|
2000-08-20 21:34:39 +00:00
|
|
|
vap->va_fileid = de->de_inode;
|
|
|
|
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-09-06 11:26:43 +00:00
|
|
|
devfs_lookupx(ap)
|
2000-08-27 14:46:36 +00:00
|
|
|
struct vop_lookup_args /* {
|
|
|
|
struct vnode * a_dvp;
|
|
|
|
struct vnode ** a_vpp;
|
|
|
|
struct componentname * a_cnp;
|
2000-08-20 21:34:39 +00:00
|
|
|
} */ *ap;
|
|
|
|
{
|
2000-08-27 14:46:36 +00:00
|
|
|
struct componentname *cnp;
|
|
|
|
struct vnode *dvp, **vpp;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
2000-08-27 14:46:36 +00:00
|
|
|
struct devfs_dirent *de, *dd;
|
|
|
|
struct devfs_mount *dmp;
|
2001-05-14 08:20:46 +00:00
|
|
|
dev_t cdev, *cpdev;
|
2001-05-23 17:48:20 +00:00
|
|
|
int error, cloned, flags, nameiop;
|
2000-08-27 14:46:36 +00:00
|
|
|
char specname[SPECNAMELEN + 1], *pname;
|
|
|
|
|
|
|
|
cnp = ap->a_cnp;
|
|
|
|
vpp = ap->a_vpp;
|
|
|
|
dvp = ap->a_dvp;
|
|
|
|
pname = cnp->cn_nameptr;
|
2001-09-12 08:38:13 +00:00
|
|
|
td = cnp->cn_thread;
|
2000-08-27 14:46:36 +00:00
|
|
|
flags = cnp->cn_flags;
|
|
|
|
nameiop = cnp->cn_nameiop;
|
|
|
|
dmp = VFSTODEVFS(dvp->v_mount);
|
|
|
|
cloned = 0;
|
|
|
|
dd = dvp->v_data;
|
|
|
|
|
|
|
|
*vpp = NULLVP;
|
2000-08-20 21:34:39 +00:00
|
|
|
|
2002-05-10 15:41:14 +00:00
|
|
|
if ((flags & ISLASTCN) && nameiop == RENAME)
|
2000-08-27 14:46:36 +00:00
|
|
|
return (EOPNOTSUPP);
|
|
|
|
|
|
|
|
if (dvp->v_type != VDIR)
|
|
|
|
return (ENOTDIR);
|
|
|
|
|
|
|
|
if ((flags & ISDOTDOT) && (dvp->v_flag & VROOT))
|
|
|
|
return (EIO);
|
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
error = VOP_ACCESS(dvp, VEXEC, cnp->cn_cred, td);
|
2000-08-27 14:46:36 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
if (cnp->cn_namelen == 1 && *pname == '.') {
|
2002-05-10 15:41:14 +00:00
|
|
|
if ((flags & ISLASTCN) && nameiop != LOOKUP)
|
2000-08-27 14:46:36 +00:00
|
|
|
return (EINVAL);
|
|
|
|
*vpp = dvp;
|
|
|
|
VREF(dvp);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & ISDOTDOT) {
|
2002-05-10 15:41:14 +00:00
|
|
|
if ((flags & ISLASTCN) && nameiop != LOOKUP)
|
2000-08-27 14:46:36 +00:00
|
|
|
return (EINVAL);
|
2001-09-12 08:38:13 +00:00
|
|
|
VOP_UNLOCK(dvp, 0, td);
|
2000-08-27 14:46:36 +00:00
|
|
|
de = TAILQ_FIRST(&dd->de_dlist); /* "." */
|
|
|
|
de = TAILQ_NEXT(de, de_list); /* ".." */
|
2000-08-24 15:36:55 +00:00
|
|
|
de = de->de_dir;
|
2001-09-12 08:38:13 +00:00
|
|
|
error = devfs_allocv(de, dvp->v_mount, vpp, td);
|
2000-08-27 14:46:36 +00:00
|
|
|
if (error) {
|
2001-09-12 08:38:13 +00:00
|
|
|
vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, td);
|
2000-08-27 14:46:36 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2000-10-09 14:18:07 +00:00
|
|
|
if ((flags & LOCKPARENT) && (flags & ISLASTCN))
|
2001-09-12 08:38:13 +00:00
|
|
|
error = vn_lock(dvp, LK_EXCLUSIVE, td);
|
2000-08-27 14:46:36 +00:00
|
|
|
if (error)
|
|
|
|
vput(*vpp);
|
|
|
|
return (error);
|
|
|
|
}
|
2000-08-20 21:34:39 +00:00
|
|
|
|
2000-08-27 14:46:36 +00:00
|
|
|
devfs_populate(dmp);
|
|
|
|
dd = dvp->v_data;
|
|
|
|
TAILQ_FOREACH(de, &dd->de_dlist, de_list) {
|
|
|
|
if (cnp->cn_namelen != de->de_dirent->d_namlen)
|
|
|
|
continue;
|
|
|
|
if (bcmp(cnp->cn_nameptr, de->de_dirent->d_name,
|
|
|
|
de->de_dirent->d_namlen) != 0)
|
|
|
|
continue;
|
2001-05-23 17:48:20 +00:00
|
|
|
if (de->de_flags & DE_WHITEOUT)
|
|
|
|
goto notfound;
|
2000-08-27 14:46:36 +00:00
|
|
|
goto found;
|
2000-08-24 15:36:55 +00:00
|
|
|
}
|
2000-08-27 14:46:36 +00:00
|
|
|
|
2001-05-23 17:48:20 +00:00
|
|
|
if (nameiop == DELETE)
|
|
|
|
goto notfound;
|
|
|
|
|
2000-08-27 14:46:36 +00:00
|
|
|
/*
|
|
|
|
* OK, we didn't have an entry for the name we were asked for
|
|
|
|
* so we try to see if anybody can create it on demand.
|
|
|
|
*/
|
2001-05-23 17:48:20 +00:00
|
|
|
pname = devfs_fqpn(specname, dvp, cnp);
|
|
|
|
if (pname == NULL)
|
|
|
|
goto notfound;
|
2000-08-27 14:46:36 +00:00
|
|
|
|
|
|
|
cdev = NODEV;
|
2001-05-23 17:48:20 +00:00
|
|
|
EVENTHANDLER_INVOKE(dev_clone, pname, strlen(pname), &cdev);
|
2000-10-09 14:18:07 +00:00
|
|
|
if (cdev == NODEV)
|
2000-08-27 14:46:36 +00:00
|
|
|
goto notfound;
|
|
|
|
|
|
|
|
devfs_populate(dmp);
|
|
|
|
dd = dvp->v_data;
|
2001-05-14 08:20:46 +00:00
|
|
|
|
2000-08-27 14:46:36 +00:00
|
|
|
TAILQ_FOREACH(de, &dd->de_dlist, de_list) {
|
2001-05-14 08:20:46 +00:00
|
|
|
cpdev = devfs_itod(de->de_inode);
|
|
|
|
if (cpdev != NULL && cdev == *cpdev)
|
|
|
|
goto found;
|
|
|
|
continue;
|
2000-08-24 15:36:55 +00:00
|
|
|
}
|
2000-08-20 21:34:39 +00:00
|
|
|
|
2000-08-27 14:46:36 +00:00
|
|
|
notfound:
|
|
|
|
|
|
|
|
if ((nameiop == CREATE || nameiop == RENAME) &&
|
|
|
|
(flags & (LOCKPARENT | WANTPARENT)) && (flags & ISLASTCN)) {
|
|
|
|
cnp->cn_flags |= SAVENAME;
|
|
|
|
if (!(flags & LOCKPARENT))
|
2001-09-12 08:38:13 +00:00
|
|
|
VOP_UNLOCK(dvp, 0, td);
|
2000-08-27 14:46:36 +00:00
|
|
|
return (EJUSTRETURN);
|
|
|
|
}
|
|
|
|
return (ENOENT);
|
|
|
|
|
|
|
|
|
|
|
|
found:
|
|
|
|
|
|
|
|
if ((cnp->cn_nameiop == DELETE) && (flags & ISLASTCN)) {
|
2001-09-12 08:38:13 +00:00
|
|
|
error = VOP_ACCESS(dvp, VWRITE, cnp->cn_cred, td);
|
2000-08-27 14:46:36 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
if (*vpp == dvp) {
|
|
|
|
VREF(dvp);
|
|
|
|
*vpp = dvp;
|
|
|
|
return (0);
|
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
error = devfs_allocv(de, dvp->v_mount, vpp, td);
|
2000-08-27 14:46:36 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
if (!(flags & LOCKPARENT))
|
2001-09-12 08:38:13 +00:00
|
|
|
VOP_UNLOCK(dvp, 0, td);
|
2000-08-27 14:46:36 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
error = devfs_allocv(de, dvp->v_mount, vpp, td);
|
2000-08-27 14:46:36 +00:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
if (!(flags & LOCKPARENT) || !(flags & ISLASTCN))
|
2001-09-12 08:38:13 +00:00
|
|
|
VOP_UNLOCK(dvp, 0, td);
|
2000-08-27 14:46:36 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-09-06 11:26:43 +00:00
|
|
|
static int
|
|
|
|
devfs_lookup(struct vop_lookup_args *ap)
|
|
|
|
{
|
|
|
|
int j;
|
|
|
|
struct devfs_mount *dmp;
|
|
|
|
|
|
|
|
dmp = VFSTODEVFS(ap->a_dvp->v_mount);
|
2001-09-12 08:38:13 +00:00
|
|
|
lockmgr(&dmp->dm_lock, LK_SHARED, 0, curthread);
|
2000-09-06 11:26:43 +00:00
|
|
|
j = devfs_lookupx(ap);
|
2001-09-12 08:38:13 +00:00
|
|
|
lockmgr(&dmp->dm_lock, LK_RELEASE, 0, curthread);
|
2000-09-06 11:26:43 +00:00
|
|
|
return (j);
|
|
|
|
}
|
|
|
|
|
2001-05-23 17:48:20 +00:00
|
|
|
static int
|
|
|
|
devfs_mknod(struct vop_mknod_args *ap)
|
|
|
|
/*
|
|
|
|
struct vop_mknod_args {
|
|
|
|
struct vnodeop_desc *a_desc;
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
struct componentname *cnp;
|
|
|
|
struct vnode *dvp, **vpp;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *td;
|
2001-05-23 17:48:20 +00:00
|
|
|
struct devfs_dirent *dd, *de;
|
|
|
|
struct devfs_mount *dmp;
|
|
|
|
int cloned, flags, nameiop;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
dvp = ap->a_dvp;
|
|
|
|
dmp = VFSTODEVFS(dvp->v_mount);
|
2001-09-12 08:38:13 +00:00
|
|
|
lockmgr(&dmp->dm_lock, LK_EXCLUSIVE, 0, curthread);
|
2001-05-23 17:48:20 +00:00
|
|
|
|
|
|
|
cnp = ap->a_cnp;
|
|
|
|
vpp = ap->a_vpp;
|
2001-09-12 08:38:13 +00:00
|
|
|
td = cnp->cn_thread;
|
2001-05-23 17:48:20 +00:00
|
|
|
flags = cnp->cn_flags;
|
|
|
|
nameiop = cnp->cn_nameiop;
|
|
|
|
cloned = 0;
|
|
|
|
dd = dvp->v_data;
|
|
|
|
|
|
|
|
error = ENOENT;
|
|
|
|
TAILQ_FOREACH(de, &dd->de_dlist, de_list) {
|
|
|
|
if (cnp->cn_namelen != de->de_dirent->d_namlen)
|
|
|
|
continue;
|
|
|
|
if (bcmp(cnp->cn_nameptr, de->de_dirent->d_name,
|
|
|
|
de->de_dirent->d_namlen) != 0)
|
|
|
|
continue;
|
|
|
|
if (de->de_flags & DE_WHITEOUT)
|
|
|
|
break;
|
|
|
|
goto notfound;
|
|
|
|
}
|
|
|
|
if (de == NULL)
|
|
|
|
goto notfound;
|
|
|
|
de->de_flags &= ~DE_WHITEOUT;
|
2001-09-12 08:38:13 +00:00
|
|
|
error = devfs_allocv(de, dvp->v_mount, vpp, td);
|
2001-05-23 17:48:20 +00:00
|
|
|
notfound:
|
2001-09-12 08:38:13 +00:00
|
|
|
lockmgr(&dmp->dm_lock, LK_RELEASE, 0, curthread);
|
2001-05-23 17:48:20 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-25 21:00:38 +00:00
|
|
|
static int
|
|
|
|
devfs_pathconf(ap)
|
|
|
|
struct vop_pathconf_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_name;
|
|
|
|
int *a_retval;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (ap->a_name) {
|
|
|
|
case _PC_NAME_MAX:
|
|
|
|
*ap->a_retval = NAME_MAX;
|
|
|
|
return (0);
|
|
|
|
case _PC_PATH_MAX:
|
|
|
|
*ap->a_retval = PATH_MAX;
|
|
|
|
return (0);
|
|
|
|
default:
|
|
|
|
return (vop_stdpathconf(ap));
|
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2000-08-27 14:46:36 +00:00
|
|
|
/* ARGSUSED */
|
|
|
|
static int
|
|
|
|
devfs_print(ap)
|
|
|
|
struct vop_print_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("tag VT_DEVFS, devfs vnode\n");
|
2000-08-20 21:34:39 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-08-26 16:20:57 +00:00
|
|
|
static int
|
|
|
|
devfs_read(ap)
|
|
|
|
struct vop_read_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
int a_ioflag;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
|
|
|
|
if (ap->a_vp->v_type != VDIR)
|
|
|
|
return (EINVAL);
|
|
|
|
return (VOP_READDIR(ap->a_vp, ap->a_uio, ap->a_cred, NULL, NULL, NULL));
|
|
|
|
}
|
|
|
|
|
2000-08-20 21:34:39 +00:00
|
|
|
static int
|
|
|
|
devfs_readdir(ap)
|
|
|
|
struct vop_readdir_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
int *a_eofflag;
|
|
|
|
int *a_ncookies;
|
|
|
|
u_long **a_cookies;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
2000-08-26 16:20:57 +00:00
|
|
|
int error;
|
|
|
|
struct uio *uio;
|
2000-08-20 21:34:39 +00:00
|
|
|
struct dirent *dp;
|
2000-08-24 15:36:55 +00:00
|
|
|
struct devfs_dirent *dd;
|
2000-08-20 21:34:39 +00:00
|
|
|
struct devfs_dirent *de;
|
2000-08-24 15:36:55 +00:00
|
|
|
struct devfs_mount *dmp;
|
2001-08-14 06:42:32 +00:00
|
|
|
off_t off, oldoff;
|
|
|
|
int ncookies = 0;
|
|
|
|
u_long *cookiebuf, *cookiep;
|
|
|
|
struct dirent *dps, *dpe;
|
2000-08-20 21:34:39 +00:00
|
|
|
|
|
|
|
if (ap->a_vp->v_type != VDIR)
|
|
|
|
return (ENOTDIR);
|
|
|
|
|
2000-08-26 16:20:57 +00:00
|
|
|
uio = ap->a_uio;
|
|
|
|
if (uio->uio_offset < 0)
|
|
|
|
return (EINVAL);
|
|
|
|
|
2000-08-24 15:36:55 +00:00
|
|
|
dmp = VFSTODEVFS(ap->a_vp->v_mount);
|
2001-09-12 08:38:13 +00:00
|
|
|
lockmgr(&dmp->dm_lock, LK_SHARED, 0, curthread);
|
2000-08-24 15:36:55 +00:00
|
|
|
devfs_populate(dmp);
|
2000-08-20 21:34:39 +00:00
|
|
|
error = 0;
|
2000-08-24 15:36:55 +00:00
|
|
|
de = ap->a_vp->v_data;
|
2000-08-20 21:34:39 +00:00
|
|
|
off = 0;
|
2001-08-14 06:42:32 +00:00
|
|
|
oldoff = uio->uio_offset;
|
2001-05-23 17:48:20 +00:00
|
|
|
TAILQ_FOREACH(dd, &de->de_dlist, de_list) {
|
|
|
|
if (dd->de_flags & DE_WHITEOUT)
|
|
|
|
continue;
|
2000-10-09 14:18:07 +00:00
|
|
|
if (dd->de_dirent->d_type == DT_DIR)
|
2000-08-24 15:36:55 +00:00
|
|
|
de = dd->de_dir;
|
|
|
|
else
|
|
|
|
de = dd;
|
|
|
|
dp = dd->de_dirent;
|
2000-08-26 16:20:57 +00:00
|
|
|
if (dp->d_reclen > uio->uio_resid)
|
|
|
|
break;
|
2000-08-20 21:34:39 +00:00
|
|
|
dp->d_fileno = de->de_inode;
|
2000-08-26 16:20:57 +00:00
|
|
|
if (off >= uio->uio_offset) {
|
2001-08-14 06:42:32 +00:00
|
|
|
ncookies++;
|
2000-08-26 16:20:57 +00:00
|
|
|
error = uiomove((caddr_t)dp, dp->d_reclen, uio);
|
|
|
|
if (error)
|
2000-08-20 21:34:39 +00:00
|
|
|
break;
|
2000-08-26 16:20:57 +00:00
|
|
|
}
|
2000-08-20 21:34:39 +00:00
|
|
|
off += dp->d_reclen;
|
|
|
|
}
|
2001-08-14 06:42:32 +00:00
|
|
|
if( !error && ap->a_ncookies != NULL && ap->a_cookies != NULL ) {
|
|
|
|
MALLOC(cookiebuf, u_long *, ncookies * sizeof(u_long),
|
|
|
|
M_TEMP, M_WAITOK);
|
|
|
|
cookiep = cookiebuf;
|
|
|
|
dps = (struct dirent *)
|
|
|
|
(uio->uio_iov->iov_base - (uio->uio_offset - oldoff));
|
|
|
|
dpe = (struct dirent *) uio->uio_iov->iov_base;
|
|
|
|
for( dp = dps;
|
|
|
|
dp < dpe;
|
|
|
|
dp = (struct dirent *)((caddr_t) dp + dp->d_reclen)) {
|
|
|
|
oldoff += dp->d_reclen;
|
|
|
|
*cookiep++ = (u_long) oldoff;
|
|
|
|
}
|
|
|
|
*ap->a_ncookies = ncookies;
|
|
|
|
*ap->a_cookies = cookiebuf;
|
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
lockmgr(&dmp->dm_lock, LK_RELEASE, 0, curthread);
|
2000-08-20 21:34:39 +00:00
|
|
|
uio->uio_offset = off;
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
devfs_readlink(ap)
|
|
|
|
struct vop_readlink_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct uio *a_uio;
|
|
|
|
struct ucred *a_cead;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct devfs_dirent *de;
|
|
|
|
|
|
|
|
de = ap->a_vp->v_data;
|
2001-05-26 20:07:57 +00:00
|
|
|
error = uiomove(de->de_symlink, strlen(de->de_symlink), ap->a_uio);
|
2000-08-20 21:34:39 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
devfs_reclaim(ap)
|
|
|
|
struct vop_reclaim_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
2000-08-24 15:36:55 +00:00
|
|
|
struct devfs_dirent *de;
|
2000-10-09 14:18:07 +00:00
|
|
|
int i;
|
2000-08-20 21:34:39 +00:00
|
|
|
|
2000-08-24 15:36:55 +00:00
|
|
|
de = vp->v_data;
|
2000-10-09 14:18:07 +00:00
|
|
|
if (de != NULL)
|
|
|
|
de->de_vnode = NULL;
|
2000-08-20 21:34:39 +00:00
|
|
|
vp->v_data = NULL;
|
2000-10-09 14:18:07 +00:00
|
|
|
if (vp->v_rdev != NODEV && vp->v_rdev != NULL) {
|
|
|
|
i = vcount(vp);
|
2001-06-01 15:51:10 +00:00
|
|
|
if ((vp->v_rdev->si_flags & SI_CHEAPCLONE) && i == 0 &&
|
|
|
|
(vp->v_rdev->si_flags & SI_NAMED))
|
2000-10-09 14:18:07 +00:00
|
|
|
destroy_dev(vp->v_rdev);
|
|
|
|
}
|
2000-08-20 21:34:39 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
devfs_remove(ap)
|
|
|
|
struct vop_remove_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
2000-08-24 15:36:55 +00:00
|
|
|
struct devfs_dirent *dd;
|
2001-05-23 17:48:20 +00:00
|
|
|
struct devfs_dirent *de;
|
2000-09-06 11:26:43 +00:00
|
|
|
struct devfs_mount *dmp = VFSTODEVFS(vp->v_mount);
|
2000-08-20 21:34:39 +00:00
|
|
|
|
2001-09-12 08:38:13 +00:00
|
|
|
lockmgr(&dmp->dm_lock, LK_EXCLUSIVE, 0, curthread);
|
2000-08-20 21:34:39 +00:00
|
|
|
dd = ap->a_dvp->v_data;
|
|
|
|
de = vp->v_data;
|
2001-09-30 08:43:33 +00:00
|
|
|
if (de->de_dirent->d_type == DT_LNK) {
|
|
|
|
TAILQ_REMOVE(&dd->de_dlist, de, de_list);
|
|
|
|
if (de->de_vnode)
|
|
|
|
de->de_vnode->v_data = NULL;
|
|
|
|
FREE(de, M_DEVFS);
|
|
|
|
} else {
|
|
|
|
de->de_flags |= DE_WHITEOUT;
|
|
|
|
}
|
2001-09-12 08:38:13 +00:00
|
|
|
lockmgr(&dmp->dm_lock, LK_RELEASE, 0, curthread);
|
2000-08-20 21:34:39 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Revoke is called on a tty when a terminal session ends. The vnode
|
|
|
|
* is orphaned by setting v_op to deadfs so we need to let go of it
|
|
|
|
* as well so that we create a new one next time around.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
devfs_revoke(ap)
|
|
|
|
struct vop_revoke_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
int a_flags;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct vnode *vp = ap->a_vp;
|
|
|
|
struct devfs_dirent *de;
|
|
|
|
|
|
|
|
de = vp->v_data;
|
|
|
|
de->de_vnode = NULL;
|
|
|
|
vop_revoke(ap);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-08-27 14:46:36 +00:00
|
|
|
static int
|
|
|
|
devfs_setattr(ap)
|
|
|
|
struct vop_setattr_args /* {
|
|
|
|
struct vnode *a_vp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
struct ucred *a_cred;
|
|
|
|
struct proc *a_p;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
|
|
|
struct devfs_dirent *de;
|
2000-09-16 12:06:58 +00:00
|
|
|
struct vattr *vap;
|
2001-11-03 17:00:02 +00:00
|
|
|
struct vnode *vp;
|
2000-09-16 12:06:58 +00:00
|
|
|
int c, error;
|
|
|
|
uid_t uid;
|
|
|
|
gid_t gid;
|
|
|
|
|
|
|
|
vap = ap->a_vap;
|
2001-11-03 17:00:02 +00:00
|
|
|
vp = ap->a_vp;
|
2000-09-16 12:06:58 +00:00
|
|
|
if ((vap->va_type != VNON) ||
|
|
|
|
(vap->va_nlink != VNOVAL) ||
|
|
|
|
(vap->va_fsid != VNOVAL) ||
|
|
|
|
(vap->va_fileid != VNOVAL) ||
|
|
|
|
(vap->va_blocksize != VNOVAL) ||
|
2000-09-18 09:40:01 +00:00
|
|
|
(vap->va_flags != VNOVAL && vap->va_flags != 0) ||
|
2000-09-16 12:06:58 +00:00
|
|
|
(vap->va_rdev != VNOVAL) ||
|
|
|
|
((int)vap->va_bytes != VNOVAL) ||
|
|
|
|
(vap->va_gen != VNOVAL)) {
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
2000-08-27 14:46:36 +00:00
|
|
|
|
2001-11-03 17:00:02 +00:00
|
|
|
de = vp->v_data;
|
|
|
|
if (vp->v_type == VDIR)
|
2000-08-27 14:46:36 +00:00
|
|
|
de = de->de_dir;
|
|
|
|
|
2000-09-16 12:06:58 +00:00
|
|
|
error = c = 0;
|
|
|
|
if (vap->va_uid == (uid_t)VNOVAL)
|
|
|
|
uid = de->de_uid;
|
|
|
|
else
|
|
|
|
uid = vap->va_uid;
|
|
|
|
if (vap->va_gid == (gid_t)VNOVAL)
|
|
|
|
gid = de->de_gid;
|
|
|
|
else
|
|
|
|
gid = vap->va_gid;
|
|
|
|
if (uid != de->de_uid || gid != de->de_gid) {
|
|
|
|
if (((ap->a_cred->cr_uid != de->de_uid) || uid != de->de_uid ||
|
|
|
|
(gid != de->de_gid && !groupmember(gid, ap->a_cred))) &&
|
2002-04-01 21:31:13 +00:00
|
|
|
(error = suser_cred(ap->a_td->td_ucred, PRISON_ROOT)) != 0)
|
2000-09-16 12:06:58 +00:00
|
|
|
return (error);
|
|
|
|
de->de_uid = uid;
|
|
|
|
de->de_gid = gid;
|
2000-08-27 14:46:36 +00:00
|
|
|
c = 1;
|
|
|
|
}
|
2001-11-03 17:00:02 +00:00
|
|
|
|
2000-09-16 12:06:58 +00:00
|
|
|
if (vap->va_mode != (mode_t)VNOVAL) {
|
|
|
|
if ((ap->a_cred->cr_uid != de->de_uid) &&
|
2002-04-01 21:31:13 +00:00
|
|
|
(error = suser_cred(ap->a_td->td_ucred, PRISON_ROOT)))
|
2000-09-16 12:06:58 +00:00
|
|
|
return (error);
|
|
|
|
de->de_mode = vap->va_mode;
|
2000-08-27 14:46:36 +00:00
|
|
|
c = 1;
|
|
|
|
}
|
2002-04-05 15:16:08 +00:00
|
|
|
|
|
|
|
if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
|
|
|
|
/* See the comment in ufs_vnops::ufs_setattr(). */
|
|
|
|
if ((error = VOP_ACCESS(vp, VADMIN, ap->a_cred, ap->a_td)) &&
|
|
|
|
((vap->va_vaflags & VA_UTIMES_NULL) == 0 ||
|
|
|
|
(error = VOP_ACCESS(vp, VWRITE, ap->a_cred, ap->a_td))))
|
2000-09-16 12:06:58 +00:00
|
|
|
return (error);
|
2002-04-05 15:16:08 +00:00
|
|
|
if (vap->va_atime.tv_sec != VNOVAL) {
|
|
|
|
if (vp->v_type == VCHR)
|
|
|
|
vp->v_rdev->si_atime = vap->va_atime;
|
|
|
|
else
|
|
|
|
de->de_atime = vap->va_atime;
|
|
|
|
}
|
|
|
|
if (vap->va_mtime.tv_sec != VNOVAL) {
|
|
|
|
if (vp->v_type == VCHR)
|
|
|
|
vp->v_rdev->si_mtime = vap->va_mtime;
|
|
|
|
else
|
|
|
|
de->de_mtime = vap->va_mtime;
|
|
|
|
}
|
2000-08-27 14:46:36 +00:00
|
|
|
c = 1;
|
|
|
|
}
|
|
|
|
|
2002-04-05 15:16:08 +00:00
|
|
|
if (c) {
|
|
|
|
if (vp->v_type == VCHR)
|
|
|
|
vfs_timestamp(&vp->v_rdev->si_ctime);
|
|
|
|
else
|
|
|
|
vfs_timestamp(&de->de_mtime);
|
|
|
|
}
|
2000-08-27 14:46:36 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-08-20 21:34:39 +00:00
|
|
|
static int
|
|
|
|
devfs_symlink(ap)
|
|
|
|
struct vop_symlink_args /* {
|
|
|
|
struct vnode *a_dvp;
|
|
|
|
struct vnode **a_vpp;
|
|
|
|
struct componentname *a_cnp;
|
|
|
|
struct vattr *a_vap;
|
|
|
|
char *a_target;
|
|
|
|
} */ *ap;
|
|
|
|
{
|
2001-02-02 18:35:29 +00:00
|
|
|
int i, error;
|
2000-08-24 15:36:55 +00:00
|
|
|
struct devfs_dirent *dd;
|
2000-08-20 21:34:39 +00:00
|
|
|
struct devfs_dirent *de;
|
2000-08-24 15:36:55 +00:00
|
|
|
struct devfs_mount *dmp;
|
2000-08-20 21:34:39 +00:00
|
|
|
|
2002-04-01 21:31:13 +00:00
|
|
|
error = suser(ap->a_cnp->cn_thread);
|
2001-02-02 18:35:29 +00:00
|
|
|
if (error)
|
|
|
|
return(error);
|
2000-08-27 14:46:36 +00:00
|
|
|
dmp = VFSTODEVFS(ap->a_dvp->v_mount);
|
2000-08-20 21:34:39 +00:00
|
|
|
dd = ap->a_dvp->v_data;
|
|
|
|
de = devfs_newdirent(ap->a_cnp->cn_nameptr, ap->a_cnp->cn_namelen);
|
|
|
|
de->de_uid = 0;
|
|
|
|
de->de_gid = 0;
|
2001-02-02 18:35:29 +00:00
|
|
|
de->de_mode = 0755;
|
2000-08-24 15:36:55 +00:00
|
|
|
de->de_inode = dmp->dm_inode++;
|
2000-08-20 21:34:39 +00:00
|
|
|
de->de_dirent->d_type = DT_LNK;
|
|
|
|
i = strlen(ap->a_target) + 1;
|
|
|
|
MALLOC(de->de_symlink, char *, i, M_DEVFS, M_WAITOK);
|
|
|
|
bcopy(ap->a_target, de->de_symlink, i);
|
2001-09-12 08:38:13 +00:00
|
|
|
lockmgr(&dmp->dm_lock, LK_EXCLUSIVE, 0, curthread);
|
2000-08-24 15:36:55 +00:00
|
|
|
TAILQ_INSERT_TAIL(&dd->de_dlist, de, de_list);
|
2000-08-20 21:34:39 +00:00
|
|
|
devfs_allocv(de, ap->a_dvp->v_mount, ap->a_vpp, 0);
|
2001-09-12 08:38:13 +00:00
|
|
|
lockmgr(&dmp->dm_lock, LK_RELEASE, 0, curthread);
|
2000-08-20 21:34:39 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-12-08 15:07:24 +00:00
|
|
|
static vop_t **devfs_vnodeop_p;
|
2000-08-20 21:34:39 +00:00
|
|
|
static struct vnodeopv_entry_desc devfs_vnodeop_entries[] = {
|
|
|
|
{ &vop_default_desc, (vop_t *) vop_defaultop },
|
|
|
|
{ &vop_access_desc, (vop_t *) devfs_access },
|
|
|
|
{ &vop_getattr_desc, (vop_t *) devfs_getattr },
|
2002-04-29 20:00:39 +00:00
|
|
|
{ &vop_islocked_desc, (vop_t *) vop_stdislocked },
|
|
|
|
{ &vop_lock_desc, (vop_t *) vop_stdlock },
|
2000-08-20 21:34:39 +00:00
|
|
|
{ &vop_lookup_desc, (vop_t *) devfs_lookup },
|
2001-05-23 17:48:20 +00:00
|
|
|
{ &vop_mknod_desc, (vop_t *) devfs_mknod },
|
2001-11-25 21:00:38 +00:00
|
|
|
{ &vop_pathconf_desc, (vop_t *) devfs_pathconf },
|
2000-08-20 21:34:39 +00:00
|
|
|
{ &vop_print_desc, (vop_t *) devfs_print },
|
2000-08-26 16:20:57 +00:00
|
|
|
{ &vop_read_desc, (vop_t *) devfs_read },
|
2000-08-20 21:34:39 +00:00
|
|
|
{ &vop_readdir_desc, (vop_t *) devfs_readdir },
|
|
|
|
{ &vop_readlink_desc, (vop_t *) devfs_readlink },
|
|
|
|
{ &vop_reclaim_desc, (vop_t *) devfs_reclaim },
|
|
|
|
{ &vop_remove_desc, (vop_t *) devfs_remove },
|
|
|
|
{ &vop_revoke_desc, (vop_t *) devfs_revoke },
|
|
|
|
{ &vop_setattr_desc, (vop_t *) devfs_setattr },
|
|
|
|
{ &vop_symlink_desc, (vop_t *) devfs_symlink },
|
2002-04-29 20:00:39 +00:00
|
|
|
{ &vop_unlock_desc, (vop_t *) vop_stdunlock },
|
2000-08-20 21:34:39 +00:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
static struct vnodeopv_desc devfs_vnodeop_opv_desc =
|
|
|
|
{ &devfs_vnodeop_p, devfs_vnodeop_entries };
|
|
|
|
|
|
|
|
VNODEOP_SET(devfs_vnodeop_opv_desc);
|
|
|
|
|
2000-12-08 15:07:24 +00:00
|
|
|
static vop_t **devfs_specop_p;
|
2000-08-20 21:34:39 +00:00
|
|
|
static struct vnodeopv_entry_desc devfs_specop_entries[] = {
|
|
|
|
{ &vop_default_desc, (vop_t *) spec_vnoperate },
|
|
|
|
{ &vop_access_desc, (vop_t *) devfs_access },
|
|
|
|
{ &vop_getattr_desc, (vop_t *) devfs_getattr },
|
2002-04-29 20:00:39 +00:00
|
|
|
{ &vop_islocked_desc, (vop_t *) vop_stdislocked },
|
|
|
|
{ &vop_lock_desc, (vop_t *) vop_stdlock },
|
2000-08-20 21:34:39 +00:00
|
|
|
{ &vop_print_desc, (vop_t *) devfs_print },
|
|
|
|
{ &vop_reclaim_desc, (vop_t *) devfs_reclaim },
|
|
|
|
{ &vop_remove_desc, (vop_t *) devfs_remove },
|
|
|
|
{ &vop_revoke_desc, (vop_t *) devfs_revoke },
|
|
|
|
{ &vop_setattr_desc, (vop_t *) devfs_setattr },
|
2002-04-29 20:00:39 +00:00
|
|
|
{ &vop_unlock_desc, (vop_t *) vop_stdunlock },
|
2000-08-20 21:34:39 +00:00
|
|
|
{ NULL, NULL }
|
|
|
|
};
|
|
|
|
static struct vnodeopv_desc devfs_specop_opv_desc =
|
|
|
|
{ &devfs_specop_p, devfs_specop_entries };
|
|
|
|
|
|
|
|
VNODEOP_SET(devfs_specop_opv_desc);
|
2001-05-13 20:52:40 +00:00
|
|
|
#endif
|