From 94bc17b82cc0bad0b16091fa71123bd486b0e489 Mon Sep 17 00:00:00 2001 From: mrg Date: Sun, 19 Sep 2010 07:11:42 +0000 Subject: [PATCH] fix the vnd_osize changes on 32 bit platforms with 64 bit alignment for 64 bit integers (eg, sparc). the problem was that the new 64 bit element on the end was used for the offsetof() (aka size) for the old structure, but this includes the padding required, thus the ioctl number was set wrongly. move all the supporting code for this inside COMPAT_50, with some renaming to suit, and kill all the external definitions related to it. tested on i386, amd64 and sparc. --- sys/dev/vnd.c | 37 ++++++++++++++++++++++++------------- sys/dev/vndvar.h | 8 +------- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/sys/dev/vnd.c b/sys/dev/vnd.c index 7a730bb8dec5..fd52544578d7 100644 --- a/sys/dev/vnd.c +++ b/sys/dev/vnd.c @@ -1,4 +1,4 @@ -/* $NetBSD: vnd.c,v 1.211 2010/09/19 05:50:28 mrg Exp $ */ +/* $NetBSD: vnd.c,v 1.212 2010/09/19 07:11:42 mrg Exp $ */ /*- * Copyright (c) 1996, 1997, 1998, 2008 The NetBSD Foundation, Inc. @@ -130,7 +130,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.211 2010/09/19 05:50:28 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: vnd.c,v 1.212 2010/09/19 07:11:42 mrg Exp $"); #if defined(_KERNEL_OPT) #include "opt_vnd.h" @@ -211,6 +211,15 @@ struct vnd_user50 { ino_t vnu_ino; /* ...at this inode */ }; #define VNDIOCGET50 _IOWR('F', 3, struct vnd_user50) /* get list */ + +struct vnd_ioctl50 { + char *vnd_file; /* pathname of file to mount */ + int vnd_flags; /* flags; see below */ + struct vndgeom vnd_geom; /* geometry to emulate */ + unsigned int vnd_size; /* (returned) size of disk */ +}; +#define VNDIOCSET50 _IOWR('F', 0, struct vnd_ioctl50) +#define VNDIOCCLR50 _IOW('F', 1, struct vnd_ioctl50) #endif /* called by main() at boot time */ @@ -1064,9 +1073,11 @@ vndioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) switch (cmd) { case VNDIOCSET: case VNDIOCCLR: -#ifdef VNDIOOCSET - case VNDIOOCSET: - case VNDIOOCCLR: +#ifdef VNDIOCSET50 + case VNDIOCSET50: +#endif +#ifdef VNDIOCCLR50 + case VNDIOCCLR50: #endif case DIOCSDINFO: case DIOCWDINFO: @@ -1083,8 +1094,8 @@ vndioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) /* Must be initialized for these... */ switch (cmd) { case VNDIOCCLR: -#ifdef VNDIOOCCLR - case VNDIOOCCLR: +#ifdef VNDIOCCLR50 + case VNDIOCCLR50: #endif case DIOCGDINFO: case DIOCSDINFO: @@ -1105,8 +1116,8 @@ vndioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) } switch (cmd) { -#ifdef VNDIOOCSET - case VNDIOOCSET: +#ifdef VNDIOCSET50 + case VNDIOCSET50: #endif case VNDIOCSET: if (vnd->sc_flags & VNF_INITED) @@ -1313,8 +1324,8 @@ vndioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l) vndthrottle(vnd, vnd->sc_vp); vio->vnd_osize = dbtob(vnd->sc_size); -#ifdef VNDIOOCSET - if (cmd != VNDIOOCSET) +#ifdef VNDIOCSET50 + if (cmd != VNDIOCSET50) #endif vio->vnd_size = dbtob(vnd->sc_size); vnd->sc_flags |= VNF_INITED; @@ -1373,8 +1384,8 @@ unlock_and_exit: vndunlock(vnd); return error; -#ifdef VNDIOOCCLR - case VNDIOOCCLR: +#ifdef VNDIOCCLR50 + case VNDIOCCLR50: #endif case VNDIOCCLR: part = DISKPART(dev); diff --git a/sys/dev/vndvar.h b/sys/dev/vndvar.h index 772fe8e9ce05..6a13608a2bba 100644 --- a/sys/dev/vndvar.h +++ b/sys/dev/vndvar.h @@ -1,4 +1,4 @@ -/* $NetBSD: vndvar.h,v 1.27 2010/09/19 05:50:28 mrg Exp $ */ +/* $NetBSD: vndvar.h,v 1.28 2010/09/19 07:11:42 mrg Exp $ */ /*- * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. @@ -210,10 +210,4 @@ struct vnd_user { #define VNDIOCCLR _IOW('F', 1, struct vnd_ioctl) /* disable disk */ #define VNDIOCGET _IOWR('F', 3, struct vnd_user) /* get list */ -/* These only have the 32bit vnd_osize field */ -#define VNDIOOCSET _IOC(IOC_INOUT, 'F', 0, \ - offsetof(struct vnd_ioctl, vnd_size)) -#define VNDIOOCCLR _IOC(IOC_IN, 'F', 1, \ - offsetof(struct vnd_ioctl, vnd_size)) - #endif /* _SYS_DEV_VNDVAR_H_ */