-/*
- * 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)
- struct vnode *vp;
- register struct uio *uio;
- struct ucred *cred;
-{
- 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;
- 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;
-{
- register struct inode *ip;
-
- if (ndp->ni_vp) {
- ip = VTOI(ndp->ni_vp);
- if (ip->i_flag & ILOCKED)
- IUNLOCK(ip);
- vrele(ndp->ni_vp);
- }
- if (ndp->ni_dvp) {
- ip = VTOI(ndp->ni_dvp);
- if (ip->i_flag & ILOCKED)
- IUNLOCK(ip);
- vrele(ndp->ni_dvp);
- }
- 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);
- }
- if (checkoverlap) {
- ebp = &buf[nbuf];
- start = bp->b_blkno;
- last = start + btodb(bp->b_bcount) - 1;
- for (ep = buf; ep < ebp; ep++) {
- if (ep == bp || (ep->b_flags & B_INVAL) ||
- ep->b_vp == (struct vnode *)0)
- continue;
- if (VOP_BMAP(ep->b_vp, (daddr_t)0, &vp, (daddr_t)0))
- continue;
- if (vp != ip->i_devvp)
- continue;
- /* look for overlap */
- if (ep->b_bcount == 0 || ep->b_blkno > last ||
- ep->b_blkno + btodb(ep->b_bcount) <= start)
- continue;
- vprint("Disk overlap", vp);
- printf("\tstart %d, end %d overlap start %d, end %d\n",
- start, last, ep->b_blkno,
- ep->b_blkno + btodb(ep->b_bcount) - 1);
- }
- }
- vp = ip->i_devvp;
- bp->b_dev = vp->v_rdev;
- (*(vp->v_op->vn_strategy))(bp);
- return (0);
-}
-
-/*
- * Print out the contents of an inode.
- */
-ufs_print(vp)
- struct vnode *vp;
-{
- register struct inode *ip = VTOI(vp);
-
- printf("tag VT_UFS, ino %d, on dev %d, %d%s\n", ip->i_number,
- major(ip->i_dev), minor(ip->i_dev),
- (ip->i_flag & ILOCKED) ? " (LOCKED)" : "");
- if (ip->i_spare0 == 0)
- return;
- printf("\towner pid %d", ip->i_spare0);
- if (ip->i_spare1)
- printf(" waiting pid %d", ip->i_spare1);
- printf("\n");
-}
-
-/*
- * Read wrapper for special devices.
- */
-ufsspec_read(vp, uio, ioflag, cred)
- struct vnode *vp;
- struct uio *uio;
- int ioflag;
- struct ucred *cred;
-{
-
- /*
- * Set access flag.
- */
- VTOI(vp)->i_flag |= IACC;
- return (spec_read(vp, uio, ioflag, cred));
-}
-
-/*
- * Write wrapper for special devices.
- */
-ufsspec_write(vp, uio, ioflag, cred)
- struct vnode *vp;
- struct uio *uio;
- int ioflag;
- struct ucred *cred;
-{
-
- /*
- * Set update and change flags.
- */
- VTOI(vp)->i_flag |= IUPD|ICHG;
- return (spec_write(vp, uio, ioflag, cred));
-}
-
-/*
- * Close wrapper for special devices.
- *
- * Update the times on the inode then do device close.
- */
-ufsspec_close(vp, fflag, cred)
- struct vnode *vp;
- int fflag;
- struct ucred *cred;
-{
- register struct inode *ip = VTOI(vp);
-
- if (vp->v_usecount > 1 && !(ip->i_flag & ILOCKED))
- ITIMES(ip, &time, &time);
- return (spec_close(vp, fflag, cred));
-}
-
-/*
- * Make a new file.
- */
-maknode(mode, ndp, ipp)
- int mode;
- register struct nameidata *ndp;
- struct inode **ipp;
-{
- register struct inode *ip;
- struct inode *tip;
- register struct inode *pdir = VTOI(ndp->ni_dvp);
- ino_t ipref;
- int error;
-
- *ipp = 0;
- if ((mode & IFMT) == IFDIR)
- ipref = dirpref(pdir->i_fs);
- else
- ipref = pdir->i_number;
- error = ialloc(pdir, ipref, mode, &tip);
- if (error) {
- iput(pdir);
- return (error);
- }
- ip = tip;
-#ifdef QUOTA
- if (ip->i_dquot != NODQUOT)
- panic("maknode: dquot");
-#endif
- ip->i_flag |= IACC|IUPD|ICHG;
- if ((mode & IFMT) == 0)
- mode |= IFREG;
- ip->i_mode = mode;
- ITOV(ip)->v_type = IFTOVT(mode); /* Rest init'd in iget() */
- ip->i_nlink = 1;
- ip->i_uid = ndp->ni_cred->cr_uid;
- ip->i_gid = pdir->i_gid;
- if ((ip->i_mode & ISGID) && !groupmember(ip->i_gid, ndp->ni_cred) &&
- suser(ndp->ni_cred, NULL))
- ip->i_mode &= ~ISGID;
-#ifdef QUOTA
- ip->i_dquot = inoquota(ip);
-#endif
-
- /*
- * Make sure inode goes to disk before directory entry.
- */
- if ((error = iupdat(ip, &time, &time, 1)) ||
- (error = direnter(ip, ndp))) {
- /*
- * Write error occurred trying to update the inode
- * or the directory so must deallocate the inode.
- */
- ip->i_nlink = 0;
- ip->i_flag |= ICHG;
- iput(ip);
- return (error);
- }
- *ipp = ip;
- return (0);
-}