Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-7]: src/sys Pull up following revision(s) (requested by manu in t...



details:   https://anonhg.NetBSD.org/src/rev/d6b2380cbdfb
branches:  netbsd-7
changeset: 799716:d6b2380cbdfb
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Wed Nov 18 08:48:46 2015 +0000

description:
Pull up following revision(s) (requested by manu in ticket #1038):
        sys/dev/vnd.c: revision 1.252
        sys/dev/vnd.c: revision 1.253
        sys/dev/vnd.c: revision 1.254
        sys/dev/vnd.c: revision 1.249
        sys/sys/disk.h: revision 1.66
        sys/dev/vnd.c: revision 1.250
        sys/dev/vnd.c: revision 1.251
- Add DK_DEV_BSIZE_OK()
- Simplify ioctl handling a little.
- disable debugging
- Return ENXIO if the get ioctl exceeds the number of configured devices.
  XXX: pullup-7
- explain why the int cast works (suggested by kre)
- fix incorrect memset.
- Use the new DK_DEV_BSIZE_OK() macro.

diffstat:

 sys/dev/vnd.c  |  150 +++++++++++++++++++++++++-------------------------------
 sys/sys/disk.h |    4 +-
 2 files changed, 70 insertions(+), 84 deletions(-)

diffs (237 lines):

diff -r 22fc07016858 -r d6b2380cbdfb sys/dev/vnd.c
--- a/sys/dev/vnd.c     Wed Nov 18 08:33:08 2015 +0000
+++ b/sys/dev/vnd.c     Wed Nov 18 08:48:46 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vnd.c,v 1.232.2.3 2015/01/28 19:16:21 martin Exp $     */
+/*     $NetBSD: vnd.c,v 1.232.2.4 2015/11/18 08:48:46 msaitoh Exp $    */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.232.2.3 2015/01/28 19:16:21 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.232.2.4 2015/11/18 08:48:46 msaitoh Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_vnd.h"
@@ -137,7 +137,7 @@
 #define VDB_INIT       0x02
 #define VDB_IO         0x04
 #define VDB_LABEL      0x08
-int vnddebug = 0x00;
+int vnddebug = 0;
 #endif
 
 #define vndunit(x)     DISKUNIT(x)
@@ -1030,7 +1030,7 @@
        vndclear(vnd, minor);
 #ifdef DEBUG
        if (vnddebug & VDB_INIT)
-               printf("vndioctl: CLRed\n");
+               printf("%s: CLRed\n", __func__);
 #endif
 
        /* Destroy the xfer and buffer pools. */
@@ -1042,6 +1042,29 @@
        return 0;
 }
 
+static int
+vndioctl_get(struct lwp *l, void *data, int unit, struct vattr *va)
+{
+       int error;
+
+       KASSERT(l);
+
+       /* the first member is always int vnd_unit in all the versions */
+       if (*(int *)data >= vnd_cd.cd_ndevs)
+               return ENXIO;
+
+       switch (error = vnd_cget(l, unit, (int *)data, va)) {
+       case -1:
+               /* unused is not an error */
+               memset(va, 0, sizeof(*va));
+               /*FALLTHROUGH*/
+       case 0:
+               return 0;
+       default:
+               return error;
+       }
+}
+
 /* ARGSUSED */
 static int
 vndioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
@@ -1067,15 +1090,46 @@
                printf("vndioctl(0x%"PRIx64", 0x%lx, %p, 0x%x, %p): unit %d\n",
                    dev, cmd, data, flag, l->l_proc, unit);
 #endif
-       vnd = device_lookup_private(&vnd_cd, unit);
-       if (vnd == NULL &&
+       /* Do the get's first; they don't need initialization or verification */
+       switch (cmd) {
 #ifdef COMPAT_30
-           cmd != VNDIOCGET30 &&
+       case VNDIOCGET30: {
+               if ((error = vndioctl_get(l, data, unit, &vattr)) != 0)
+                       return error;
+
+               struct vnd_user30 *vnu = data;
+               vnu->vnu_dev = vattr.va_fsid;
+               vnu->vnu_ino = vattr.va_fileid;
+               return 0;
+       }
 #endif
 #ifdef COMPAT_50
-           cmd != VNDIOCGET50 &&
+       case VNDIOCGET50: {
+               if ((error = vndioctl_get(l, data, unit, &vattr)) != 0)
+                       return error;
+
+               struct vnd_user50 *vnu = data;
+               vnu->vnu_dev = vattr.va_fsid;
+               vnu->vnu_ino = vattr.va_fileid;
+               return 0;
+       }
 #endif
-           cmd != VNDIOCGET)
+
+       case VNDIOCGET: {
+               if ((error = vndioctl_get(l, data, unit, &vattr)) != 0)
+                       return error;
+
+               struct vnd_user *vnu = data;
+               vnu->vnu_dev = vattr.va_fsid;
+               vnu->vnu_ino = vattr.va_fileid;
+               return 0;
+       }
+       default:
+               break;
+       }
+
+       vnd = device_lookup_private(&vnd_cd, unit);
+       if (vnd == NULL)
                return ENXIO;
        vio = (struct vnd_ioctl *)data;
 
@@ -1190,8 +1244,7 @@
                        /* note last offset is the file byte size */
                        vnd->sc_comp_numoffs = ntohl(ch->num_blocks)+1;
                        free(ch, M_TEMP);
-                       if (vnd->sc_comp_blksz == 0 ||
-                           vnd->sc_comp_blksz % DEV_BSIZE !=0) {
+                       if (!DK_DEV_BSIZE_OK(vnd->sc_comp_blksz)) {
                                VOP_UNLOCK(nd.ni_vp);
                                error = EINVAL;
                                goto close_and_exit;
@@ -1286,14 +1339,11 @@
 
                        /*
                         * Sanity-check the sector size.
-                        * XXX Don't allow secsize < DEV_BSIZE.  Should
-                        * XXX we?
                         */
-                       if (vnd->sc_geom.vng_secsize < DEV_BSIZE ||
-                           (vnd->sc_geom.vng_secsize % DEV_BSIZE) != 0 ||
+                       if (!DK_DEV_BSIZE_OK(vnd->sc_geom.vng_secsize) ||
                            vnd->sc_geom.vng_ncylinders == 0 ||
-                           (vnd->sc_geom.vng_ntracks *
-                            vnd->sc_geom.vng_nsectors) == 0) {
+                           vnd->sc_geom.vng_ntracks == 0 ||
+                           vnd->sc_geom.vng_nsectors == 0) {
                                error = EINVAL;
                                goto close_and_exit;
                        }
@@ -1418,72 +1468,6 @@
 
                break;
 
-#ifdef COMPAT_30
-       case VNDIOCGET30: {
-               struct vnd_user30 *vnu;
-               struct vattr va;
-               vnu = (struct vnd_user30 *)data;
-               KASSERT(l);
-               switch (error = vnd_cget(l, unit, &vnu->vnu_unit, &va)) {
-               case 0:
-                       vnu->vnu_dev = va.va_fsid;
-                       vnu->vnu_ino = va.va_fileid;
-                       break;
-               case -1:
-                       /* unused is not an error */
-                       vnu->vnu_dev = 0;
-                       vnu->vnu_ino = 0;
-                       break;
-               default:
-                       return error;
-               }
-               break;
-       }
-#endif
-
-#ifdef COMPAT_50
-       case VNDIOCGET50: {
-               struct vnd_user50 *vnu;
-               struct vattr va;
-               vnu = (struct vnd_user50 *)data;
-               KASSERT(l);
-               switch (error = vnd_cget(l, unit, &vnu->vnu_unit, &va)) {
-               case 0:
-                       vnu->vnu_dev = va.va_fsid;
-                       vnu->vnu_ino = va.va_fileid;
-                       break;
-               case -1:
-                       /* unused is not an error */
-                       vnu->vnu_dev = 0;
-                       vnu->vnu_ino = 0;
-                       break;
-               default:
-                       return error;
-               }
-               break;
-       }
-#endif
-
-       case VNDIOCGET: {
-               struct vnd_user *vnu;
-               struct vattr va;
-               vnu = (struct vnd_user *)data;
-               KASSERT(l);
-               switch (error = vnd_cget(l, unit, &vnu->vnu_unit, &va)) {
-               case 0:
-                       vnu->vnu_dev = va.va_fsid;
-                       vnu->vnu_ino = va.va_fileid;
-                       break;
-               case -1:
-                       /* unused is not an error */
-                       vnu->vnu_dev = 0;
-                       vnu->vnu_ino = 0;
-                       break;
-               default:
-                       return error;
-               }
-               break;
-       }
 
        case DIOCGDINFO:
                *(struct disklabel *)data = *(vnd->sc_dkdev.dk_label);
diff -r 22fc07016858 -r d6b2380cbdfb sys/sys/disk.h
--- a/sys/sys/disk.h    Wed Nov 18 08:33:08 2015 +0000
+++ b/sys/sys/disk.h    Wed Nov 18 08:48:46 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: disk.h,v 1.60 2014/04/03 15:24:20 christos Exp $       */
+/*     $NetBSD: disk.h,v 1.60.4.1 2015/11/18 08:48:46 msaitoh Exp $    */
 
 /*-
  * Copyright (c) 1996, 1997, 2004 The NetBSD Foundation, Inc.
@@ -507,6 +507,8 @@
 
 #define        DK_BSIZE2BLKSHIFT(b)    ((ffs((b) / DEV_BSIZE)) - 1)
 #define        DK_BSIZE2BYTESHIFT(b)   (ffs((b)) - 1)
+#define DK_DEV_BSIZE_OK(b) \
+    ((b) >= DEV_BSIZE && ((b) & ((b) - 1)) == 0 && (b) <= MAXPHYS)
 
 #ifdef _KERNEL
 extern int disk_count;                 /* number of disks in global disklist */



Home | Main Index | Thread Index | Old Index