ccd_60.c revision 1.8 1 /* $NetBSD: ccd_60.c,v 1.8 2019/01/27 02:08:39 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.8 2019/01/27 02:08:39 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 #if 0
50 static int
51 compat_60_ccdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l,
52 int (*f)(dev_t, u_long, void *, int, struct lwp *))
53 {
54 switch (cmd) {
55 #ifdef CCDIOCSET_60
56 case CCDIOCSET_60: {
57 if (data == NULL)
58 return 0;
59
60 struct ccd_ioctl ccio;
61 struct ccd_ioctl_60 *ccio60 = data;
62
63 ccio.ccio_disks = ccio60->ccio_disks;
64 ccio.ccio_ndisks = ccio60->ccio_ndisks;
65 ccio.ccio_ileave = ccio60->ccio_ileave;
66 ccio.ccio_flags = ccio60->ccio_flags;
67 ccio.ccio_unit = ccio60->ccio_unit;
68 int error = (*f)(dev, CCDIOCSET, &ccio, flag, l);
69 if (!error) {
70 /* Copy data back, adjust types if necessary */
71 ccio60->ccio_disks = ccio.ccio_disks;
72 ccio60->ccio_ndisks = ccio.ccio_ndisks;
73 ccio60->ccio_ileave = ccio.ccio_ileave;
74 ccio60->ccio_flags = ccio.ccio_flags;
75 ccio60->ccio_unit = ccio.ccio_unit;
76 ccio60->ccio_size = (size_t)ccio.ccio_size;
77 }
78 return error;
79 }
80
81 case CCDIOCCLR_60:
82 if (data == NULL)
83 return ENOSYS;
84 /*
85 * ccio_size member not used, so existing struct OK
86 * drop through to existing non-compat version
87 */
88 return (*f)(dev, CCDIOCCLR, data, flag, l);
89 #endif
90 default:
91 return ENOSYS;
92 }
93 }
94 #endif
95
96 void
97 ccd_60_init(void)
98 {
99
100 MODULE_SET_HOOK(ccd_ioctl_60_hook, "ccd_60", compat_60_ccdioctl);
101 }
102
103 void
104 ccd_60_fini(void)
105 {
106
107 MODULE_UNSET_HOOK(ccd_ioctl_60_hook);
108 }
109