*
* %sccs.include.redist.c%
*
- * @(#)ufs_vnops.c 7.74 (Berkeley) %G%
+ * @(#)ufs_vnops.c 7.88 (Berkeley) %G%
*/
#include <sys/param.h>
#include <sys/fifo.h>
#include <sys/malloc.h>
+#include <vm/vm.h>
+
#include <ufs/ufs/lockf.h>
#include <ufs/ufs/quota.h>
#include <ufs/ufs/inode.h>
#include <ufs/ufs/ufsmount.h>
#include <ufs/ufs/ufs_extern.h>
-int ufs_chmod __P((struct vnode *, int, struct proc *));
-int ufs_chown __P((struct vnode *, u_int, u_int, struct proc *));
-
-enum vtype iftovt_tab[16] = {
- VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON,
- VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VBAD,
-};
-int vttoif_tab[9] = {
- 0, IFREG, IFDIR, IFBLK, IFCHR, IFLNK, IFSOCK, IFIFO, IFMT,
-};
+int ufs_chmod __P((struct vnode *, int, struct ucred *, struct proc *));
+int ufs_chown
+ __P((struct vnode *, uid_t, gid_t, struct ucred *, struct proc *));
#ifdef _NOQUAD
#define SETHIGH(q, h) (q).val[_QUAD_HIGHWORD] = (h)
#else
vap->va_qsize = ip->i_din.di_qsize;
#endif
- vap->va_atime.tv_sec = ip->i_atime;
- vap->va_atime.tv_usec = 0;
- vap->va_mtime.tv_sec = ip->i_mtime;
- vap->va_mtime.tv_usec = 0;
- vap->va_ctime.tv_sec = ip->i_ctime;
- vap->va_ctime.tv_usec = 0;
+ vap->va_atime = ip->i_atime;
+ vap->va_mtime = ip->i_mtime;
+ vap->va_ctime = ip->i_ctime;
vap->va_flags = ip->i_flags;
vap->va_gen = ip->i_gen;
/* this doesn't belong here */
/*
* Go through the fields and update iff not VNOVAL.
*/
- 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))
+ if (vap->va_uid != (uid_t)VNOVAL || vap->va_gid != (gid_t)VNOVAL)
+ if (error = ufs_chown(vp, vap->va_uid, vap->va_gid, cred, p))
return (error);
if (vap->va_size != VNOVAL) {
if (vp->v_type == VDIR)
return (EISDIR);
- if (error = VOP_TRUNCATE(vp, vap->va_size, 0)) /* IO_SYNC? */
+ if (error = VOP_TRUNCATE(vp, vap->va_size, 0, cred))
return (error);
}
ip = VTOI(vp);
return (error);
}
error = 0;
- if (vap->va_mode != (u_short)VNOVAL)
- error = ufs_chmod(vp, (int)vap->va_mode, p);
+ if (vap->va_mode != (mode_t)VNOVAL)
+ error = ufs_chmod(vp, (int)vap->va_mode, cred, p);
if (vap->va_flags != VNOVAL) {
if (cred->cr_uid != ip->i_uid &&
(error = suser(cred, &p->p_acflag)))
* Inode must be locked before calling.
*/
static int
-ufs_chmod(vp, mode, p)
+ufs_chmod(vp, mode, cred, p)
register struct vnode *vp;
register int mode;
+ register struct ucred *cred;
struct proc *p;
{
- register struct ucred *cred = p->p_ucred;
register struct inode *ip = VTOI(vp);
int error;
* inode must be locked prior to call.
*/
static int
-ufs_chown(vp, uid, gid, p)
+ufs_chown(vp, uid, gid, cred, p)
register struct vnode *vp;
- u_int uid;
- u_int gid;
+ uid_t uid;
+ gid_t gid;
+ struct ucred *cred;
struct proc *p;
{
register struct inode *ip = VTOI(vp);
- register struct ucred *cred = p->p_ucred;
uid_t ouid;
gid_t ogid;
int error = 0;
long change;
#endif
- if (uid == (u_short)VNOVAL)
+ if (uid == (uid_t)VNOVAL)
uid = ip->i_uid;
- if (gid == (u_short)VNOVAL)
+ if (gid == (gid_t)VNOVAL)
gid = ip->i_gid;
/*
* If we don't own the file, are trying to change the owner
* link vnode call
*/
int
-ufs_link(vp, tdvp, cnp)
- register struct vnode *vp; /* source vnode */
+ufs_link(tdvp, vp, cnp)
struct vnode *tdvp;
+ register struct vnode *vp; /* source vnode */
struct componentname *cnp;
{
register struct inode *ip;
int error;
-#ifdef DIANOSTIC
+#ifdef DIAGNOSTIC
if ((cnp->cn_flags & HASBUF) == 0)
panic("ufs_link: no name");
#endif
ip = VTOI(vp);
- if ((unsigned short)ip->i_nlink >= LINK_MAX) {
+ if ((nlink_t)ip->i_nlink >= LINK_MAX) {
free(cnp->cn_pnbuf, M_NAMEI);
return (EMLINK);
}
struct vnode *dvp, **vpp;
struct componentname *cnp;
{
- register char *cp; /* pointer into pathname argument */
register struct vnode *dp = 0; /* the directory we are searching */
struct vnode *tdp; /* saved dp */
struct mount *mp; /* mount table entry */
int docache; /* == 0 do not cache last component */
int wantparent; /* 1 => wantparent or lockparent flag */
int rdonly; /* lookup read-only flag bit */
+ char *cp; /* DEBUG: check name ptr/len */
+ int newhash; /* DEBUG: check name hash */
int error = 0;
- int newhash;
/*
* Setup: break out flag bits into variables.
* responsibility for freeing the pathname buffer.
*/
#ifdef NAMEI_DIAGNOSTIC
- newhash = 0;
- for (cp = cnp->cn_nameptr; *cp != 0 && *cp != '/'; cp++)
+ for (newhash = 0, cp = cnp->cn_nameptr; *cp != 0 && *cp != '/'; cp++)
newhash += (unsigned char)*cp;
if (newhash != cnp->cn_hash)
panic("relookup: bad hash");
if (cnp->cn_namelen != cp - cnp->cn_nameptr)
panic ("relookup: bad len");
- { char c = *cp;
- *cp = '\0';
+ if (*cp != 0)
+ panic("relookup: not last component");
printf("{%s}: ", cnp->cn_nameptr);
- *cp = c; }
#endif
/*
if (*vpp != NULL)
panic("leaf should be empty");
#endif
-#ifdef NAMEI_DIAGNOSTIC
- printf("not found\n");
-#endif
- if (cnp->cn_nameiop == LOOKUP || cnp->cn_nameiop == DELETE ||
- error != ENOENT || *cp != 0)
+ if (error != EJUSTRETURN)
goto bad;
/*
* If creating and at end of pathname, then can consider
error = EROFS;
goto bad;
}
+ /* ASSERT(dvp == ndp->ni_startdir) */
+ if (cnp->cn_flags & SAVESTART)
+ VREF(dvp);
/*
* We return with ni_vp NULL to indicate that the entry
* doesn't currently exist, leaving a pointer to the
* (possibly locked) directory inode in ndp->ni_dvp.
*/
- if (cnp->cn_flags & SAVESTART) {
- /*
- * startdir == dvp, always
- */
- VREF(dvp);
- }
return (0);
}
-#ifdef NAMEI_DIAGNOSTIC
- printf("found\n");
-#endif
-
dp = *vpp;
+
#ifdef DIAGNOSTIC
/*
* Check for symbolic link
*/
- if (dp->v_type == VLNK) {
+ if (dp->v_type == VLNK && (cnp->cn_flags & FOLLOW))
panic ("relookup: symlink found.\n");
- };
-
- /*
- * Check to see if the vnode has been mounted on;
- * if so find the root of the mounted file system.
- */
#endif
-
nextname:
/*
* Check for read-only file systems.
goto bad2;
}
}
- if (cnp->cn_flags & SAVESTART) {
- /* ASSERT(dvp==ndp->ni_startdir) */
+ /* ASSERT(dvp == ndp->ni_startdir) */
+ if (cnp->cn_flags & SAVESTART)
VREF(dvp);
- }
if (!wantparent)
vrele(dvp);
int error = 0;
int fdvpneedsrele = 1, tdvpneedsrele = 1;
-#ifdef DIANOSTIC
+#ifdef DIAGNOSTIC
if ((tcnp->cn_flags & HASBUF) == 0 ||
(fcnp->cn_flags & HASBUF) == 0)
panic("ufs_rename: no name");
* parent we don't fool with the link count.
*/
if (doingdirectory && newparent) {
- if ((unsigned short)dp->i_nlink >= LINK_MAX) {
+ if ((nlink_t)dp->i_nlink >= LINK_MAX) {
error = EMLINK;
goto bad;
}
if (doingdirectory) {
if (--xp->i_nlink != 0)
panic("rename: linked directory");
- error = VOP_TRUNCATE(ITOV(xp), (u_long)0, IO_SYNC);
+ error = VOP_TRUNCATE(ITOV(xp), (off_t)0, IO_SYNC,
+ tcnp->cn_cred);
}
xp->i_flag |= ICHG;
ufs_iput(xp);
if ((fcnp->cn_flags & SAVESTART) == 0)
panic("ufs_rename: lost from startdir");
p->p_spare[1]--;
- (void) relookup(fdvp, &fvp, fcnp); /* NEEDSWORK: startdir stuff */
+ (void) relookup(fdvp, &fvp, fcnp);
if (fvp != NULL) {
xp = VTOI(fvp);
dp = VTOI(fdvp);
if (dirbuf.dotdot_namlen != 2 ||
dirbuf.dotdot_name[0] != '.' ||
dirbuf.dotdot_name[1] != '.') {
- ufs_dirbad(xp, 12,
+ ufs_dirbad(xp, (doff_t)12,
"rename: mangled dir");
} else {
dirbuf.dotdot_ino = newparent;
int error;
int dmode;
-#ifdef DIANOSTIC
+#ifdef DIAGNOSTIC
if ((cnp->cn_flags & HASBUF) == 0)
panic("ufs_mkdir: no name");
#endif
dp = VTOI(dvp);
- if ((unsigned short)dp->i_nlink >= LINK_MAX) {
+ if ((nlink_t)dp->i_nlink >= LINK_MAX) {
free(cnp->cn_pnbuf, M_NAMEI);
ufs_iput(dp);
return (EMLINK);
* worry about them later.
*/
ip->i_nlink -= 2;
- error = VOP_TRUNCATE(vp, (u_long)0, IO_SYNC);
+ error = VOP_TRUNCATE(vp, (off_t)0, IO_SYNC, cnp->cn_cred);
cache_purge(ITOV(ip));
out:
if (dvp)
}
/*
- * Vnode op for read and write
+ * Vnode op for reading directories.
+ *
+ * The routine below assumes that the on-disk format of a directory
+ * is the same as that defined by <sys/dirent.h>. If the on-disk
+ * format changes, then it will be necessary to do a conversion
+ * from the on-disk format that read returns to the format defined
+ * by <sys/dirent.h>.
*/
int
ufs_readdir(vp, uio, cred, eofflagp)
* Calculate the logical to physical mapping if not done already,
* then call the device strategy routine.
*/
-int checkoverlap = 0;
-
int
ufs_strategy(bp)
register struct buf *bp;
panic("ufs_strategy: spec");
if (bp->b_blkno == bp->b_lblkno) {
if (error =
- VOP_BMAP(bp->b_vp, bp->b_lblkno, NULL, &bp->b_blkno))
+ VOP_BMAP(bp->b_vp, bp->b_lblkno, NULL, &bp->b_blkno)) {
+ bp->b_error = error;
+ bp->b_flags |= B_ERROR;
+ biodone(bp);
return (error);
+ }
if ((long)bp->b_blkno == -1)
clrbuf(bp);
}
biodone(bp);
return (0);
}
-#ifdef DIAGNOSTIC
- if (checkoverlap && bp->b_vp->v_mount->mnt_stat.f_type == MOUNT_UFS)
- ffs_checkoverlap(bp, ip);
-#endif
-
vp = ip->i_devvp;
bp->b_dev = vp->v_rdev;
(vp->v_op->vop_strategy)(bp);
int
ufs_vinit(mntp, specops, fifoops, vpp)
struct mount *mntp;
- struct vnodeops *specops, *fifoops;
+ int (**specops)();
+ int (**fifoops)();
struct vnode **vpp;
{
struct inode *ip, *nip;
int error;
pdir = VTOI(dvp);
-#ifdef DIANOSTIC
+#ifdef DIAGNOSTIC
if ((cnp->cn_flags & HASBUF) == 0)
panic("ufs_makeinode: no name");
#endif
ufs_iput(ip);
return (error);
}
-
-
-#if defined(JOHNH) && 0
-/*
- * A hack to get the kernel to compile.
- */
-int
-hang_addrlist()
-{
- return 0;
-}
-int
-free_addrlist()
-{
- return 0;
-}
-#endif
-