BSD 4_4_Lite1 release
[unix-history] / usr / src / sys / miscfs / specfs / spec_vnops.c
index e8e082f..111c517 100644 (file)
@@ -2,9 +2,35 @@
  * Copyright (c) 1989, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
  * Copyright (c) 1989, 1993
  *     The Regents of the University of California.  All rights reserved.
  *
- * %sccs.include.redist.c%
+ * 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. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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.
  *
  *
- *     @(#)spec_vnops.c        8.2 (Berkeley) %G%
+ * 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.
+ *
+ *     @(#)spec_vnops.c        8.6 (Berkeley) 4/9/94
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -141,7 +167,7 @@ spec_open(ap)
                                if ((bdev = chrtoblk(dev)) != NODEV &&
                                    vfinddev(bdev, VBLK, &bvp) &&
                                    bvp->v_usecount > 0 &&
                                if ((bdev = chrtoblk(dev)) != NODEV &&
                                    vfinddev(bdev, VBLK, &bvp) &&
                                    bvp->v_usecount > 0 &&
-                                   (error = ufs_mountedon(bvp)))
+                                   (error = vfs_mountedon(bvp)))
                                        return (error);
                                if (iskmemdev(dev))
                                        return (EPERM);
                                        return (error);
                                if (iskmemdev(dev))
                                        return (EPERM);
@@ -166,7 +192,7 @@ spec_open(ap)
                 * Do not allow opens of block devices that are
                 * currently mounted.
                 */
                 * Do not allow opens of block devices that are
                 * currently mounted.
                 */
-               if (error = ufs_mountedon(vp))
+               if (error = vfs_mountedon(vp))
                        return (error);
                return ((*bdevsw[maj].d_open)(dev, ap->a_mode, S_IFBLK, ap->a_p));
        }
                        return (error);
                return ((*bdevsw[maj].d_open)(dev, ap->a_mode, S_IFBLK, ap->a_p));
        }
@@ -192,8 +218,9 @@ spec_read(ap)
        daddr_t bn, nextbn;
        long bsize, bscale;
        struct partinfo dpart;
        daddr_t bn, nextbn;
        long bsize, bscale;
        struct partinfo dpart;
-       register int n, on;
+       int n, on, majordev, (*ioctl)();
        int error = 0;
        int error = 0;
+       dev_t dev;
 
 #ifdef DIAGNOSTIC
        if (uio->uio_rw != UIO_READ)
 
 #ifdef DIAGNOSTIC
        if (uio->uio_rw != UIO_READ)
@@ -217,13 +244,13 @@ spec_read(ap)
                if (uio->uio_offset < 0)
                        return (EINVAL);
                bsize = BLKDEV_IOSIZE;
                if (uio->uio_offset < 0)
                        return (EINVAL);
                bsize = BLKDEV_IOSIZE;
-               if ((*bdevsw[major(vp->v_rdev)].d_ioctl)(vp->v_rdev, DIOCGPART,
-                   (caddr_t)&dpart, FREAD, p) == 0) {
-                       if (dpart.part->p_fstype == FS_BSDFFS &&
-                           dpart.part->p_frag != 0 && dpart.part->p_fsize != 0)
-                               bsize = dpart.part->p_frag *
-                                   dpart.part->p_fsize;
-               }
+               dev = vp->v_rdev;
+               if ((majordev = major(dev)) < nblkdev &&
+                   (ioctl = bdevsw[majordev].d_ioctl) != NULL &&
+                   (*ioctl)(dev, DIOCGPART, (caddr_t)&dpart, FREAD, p) == 0 &&
+                   dpart.part->p_fstype == FS_BSDFFS &&
+                   dpart.part->p_frag != 0 && dpart.part->p_fsize != 0)
+                       bsize = dpart.part->p_frag * dpart.part->p_fsize;
                bscale = bsize / DEV_BSIZE;
                do {
                        bn = (uio->uio_offset / DEV_BSIZE) &~ (bscale - 1);
                bscale = bsize / DEV_BSIZE;
                do {
                        bn = (uio->uio_offset / DEV_BSIZE) &~ (bscale - 1);
@@ -418,8 +445,8 @@ spec_fsync(ap)
         */
 loop:
        s = splbio();
         */
 loop:
        s = splbio();
-       for (bp = vp->v_dirtyblkhd.le_next; bp; bp = nbp) {
-               nbp = bp->b_vnbufs.qe_next;
+       for (bp = vp->v_dirtyblkhd.lh_first; bp; bp = nbp) {
+               nbp = bp->b_vnbufs.le_next;
                if ((bp->b_flags & B_BUSY))
                        continue;
                if ((bp->b_flags & B_DELWRI) == 0)
                if ((bp->b_flags & B_BUSY))
                        continue;
                if ((bp->b_flags & B_DELWRI) == 0)
@@ -436,7 +463,7 @@ loop:
                        sleep((caddr_t)&vp->v_numoutput, PRIBIO + 1);
                }
 #ifdef DIAGNOSTIC
                        sleep((caddr_t)&vp->v_numoutput, PRIBIO + 1);
                }
 #ifdef DIAGNOSTIC
-               if (vp->v_dirtyblkhd.le_next) {
+               if (vp->v_dirtyblkhd.lh_first) {
                        vprint("spec_fsync: dirty", vp);
                        goto loop;
                }
                        vprint("spec_fsync: dirty", vp);
                        goto loop;
                }
@@ -552,7 +579,7 @@ spec_close(ap)
                 * we must invalidate any in core blocks, so that
                 * we can, for instance, change floppy disks.
                 */
                 * we must invalidate any in core blocks, so that
                 * we can, for instance, change floppy disks.
                 */
-               if (error = vinvalbuf(vp, 1, ap->a_cred, ap->a_p, 0, 0))
+               if (error = vinvalbuf(vp, V_SAVE, ap->a_cred, ap->a_p, 0, 0))
                        return (error);
                /*
                 * We do not want to really close the device if it
                        return (error);
                /*
                 * We do not want to really close the device if it