*
* %sccs.include.redist.c%
*
- * @(#)ufs_vnops.c 7.65 (Berkeley) %G%
+ * @(#)ufs_vnops.c 7.68 (Berkeley) %G%
*/
#include <sys/param.h>
static int ufs_chmod __P((struct vnode *, int, struct proc *));
static int ufs_chown __P((struct vnode *, u_int, u_int, struct proc *));
-#ifdef FIFO
-struct vnodeops fifo_inodeops = {
- fifo_lookup, /* lookup */
- fifo_create, /* create */
- fifo_mknod, /* mknod */
- fifo_open, /* open */
- ufsfifo_close, /* close */
- ufs_access, /* access */
- ufs_getattr, /* getattr */
- ufs_setattr, /* setattr */
- ufsfifo_read, /* read */
- ufsfifo_write, /* write */
- fifo_ioctl, /* ioctl */
- fifo_select, /* select */
- fifo_mmap, /* mmap */
- fifo_fsync, /* fsync */
- fifo_seek, /* seek */
- fifo_remove, /* remove */
- fifo_link, /* link */
- fifo_rename, /* rename */
- fifo_mkdir, /* mkdir */
- fifo_rmdir, /* rmdir */
- fifo_symlink, /* symlink */
- fifo_readdir, /* readdir */
- fifo_readlink, /* readlink */
- fifo_abortop, /* abortop */
- ufs_inactive, /* inactive */
- ufs_reclaim, /* reclaim */
- ufs_lock, /* lock */
- ufs_unlock, /* unlock */
- fifo_bmap, /* bmap */
- fifo_strategy, /* strategy */
- ufs_print, /* print */
- ufs_islocked, /* islocked */
- fifo_advlock, /* advlock */
-};
-#endif /* FIFO */
-
-struct vnodeops spec_inodeops = {
- spec_lookup, /* lookup */
- spec_create, /* create */
- spec_mknod, /* mknod */
- spec_open, /* open */
- ufsspec_close, /* close */
- ufs_access, /* access */
- ufs_getattr, /* getattr */
- ufs_setattr, /* setattr */
- ufsspec_read, /* read */
- ufsspec_write, /* write */
- spec_ioctl, /* ioctl */
- spec_select, /* select */
- spec_mmap, /* mmap */
- spec_fsync, /* fsync */
- spec_seek, /* seek */
- spec_remove, /* remove */
- spec_link, /* link */
- spec_rename, /* rename */
- spec_mkdir, /* mkdir */
- spec_rmdir, /* rmdir */
- spec_symlink, /* symlink */
- spec_readdir, /* readdir */
- spec_readlink, /* readlink */
- spec_abortop, /* abortop */
- ufs_inactive, /* inactive */
- ufs_reclaim, /* reclaim */
- ufs_lock, /* lock */
- ufs_unlock, /* unlock */
- spec_bmap, /* bmap */
- spec_strategy, /* strategy */
- ufs_print, /* print */
- ufs_islocked, /* islocked */
- spec_advlock, /* advlock */
-};
-
enum vtype iftovt_tab[16] = {
VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON,
VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VBAD,
struct vattr *vap;
struct proc *p;
{
- struct ufsmount *ump;
- struct inode *ip;
+ struct vnode *vp;
int error;
- ump = VFSTOUFS(ndp->ni_dvp->v_mount);
if (error =
- ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode), ndp, &ip))
+ ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode), ndp, &vp))
return (error);
- ndp->ni_vp = ITOV(ip);
+ ndp->ni_vp = vp;
return (0);
}
struct ucred *cred;
struct proc *p;
{
- register struct vnode *vp;
- struct inode *ip;
- struct ufsmount *ump;
+ register struct inode *ip;
+ struct vnode *vp;
int error;
- ump = VFSTOUFS(ndp->ni_dvp->v_mount);
if (error =
- ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode), ndp, &ip))
+ ufs_makeinode(MAKEIMODE(vap->va_type, vap->va_mode), ndp, &vp))
return (error);
+ ip = VTOI(vp);
ip->i_flag |= IACC|IUPD|ICHG;
if (vap->va_rdev != VNOVAL) {
/*
* checked to see if it is an alias of an existing entry
* in the inode cache.
*/
- vp = ITOV(ip);
vput(vp);
vp->v_type = VNON;
vgone(vp);
struct proc *p;
{
register struct inode *ip;
- struct ufsmount *ump;
int error;
/*
if (vap->va_uid != (u_short)VNOVAL || vap->va_gid != (u_short)VNOVAL)
if (error = ufs_chown(vp, vap->va_uid, vap->va_gid, p))
return (error);
- ip = VTOI(vp);
- ump = VFSTOUFS(vp->v_mount);
if (vap->va_size != VNOVAL) {
if (vp->v_type == VDIR)
return (EISDIR);
- if (error =
- (ump->um_itrunc)(ip, vap->va_size, 0)) /* XXX IO_SYNC? */
+ if (error = VOP_TRUNCATE(vp, vap->va_size, 0)) /* IO_SYNC? */
return (error);
}
+ ip = VTOI(vp);
if (vap->va_atime.tv_sec != VNOVAL || vap->va_mtime.tv_sec != VNOVAL) {
if (cred->cr_uid != ip->i_uid &&
(error = suser(cred, &p->p_acflag)))
if (vap->va_mtime.tv_sec != VNOVAL)
ip->i_flag |= IUPD;
ip->i_flag |= ICHG;
- if (error =
- (ump->um_iupdat)(ip, &vap->va_atime, &vap->va_mtime, 1))
+ if (error = VOP_UPDATE(vp, &vap->va_atime, &vap->va_mtime, 1))
return (error);
}
error = 0;
* Change the mode on a file.
* Inode must be locked before calling.
*/
-int
+static int
ufs_chmod(vp, mode, p)
register struct vnode *vp;
register int mode;
* Perform chown operation on inode ip;
* inode must be locked prior to call.
*/
-int
+static int
ufs_chown(vp, uid, gid, p)
register struct vnode *vp;
u_int uid;
struct proc *p;
{
register struct inode *ip;
- struct ufsmount *ump;
int error;
#ifdef DIANOSTIC
ILOCK(ip);
ip->i_nlink++;
ip->i_flag |= ICHG;
- ump = VFSTOUFS(ndp->ni_dvp->v_mount);
- error = (ump->um_iupdat)(ip, &time, &time, 1);
+ error = VOP_UPDATE(vp, &time, &time, 1);
if (!error)
error = ufs_direnter(ip, ndp);
if (ndp->ni_dvp != vp)
{
register struct inode *ip, *xp, *dp;
struct dirtemplate dirbuf;
- struct ufsmount *ump;
int doingdirectory = 0, oldparent = 0, newparent = 0;
int error = 0;
*/
ip->i_nlink++;
ip->i_flag |= ICHG;
- ump = VFSTOUFS(fndp->ni_dvp->v_mount);
- error = (ump->um_iupdat)(ip, &time, &time, 1);
+ error = VOP_UPDATE(fndp->ni_vp, &time, &time, 1);
IUNLOCK(ip);
/*
}
dp->i_nlink++;
dp->i_flag |= ICHG;
- if (error = (ump->um_iupdat)(dp, &time, &time, 1))
+ if (error = VOP_UPDATE(ITOV(dp), &time, &time, 1))
goto bad;
}
if (error = ufs_direnter(ip, tndp)) {
if (doingdirectory && newparent) {
dp->i_nlink--;
dp->i_flag |= ICHG;
- (void)(ump->um_iupdat)(dp, &time, &time, 1);
+ (void)VOP_UPDATE(ITOV(dp), &time, &time, 1);
}
goto bad;
}
dp->i_nlink--;
dp->i_flag |= ICHG;
}
- vput(ITOV(dp));
+ ufs_iput(dp);
/*
* Adjust the link count of the target to
* reflect the dirrewrite above. If this is
if (doingdirectory) {
if (--xp->i_nlink != 0)
panic("rename: linked directory");
- error = (ump->um_itrunc)(xp, (u_long)0, IO_SYNC);
+ error = VOP_TRUNCATE(ITOV(xp), (u_long)0, IO_SYNC);
}
xp->i_flag |= ICHG;
ufs_iput(xp);
struct proc *p;
{
register struct inode *ip, *dp;
- struct inode *tip;
- struct ufsmount *ump;
+ struct vnode *tvp;
struct vnode *dvp;
struct dirtemplate dirtemplate;
int error;
* not have it entered in the parent directory. The entry is made
* later after writing "." and ".." entries.
*/
- ump = VFSTOUFS(ndp->ni_dvp->v_mount);
- if (error = (ump->um_ialloc)(dp, dmode, ndp->ni_cred, &tip)) {
+ if (error = VOP_VALLOC(dvp, dmode, ndp->ni_cred, &tvp)) {
free(ndp->ni_pnbuf, M_NAMEI);
ufs_iput(dp);
return (error);
}
- ip = tip;
+ ip = VTOI(tvp);
ip->i_uid = ndp->ni_cred->cr_uid;
ip->i_gid = dp->i_gid;
#ifdef QUOTA
if ((error = getinoquota(ip)) ||
(error = chkiq(ip, 1, ndp->ni_cred, 0))) {
free(ndp->ni_pnbuf, M_NAMEI);
- (ump->um_ifree)(ip, ip->i_number, dmode);
+ VOP_VFREE(tvp, ip->i_number, dmode);
ufs_iput(ip);
ufs_iput(dp);
return (error);
ip->i_mode = dmode;
ITOV(ip)->v_type = VDIR; /* Rest init'd in iget() */
ip->i_nlink = 2;
- error = (ump->um_iupdat)(ip, &time, &time, 1);
+ error = VOP_UPDATE(ITOV(ip), &time, &time, 1);
/*
* Bump link count in parent directory
*/
dp->i_nlink++;
dp->i_flag |= ICHG;
- if (error = (ump->um_iupdat)(dp, &time, &time, 1))
+ if (error = VOP_UPDATE(ITOV(dp), &time, &time, 1))
goto bad;
/* Initialize directory with "." and ".." from static template. */
dp->i_flag |= ICHG;
goto bad;
}
- if (DIRBLKSIZ > ump->um_mountp->mnt_stat.f_fsize)
+ if (DIRBLKSIZ > VFSTOUFS(dvp->v_mount)->um_mountp->mnt_stat.f_fsize)
panic("ufs_mkdir: blksize"); /* XXX should grow with balloc() */
else {
ip->i_size = DIRBLKSIZ;
}
bad:
/*
- * No need to do an explicit itrunc here, vrele will do this for us
- * because we set the link count to 0.
+ * No need to do an explicit VOP_TRUNCATE here, vrele will do this
+ * for us because we set the link count to 0.
*/
if (error) {
ip->i_nlink = 0;
struct proc *p;
{
register struct inode *ip, *dp;
- struct ufsmount *ump;
int error;
ip = VTOI(ndp->ni_vp);
* No rmdir "." please.
*/
if (dp == ip) {
- vrele(ITOV(dp));
+ vrele(ndp->ni_dvp);
ufs_iput(ip);
return (EINVAL);
}
goto out;
dp->i_nlink--;
dp->i_flag |= ICHG;
- cache_purge(ITOV(dp));
+ cache_purge(ndp->ni_dvp);
ufs_iput(dp);
ndp->ni_dvp = NULL;
/*
* worry about them later.
*/
ip->i_nlink -= 2;
- ump = VFSTOUFS(ndp->ni_dvp->v_mount);
- error = (ump->um_itrunc)(ip, (u_long)0, IO_SYNC);
+ error = VOP_TRUNCATE(ndp->ni_vp, (u_long)0, IO_SYNC);
cache_purge(ITOV(ip));
out:
if (ndp->ni_dvp)
char *target;
struct proc *p;
{
- struct inode *ip;
- struct ufsmount *ump;
+ struct vnode *vp;
int error;
- ump = VFSTOUFS(ndp->ni_dvp->v_mount);
- if (error = ufs_makeinode(IFLNK | vap->va_mode, ndp, &ip))
+ if (error = ufs_makeinode(IFLNK | vap->va_mode, ndp, &vp))
return (error);
- error = vn_rdwr(UIO_WRITE, ITOV(ip), target, strlen(target), (off_t)0,
+ error = vn_rdwr(UIO_WRITE, vp, target, strlen(target), (off_t)0,
UIO_SYSSPACE, IO_NODELOCKED, ndp->ni_cred, (int *)0,
(struct proc *)0);
- ufs_iput(ip);
+ vput(vp);
return (error);
}
return (0);
}
-/*
- * Get access to bmap
- */
-int
-ufs_bmap(vp, bn, vpp, bnp)
- struct vnode *vp;
- daddr_t bn;
- struct vnode **vpp;
- daddr_t *bnp;
-{
- struct inode *ip;
- struct ufsmount *ump;
-
- ip = VTOI(vp);
- if (vpp != NULL)
- *vpp = ip->i_devvp;
- if (bnp == NULL)
- return (0);
- ump = VFSTOUFS(vp->v_mount);
- return ((ump->um_bmap)(ip, bn, bnp));
-}
-
/*
* Calculate the logical to physical mapping if not done already,
* then call the device strategy routine.
register struct buf *bp;
{
register struct inode *ip;
- struct ufsmount *ump;
struct vnode *vp;
int error;
if (bp->b_vp->v_type == VBLK || bp->b_vp->v_type == VCHR)
panic("ufs_strategy: spec");
if (bp->b_blkno == bp->b_lblkno) {
- ump = VFSTOUFS(bp->b_vp->v_mount);
- if (error = (ump->um_bmap)(ip, bp->b_lblkno, &bp->b_blkno))
+ if (error =
+ VOP_BMAP(bp->b_vp, bp->b_lblkno, NULL, &bp->b_blkno))
return (error);
if ((long)bp->b_blkno == -1)
clrbuf(bp);
* vnodes.
*/
int
-ufs_vinit(mntp, vpp)
+ufs_vinit(mntp, specops, fifoops, vpp)
struct mount *mntp;
+ struct vnodeops *specops, *fifoops;
struct vnode **vpp;
{
struct inode *ip, *nip;
switch(vp->v_type = IFTOVT(ip->i_mode)) {
case VCHR:
case VBLK:
- vp->v_op = &spec_inodeops;
+ vp->v_op = specops;
if (nvp = checkalias(vp, ip->i_rdev, mntp)) {
- /* Reinitialize aliased inode. */
+ /*
+ * Reinitialize aliased inode.
+ */
vp = nvp;
nip = VTOI(vp);
nip->i_vnode = vp;
nip->i_dev = ip->i_dev;
nip->i_number = ip->i_number;
ufs_ihashins(nip);
-
- /* Discard unneeded inode. */
+ /*
+ * Discard unneeded inode.
+ */
ip->i_mode = 0;
ufs_iput(ip);
-
ip = nip;
}
break;
case VFIFO:
#ifdef FIFO
- vp->v_op = &fifo_inodeops;
+ vp->v_op = fifoops;
break;
#else
return (EOPNOTSUPP);
#endif
}
- VREF(ip->i_devvp);
-
if (ip->i_number == ROOTINO)
vp->v_flag |= VROOT;
-
*vpp = vp;
return (0);
}
* Allocate a new inode.
*/
int
-ufs_makeinode(mode, ndp, ipp)
+ufs_makeinode(mode, ndp, vpp)
int mode;
register struct nameidata *ndp;
- struct inode **ipp;
+ struct vnode **vpp;
{
register struct inode *ip, *pdir;
- struct inode *tip;
- struct ufsmount *ump;
+ struct vnode *tvp;
int error;
pdir = VTOI(ndp->ni_dvp);
if ((ndp->ni_nameiop & HASBUF) == 0)
panic("ufs_makeinode: no name");
#endif
- *ipp = NULL;
+ *vpp = NULL;
if ((mode & IFMT) == 0)
mode |= IFREG;
- ump = VFSTOUFS(ndp->ni_dvp->v_mount);
- if (error = (ump->um_ialloc)(pdir, mode, ndp->ni_cred, &tip)) {
+ if (error = VOP_VALLOC(ndp->ni_dvp, mode, ndp->ni_cred, &tvp)) {
free(ndp->ni_pnbuf, M_NAMEI);
ufs_iput(pdir);
return (error);
}
- ip = tip;
+ ip = VTOI(tvp);
ip->i_uid = ndp->ni_cred->cr_uid;
ip->i_gid = pdir->i_gid;
#ifdef QUOTA
if ((error = getinoquota(ip)) ||
(error = chkiq(ip, 1, ndp->ni_cred, 0))) {
free(ndp->ni_pnbuf, M_NAMEI);
- (ump->um_ifree)(ip, ip->i_number, mode);
+ VOP_VFREE(tvp, ip->i_number, mode);
ufs_iput(ip);
ufs_iput(pdir);
return (error);
#endif
ip->i_flag |= IACC|IUPD|ICHG;
ip->i_mode = mode;
- ITOV(ip)->v_type = IFTOVT(mode); /* Rest init'd in iget() */
+ tvp->v_type = IFTOVT(mode); /* Rest init'd in iget() */
ip->i_nlink = 1;
if ((ip->i_mode & ISGID) && !groupmember(ip->i_gid, ndp->ni_cred) &&
suser(ndp->ni_cred, NULL))
/*
* Make sure inode goes to disk before directory entry.
*/
- if (error = (ump->um_iupdat)(ip, &time, &time, 1))
+ if (error = VOP_UPDATE(tvp, &time, &time, 1))
goto bad;
if (error = ufs_direnter(ip, ndp))
goto bad;
if ((ndp->ni_nameiop & SAVESTART) == 0)
FREE(ndp->ni_pnbuf, M_NAMEI);
ufs_iput(pdir);
- *ipp = ip;
+ *vpp = tvp;
return (0);
bad: