- error = iupdat(ip, &time, &time, 1);
-
- /*
- * Bump link count in parent directory
- * to reflect work done below. Should
- * be done before reference is created
- * so reparation is possible if we crash.
- */
- dp->i_nlink++;
- dp->i_flag |= ICHG;
- error = iupdat(dp, &time, &time, 1);
-
- /*
- * Initialize directory with "."
- * and ".." from static template.
- */
- dirtemplate = mastertemplate;
- dirtemplate.dot_ino = ip->i_number;
- dirtemplate.dotdot_ino = dp->i_number;
- error = vn_rdwr(UIO_WRITE, ITOV(ip), (caddr_t)&dirtemplate,
- sizeof (dirtemplate), (off_t)0, UIO_SYSSPACE,
- IO_NODELOCKED|IO_SYNC, ndp->ni_cred, (int *)0);
- if (error) {
- dp->i_nlink--;
- dp->i_flag |= ICHG;
- goto bad;
- }
- if (DIRBLKSIZ > dp->i_fs->fs_fsize)
- panic("mkdir: blksize"); /* XXX - should grow w/balloc() */
- else
- ip->i_size = DIRBLKSIZ;
- /*
- * Directory all set up, now
- * install the entry for it in
- * the parent directory.
- */
- error = direnter(ip, ndp);
- dp = NULL;
- if (error) {
- ndp->ni_nameiop = LOOKUP | NOCACHE;
- error = namei(ndp);
- if (!error) {
- dp = VTOI(ndp->ni_vp);
- dp->i_nlink--;
- dp->i_flag |= ICHG;
- }
- }
-bad:
- /*
- * No need to do an explicit itrunc here,
- * vrele will do this for us because we set
- * the link count to 0.
- */
- if (error) {
- ip->i_nlink = 0;
- ip->i_flag |= ICHG;
- iput(ip);
- } else
- ndp->ni_vp = ITOV(ip);
- if (dp)
- iput(dp);
- return (error);
-}
-
-/*
- * Rmdir system call.
- */
-ufs_rmdir(ndp)
- register struct nameidata *ndp;
-{
- register struct inode *ip, *dp;
- int error = 0;
-
- ip = VTOI(ndp->ni_vp);
- dp = VTOI(ndp->ni_dvp);
- /*
- * No rmdir "." please.
- */
- if (dp == ip) {
- vrele(ITOV(dp));
- iput(ip);
- return (EINVAL);
- }
- /*
- * Verify the directory is empty (and valid).
- * (Rmdir ".." won't be valid since
- * ".." will contain a reference to
- * the current directory and thus be
- * non-empty.)
- */
- if (ip->i_nlink != 2 || !dirempty(ip, dp->i_number, ndp->ni_cred)) {
- error = ENOTEMPTY;
- goto out;
- }
- /*
- * Delete reference to directory before purging
- * inode. If we crash in between, the directory
- * will be reattached to lost+found,
- */
- if (error = dirremove(ndp))
- goto out;
- dp->i_nlink--;
- dp->i_flag |= ICHG;
- cache_purge(ITOV(dp));
- iput(dp);
- ndp->ni_dvp = NULL;
- /*
- * Truncate inode. The only stuff left
- * in the directory is "." and "..". The
- * "." reference is inconsequential since
- * we're quashing it. The ".." reference
- * has already been adjusted above. We've
- * removed the "." reference and the reference
- * in the parent directory, but there may be
- * other hard links so decrement by 2 and
- * worry about them later.
- */
- ip->i_nlink -= 2;
- error = itrunc(ip, (u_long)0, IO_SYNC);
- cache_purge(ITOV(ip));
-out:
- if (ndp->ni_dvp)
- iput(dp);
- iput(ip);
- return (error);
-}
-
-/*
- * symlink -- make a symbolic link
- */
-ufs_symlink(ndp, vap, target)
- struct nameidata *ndp;
- struct vattr *vap;
- char *target;
-{
- struct inode *ip;
- int error;
-
- error = maknode(IFLNK | vap->va_mode, ndp, &ip);
- if (error)
- return (error);
- error = vn_rdwr(UIO_WRITE, ITOV(ip), target, strlen(target), (off_t)0,
- UIO_SYSSPACE, IO_NODELOCKED, ndp->ni_cred, (int *)0);
- iput(ip);
- return (error);
-}
-
-/*
- * Vnode op for read and write
- */
-ufs_readdir(vp, uio, cred, eofflagp)
- struct vnode *vp;
- register struct uio *uio;
- struct ucred *cred;
- int *eofflagp;
-{
- int count, lost, error;
-
- count = uio->uio_resid;
- count &= ~(DIRBLKSIZ - 1);
- lost = uio->uio_resid - count;
- if (count < DIRBLKSIZ || (uio->uio_offset & (DIRBLKSIZ -1)))
- return (EINVAL);
- uio->uio_resid = count;
- uio->uio_iov->iov_len = count;
- error = ufs_read(vp, uio, 0, cred);
- uio->uio_resid += lost;
- if ((VTOI(vp)->i_size - uio->uio_offset) <= 0)
- *eofflagp = 1;
- else
- *eofflagp = 0;
- return (error);
-}
-
-/*
- * Return target name of a symbolic link
- */
-ufs_readlink(vp, uiop, cred)
- struct vnode *vp;
- struct uio *uiop;
- struct ucred *cred;
-{
-
- return (ufs_read(vp, uiop, 0, cred));
-}
-
-/*
- * Ufs abort op, called after namei() when a CREATE/DELETE isn't actually
- * done. Iff ni_vp/ni_dvp not null and locked, unlock.
- */
-ufs_abortop(ndp)
- register struct nameidata *ndp;
-{
-
- if (ndp->ni_dvp) {
- if (VOP_ISLOCKED(ndp->ni_dvp))
- VOP_UNLOCK(ndp->ni_dvp);
- vrele(ndp->ni_dvp);
- }
- if (ndp->ni_vp) {
- if (VOP_ISLOCKED(ndp->ni_vp))
- VOP_UNLOCK(ndp->ni_vp);
- vrele(ndp->ni_vp);
- }
- return;
-}
-
-/*
- * Lock an inode.
- */
-ufs_lock(vp)
- struct vnode *vp;
-{
- register struct inode *ip = VTOI(vp);
-
- ILOCK(ip);
- return (0);
-}
-
-/*
- * Unlock an inode.
- */
-ufs_unlock(vp)
- struct vnode *vp;
-{
- register struct inode *ip = VTOI(vp);
-
- if (!(ip->i_flag & ILOCKED))
- panic("ufs_unlock NOT LOCKED");
- IUNLOCK(ip);
- return (0);
-}
-
-/*
- * Check for a locked inode.
- */
-ufs_islocked(vp)
- struct vnode *vp;
-{
-
- if (VTOI(vp)->i_flag & ILOCKED)
- return (1);
- return (0);
-}
-
-/*
- * Get access to bmap
- */
-ufs_bmap(vp, bn, vpp, bnp)
- struct vnode *vp;
- daddr_t bn;
- struct vnode **vpp;
- daddr_t *bnp;
-{
- struct inode *ip = VTOI(vp);
-
- if (vpp != NULL)
- *vpp = ip->i_devvp;
- if (bnp == NULL)
- return (0);
- return (bmap(ip, bn, bnp, (daddr_t *)0, (int *)0));
-}
-
-/*
- * Just call the device strategy routine
- */
-int checkoverlap = 1;
-
-ufs_strategy(bp)
- register struct buf *bp;
-{
- register struct inode *ip = VTOI(bp->b_vp);
- register struct buf *ep;
- struct vnode *vp;
- struct buf *ebp;
- daddr_t start, last;
- 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) {
- if (error = bmap(ip, bp->b_lblkno, &bp->b_blkno))
- return (error);
- if ((long)bp->b_blkno == -1)
- clrbuf(bp);
- }
- if ((long)bp->b_blkno == -1) {
- biodone(bp);
- return (0);