Home | History | Annotate | Line # | Download | only in common
bio_30.c revision 1.1.2.2
      1 /*	$NetBSD: bio_30.c,v 1.1.2.2 2018/09/17 11:04:30 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.1.2.2 2018/09/17 11:04:30 pgoyette Exp $");
     30 
     31 #include <sys/param.h>
     32 #include <sys/conf.h>
     33 #include <sys/device.h>
     34 #include <sys/event.h>
     35 #include <sys/ioctl.h>
     36 #include <sys/malloc.h>
     37 #include <sys/queue.h>
     38 #include <sys/systm.h>
     39 #include <sys/mutex.h>
     40 #include <sys/proc.h>
     41 #include <sys/kauth.h>
     42 #include <sys/compat_stub.h>
     43 
     44 #include <dev/biovar.h>
     45 #include <dev/sysmon/sysmonvar.h>
     46 
     47 #include <compat/common/compat_mod.h>
     48 
     49 static int
     50 compat_30_bio(void *cookie, u_long cmd, void *addr,
     51     int (*delegate)(void *, u_long, void *))
     52 {
     53 	int error;
     54 
     55 	switch (cmd) {
     56 	case OBIOCDISK: {
     57 		struct bioc_disk *bd =
     58 		    malloc(sizeof(*bd), M_DEVBUF, M_WAITOK|M_ZERO);
     59 
     60 		(void)memcpy(bd, addr, sizeof(struct obioc_disk));
     61 		error = (*delegate)(cookie, BIOCDISK, bd);
     62 		if (error) {
     63 			free(bd, M_DEVBUF);
     64 			return error;
     65 		}
     66 
     67 		(void)memcpy(addr, bd, sizeof(struct obioc_disk));
     68 		free(bd, M_DEVBUF);
     69 		return 0;
     70 	}
     71 	case OBIOCVOL: {
     72 		struct bioc_vol *bv =
     73 		    malloc(sizeof(*bv), M_DEVBUF, M_WAITOK|M_ZERO);
     74 
     75 		(void)memcpy(bv, addr, sizeof(struct obioc_vol));
     76 		error = (*delegate)(cookie, BIOCVOL, bv);
     77 		if (error) {
     78 			free(bv, M_DEVBUF);
     79 			return error;
     80 		}
     81 
     82 		(void)memcpy(addr, bv, sizeof(struct obioc_vol));
     83 		free(bv, M_DEVBUF);
     84 		return 0;
     85 	}
     86 	default:
     87 		return ENOSYS;
     88 	}
     89 }
     90 
     91 COMPAT_SET_HOOK(compat_bio_30_hook, "bio_30", compat_30_bio);
     92 COMPAT_UNSET_HOOK(compat_bio_30_hook);
     93 
     94 void
     95 bio_30_init(void)
     96 {
     97 
     98 	compat_bio_30_hook_set();
     99 }
    100 
    101 void
    102 bio_30_fini(void)
    103 {
    104 
    105 	compat_bio_30_hook_unset();
    106 }
    107