bio_30.c revision 1.2 1 /* $NetBSD: bio_30.c,v 1.2 2019/01/27 02:08:39 pgoyette Exp $ */
2 /* $OpenBSD: bio.c,v 1.9 2007/03/20 02:35:55 marco Exp $ */
3
4 /*
5 * Copyright (c) 2002 Niklas Hallqvist. 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 AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: bio_30.c,v 1.2 2019/01/27 02:08:39 pgoyette Exp $");
30
31 #if defined(_KERNEL_OPT)
32 #include "opt_compat_netbsd.h"
33 #endif
34
35 #include <sys/param.h>
36 #include <sys/conf.h>
37 #include <sys/device.h>
38 #include <sys/event.h>
39 #include <sys/ioctl.h>
40 #include <sys/malloc.h>
41 #include <sys/queue.h>
42 #include <sys/systm.h>
43 #include <sys/mutex.h>
44 #include <sys/proc.h>
45 #include <sys/kauth.h>
46 #include <sys/compat_stub.h>
47
48 #include <dev/biovar.h>
49 #include <dev/sysmon/sysmonvar.h>
50
51 #include <compat/common/compat_mod.h>
52
53 static int
54 compat_30_bio(void *cookie, u_long cmd, void *addr,
55 int (*delegate)(void *, u_long, void *))
56 {
57 int error;
58
59 switch (cmd) {
60 case OBIOCDISK: {
61 struct bioc_disk *bd =
62 malloc(sizeof(*bd), M_DEVBUF, M_WAITOK|M_ZERO);
63
64 (void)memcpy(bd, addr, sizeof(struct obioc_disk));
65 error = (*delegate)(cookie, BIOCDISK, bd);
66 if (error) {
67 free(bd, M_DEVBUF);
68 return error;
69 }
70
71 (void)memcpy(addr, bd, sizeof(struct obioc_disk));
72 free(bd, M_DEVBUF);
73 return 0;
74 }
75 case OBIOCVOL: {
76 struct bioc_vol *bv =
77 malloc(sizeof(*bv), M_DEVBUF, M_WAITOK|M_ZERO);
78
79 (void)memcpy(bv, addr, sizeof(struct obioc_vol));
80 error = (*delegate)(cookie, BIOCVOL, bv);
81 if (error) {
82 free(bv, M_DEVBUF);
83 return error;
84 }
85
86 (void)memcpy(addr, bv, sizeof(struct obioc_vol));
87 free(bv, M_DEVBUF);
88 return 0;
89 }
90 default:
91 return ENOSYS;
92 }
93 }
94
95 void
96 bio_30_init(void)
97 {
98
99 MODULE_SET_HOOK(compat_bio_30_hook, "bio_30", compat_30_bio);
100 }
101
102 void
103 bio_30_fini(void)
104 {
105
106 MODULE_UNSET_HOOK(compat_bio_30_hook);
107 }
108