From 216936ca6d54e77a70cdfe5305d1ba3ac2412fad Mon Sep 17 00:00:00 2001 From: phk Date: Mon, 30 Aug 1999 07:56:23 +0000 Subject: Make bdev userland access work like cdev userland access unless the highly non-recommended option ALLOW_BDEV_ACCESS is used. (bdev access is evil because you don't get write errors reported.) Kill si_bsize_best before it kills Matt :-) Use the specfs routines rather having cloned copies in devfs. --- sys/fs/specfs/spec_vnops.c | 59 +++++++++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'sys/fs') diff --git a/sys/fs/specfs/spec_vnops.c b/sys/fs/specfs/spec_vnops.c index 1afc400..e097ef8 100644 --- a/sys/fs/specfs/spec_vnops.c +++ b/sys/fs/specfs/spec_vnops.c @@ -34,6 +34,7 @@ * $FreeBSD$ */ +#include "opt_fs.h" #include #include #include @@ -258,6 +259,8 @@ spec_read(ap) int error = 0; dev_t dev; + dev = vp->v_rdev; + #ifdef DIAGNOSTIC if (uio->uio_rw != UIO_READ) panic("spec_read mode"); @@ -269,24 +272,14 @@ spec_read(ap) switch (vp->v_type) { - case VCHR: - VOP_UNLOCK(vp, 0, p); - error = (*devsw(vp->v_rdev)->d_read) - (vp->v_rdev, uio, ap->a_ioflag); - vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); - return (error); - case VBLK: +#ifdef ALLOW_BDEV_ACCESS if (uio->uio_offset < 0) return (EINVAL); - dev = vp->v_rdev; - - /* - * Calculate block size for block device. The block size must - * be larger then the physical minimum. - */ - bsize = vp->v_rdev->si_bsize_best; + bsize = dev->si_bsize_phys; + while (bsize < dev->si_bsize_max && bsize < uio->uio_resid) + bsize <<= 1; if ((ioctl = devsw(dev)->d_ioctl) != NULL && (*ioctl)(dev, DIOCGPART, (caddr_t)&dpart, FREAD, p) == 0 && @@ -314,6 +307,12 @@ spec_read(ap) brelse(bp); } while (error == 0 && uio->uio_resid > 0 && n != 0); return (error); +#endif /* ALLOW_BDEV_ACCESS */ + case VCHR: + VOP_UNLOCK(vp, 0, p); + error = (*devsw(dev)->d_read) (dev, uio, ap->a_ioflag); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + return (error); default: panic("spec_read type"); @@ -343,36 +342,30 @@ spec_write(ap) struct partinfo dpart; register int n, on; int error = 0; + dev_t dev; + dev = vp->v_rdev; #ifdef DIAGNOSTIC if (uio->uio_rw != UIO_WRITE) panic("spec_write mode"); if (uio->uio_segflg == UIO_USERSPACE && uio->uio_procp != curproc) panic("spec_write proc"); #endif + if (uio->uio_resid == 0) + return (0); switch (vp->v_type) { - case VCHR: - VOP_UNLOCK(vp, 0, p); - error = (*devsw(vp->v_rdev)->d_write) - (vp->v_rdev, uio, ap->a_ioflag); - vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); - return (error); - case VBLK: - if (uio->uio_resid == 0) - return (0); +#ifdef ALLOW_BDEV_ACCESS if (uio->uio_offset < 0) return (EINVAL); - /* - * Calculate block size for block device. The block size must - * be larger then the physical minimum. - */ - bsize = vp->v_rdev->si_bsize_best; + bsize = dev->si_bsize_phys; + while (bsize < dev->si_bsize_max && bsize < uio->uio_resid) + bsize <<= 1; - if ((*devsw(vp->v_rdev)->d_ioctl)(vp->v_rdev, DIOCGPART, + if ((*devsw(dev)->d_ioctl)(dev, DIOCGPART, (caddr_t)&dpart, FREAD, p) == 0) { if (dpart.part->p_fstype == FS_BSDFFS && dpart.part->p_frag != 0 && dpart.part->p_fsize != 0) @@ -400,6 +393,14 @@ spec_write(ap) bdwrite(bp); } while (error == 0 && uio->uio_resid > 0 && n != 0); return (error); +#endif /* ALLOW_BDEV_ACCESS */ + + case VCHR: + VOP_UNLOCK(vp, 0, p); + error = (*devsw(dev)->d_write) + (dev, uio, ap->a_ioflag); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p); + return (error); default: panic("spec_write type"); -- cgit v1.1