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