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