1 /* $NetBSD: ccd_60.c,v 1.10 2019/03/01 11:06:56 pgoyette Exp $ */ 2 3 /*- 4 * Copyright (c) 2018 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 * POSSIBILITY OF SUCH DAMAGE. 27 */ 28 #include <sys/cdefs.h> 29 __KERNEL_RCSID(0, "$NetBSD: ccd_60.c,v 1.10 2019/03/01 11:06:56 pgoyette Exp $"); 30 31 #ifdef _KERNEL_OPT 32 #include "opt_compat_netbsd.h" 33 #endif 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/disk.h> 38 #include <sys/lwp.h> 39 #include <sys/compat_stub.h> 40 41 #include <dev/ccdvar.h> 42 #include <compat/sys/ccdvar.h> 43 44 /* 45 * Compat code must not be called if on a platform where 46 * sizeof (size_t) == sizeof (uint64_t) as CCDIOCSET will 47 * be the same as CCDIOCSET_60 48 */ 49 static int 50 compat_60_ccdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l, 51 int (*f)(dev_t, u_long, void *, int, struct lwp *)) 52 { 53 switch (cmd) { 54 #ifdef CCDIOCSET_60 55 case CCDIOCSET_60: { 56 if (data == NULL) 57 return 0; 58 59 struct ccd_ioctl ccio; 60 struct ccd_ioctl_60 *ccio60 = data; 61 62 ccio.ccio_disks = ccio60->ccio_disks; 63 ccio.ccio_ndisks = ccio60->ccio_ndisks; 64 ccio.ccio_ileave = ccio60->ccio_ileave; 65 ccio.ccio_flags = ccio60->ccio_flags; 66 ccio.ccio_unit = ccio60->ccio_unit; 67 int error = (*f)(dev, CCDIOCSET, &ccio, flag, l); 68 if (!error) { 69 /* Copy data back, adjust types if necessary */ 70 ccio60->ccio_disks = ccio.ccio_disks; 71 ccio60->ccio_ndisks = ccio.ccio_ndisks; 72 ccio60->ccio_ileave = ccio.ccio_ileave; 73 ccio60->ccio_flags = ccio.ccio_flags; 74 ccio60->ccio_unit = ccio.ccio_unit; 75 ccio60->ccio_size = (size_t)ccio.ccio_size; 76 } 77 return error; 78 } 79 80 case CCDIOCCLR_60: 81 if (data == NULL) 82 return ENOSYS; 83 /* 84 * ccio_size member not used, so existing struct OK 85 * drop through to existing non-compat version 86 */ 87 return (*f)(dev, CCDIOCCLR, data, flag, l); 88 #endif 89 default: 90 return ENOSYS; 91 } 92 } 93 94 void 95 ccd_60_init(void) 96 { 97 98 MODULE_HOOK_SET(ccd_ioctl_60_hook, "ccd_60", compat_60_ccdioctl); 99 } 100 101 void 102 ccd_60_fini(void) 103 { 104 105 MODULE_HOOK_UNSET(ccd_ioctl_60_hook); 106 } 107