From b17bde009a29901e8647e3d0c680a716f3526a2d Mon Sep 17 00:00:00 2001 From: bde Date: Sun, 25 Oct 1998 16:11:49 +0000 Subject: [PATCH] Fixed device number checking in bdevvp(): - dev != NODEV was checked for, but 0 was returned on failure. This was fixed in Lite2 (except the return code was still slightly wrong (ENODEV instead of ENXIO)) but the changes were not merged. This case probably doesn't actually occur under FreeBSD. - major(dev) was not checked to have a valid non-NULL bdevsw entry. This caused panics when the driver for the root device didn't exist. Fixed minor misformattings in bdevvp(). Rev.1.14 consisted mainly of gratuitous reformattings that seem to have caused many Lite2 merge errors. PR: 8417 --- sys/kern/vfs_export.c | 16 ++++++++++------ sys/kern/vfs_subr.c | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/sys/kern/vfs_export.c b/sys/kern/vfs_export.c index 867cf8866f37..c0117a634fee 100644 --- a/sys/kern/vfs_export.c +++ b/sys/kern/vfs_export.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 - * $Id: vfs_subr.c,v 1.165 1998/10/13 08:24:41 dg Exp $ + * $Id: vfs_subr.c,v 1.166 1998/10/14 15:05:52 dt Exp $ */ /* @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -1126,16 +1127,19 @@ bdevvp(dev, vpp) struct vnode *nvp; int error; - if (dev == NODEV) - return (0); - error = getnewvnode(VT_NON, (struct mount *) 0, spec_vnodeop_p, &nvp); + if (dev == NODEV || major(dev) >= nblkdev || + bdevsw[major(dev)] == NULL) { + *vpp = NULLVP; + return (ENXIO); + } + error = getnewvnode(VT_NON, (struct mount *)0, spec_vnodeop_p, &nvp); if (error) { - *vpp = 0; + *vpp = NULLVP; return (error); } vp = nvp; vp->v_type = VBLK; - if ((nvp = checkalias(vp, dev, (struct mount *) 0))) { + if ((nvp = checkalias(vp, dev, (struct mount *)0)) != NULL) { vput(vp); vp = nvp; } diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index 867cf8866f37..c0117a634fee 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95 - * $Id: vfs_subr.c,v 1.165 1998/10/13 08:24:41 dg Exp $ + * $Id: vfs_subr.c,v 1.166 1998/10/14 15:05:52 dt Exp $ */ /* @@ -46,6 +46,7 @@ #include #include +#include #include #include #include @@ -1126,16 +1127,19 @@ bdevvp(dev, vpp) struct vnode *nvp; int error; - if (dev == NODEV) - return (0); - error = getnewvnode(VT_NON, (struct mount *) 0, spec_vnodeop_p, &nvp); + if (dev == NODEV || major(dev) >= nblkdev || + bdevsw[major(dev)] == NULL) { + *vpp = NULLVP; + return (ENXIO); + } + error = getnewvnode(VT_NON, (struct mount *)0, spec_vnodeop_p, &nvp); if (error) { - *vpp = 0; + *vpp = NULLVP; return (error); } vp = nvp; vp->v_type = VBLK; - if ((nvp = checkalias(vp, dev, (struct mount *) 0))) { + if ((nvp = checkalias(vp, dev, (struct mount *)0)) != NULL) { vput(vp); vp = nvp; }