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