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