Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev Simplify ioctl handling a little.
details: https://anonhg.NetBSD.org/src/rev/7327bbf23418
branches: trunk
changeset: 341513:7327bbf23418
user: christos <christos%NetBSD.org@localhost>
date: Mon Nov 09 16:52:09 2015 +0000
description:
Simplify ioctl handling a little.
diffstat:
sys/dev/vnd.c | 140 ++++++++++++++++++++++++++-------------------------------
1 files changed, 65 insertions(+), 75 deletions(-)
diffs (199 lines):
diff -r b6e820ffae91 -r 7327bbf23418 sys/dev/vnd.c
--- a/sys/dev/vnd.c Mon Nov 09 15:12:12 2015 +0000
+++ b/sys/dev/vnd.c Mon Nov 09 16:52:09 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vnd.c,v 1.248 2015/08/20 14:40:17 christos Exp $ */
+/* $NetBSD: vnd.c,v 1.249 2015/11/09 16:52:09 christos Exp $ */
/*-
* Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc.
@@ -91,13 +91,14 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.248 2015/08/20 14:40:17 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.249 2015/11/09 16:52:09 christos Exp $");
#if defined(_KERNEL_OPT)
#include "opt_vnd.h"
#include "opt_compat_netbsd.h"
#endif
+#define DEBUG
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/namei.h>
@@ -139,7 +140,7 @@
#define VDB_INIT 0x02
#define VDB_IO 0x04
#define VDB_LABEL 0x08
-int vnddebug = 0x00;
+int vnddebug = 0xff;
#endif
#define vndunit(x) DISKUNIT(x)
@@ -1049,7 +1050,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. */
@@ -1061,6 +1062,30 @@
return 0;
}
+static int
+vndioctl_get(struct lwp *l, void *data, int unit, struct vattr *va)
+{
+ int error;
+
+ KASSERT(l);
+#ifdef notyet
+ /* Current userland code does not handle this */
+ if (*(int *)data >= vnd_cd.cd_ndevs)
+ return ENXIO;
+#endif
+
+ 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)
@@ -1084,15 +1109,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;
@@ -1435,72 +1491,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 DIOCWDINFO:
case DIOCSDINFO:
Home |
Main Index |
Thread Index |
Old Index