Home | History | Annotate | Line # | Download | only in common
      1  1.5   thorpej /*	$NetBSD: bio_30.c,v 1.5 2020/12/19 22:10:56 thorpej 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.5   thorpej __KERNEL_RCSID(0, "$NetBSD: bio_30.c,v 1.5 2020/12/19 22:10:56 thorpej 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.5   thorpej #include <sys/kmem.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.5   thorpej 		struct bioc_disk *bd = kmem_zalloc(sizeof(*bd), KM_SLEEP);
     62  1.2  pgoyette 
     63  1.2  pgoyette 		(void)memcpy(bd, addr, sizeof(struct obioc_disk));
     64  1.2  pgoyette 		error = (*delegate)(cookie, BIOCDISK, bd);
     65  1.2  pgoyette 		if (error) {
     66  1.5   thorpej 			kmem_free(bd, sizeof(*bd));
     67  1.2  pgoyette 			return error;
     68  1.2  pgoyette 		}
     69  1.2  pgoyette 
     70  1.2  pgoyette 		(void)memcpy(addr, bd, sizeof(struct obioc_disk));
     71  1.5   thorpej 		kmem_free(bd, sizeof(*bd));
     72  1.2  pgoyette 		return 0;
     73  1.2  pgoyette 	}
     74  1.2  pgoyette 	case OBIOCVOL: {
     75  1.5   thorpej 		struct bioc_vol *bv = kmem_zalloc(sizeof(*bv), KM_SLEEP);
     76  1.2  pgoyette 
     77  1.2  pgoyette 		(void)memcpy(bv, addr, sizeof(struct obioc_vol));
     78  1.2  pgoyette 		error = (*delegate)(cookie, BIOCVOL, bv);
     79  1.2  pgoyette 		if (error) {
     80  1.5   thorpej 			kmem_free(bv, sizeof(*bv));
     81  1.2  pgoyette 			return error;
     82  1.2  pgoyette 		}
     83  1.2  pgoyette 
     84  1.2  pgoyette 		(void)memcpy(addr, bv, sizeof(struct obioc_vol));
     85  1.5   thorpej 		kmem_free(bv, sizeof(*bv));
     86  1.2  pgoyette 		return 0;
     87  1.2  pgoyette 	}
     88  1.2  pgoyette 	default:
     89  1.2  pgoyette 		return ENOSYS;
     90  1.2  pgoyette 	}
     91  1.2  pgoyette }
     92  1.2  pgoyette 
     93  1.2  pgoyette void
     94  1.2  pgoyette bio_30_init(void)
     95  1.2  pgoyette {
     96  1.2  pgoyette 
     97  1.4  pgoyette 	MODULE_HOOK_SET(compat_bio_30_hook, compat_30_bio);
     98  1.2  pgoyette }
     99  1.2  pgoyette 
    100  1.2  pgoyette void
    101  1.2  pgoyette bio_30_fini(void)
    102  1.2  pgoyette {
    103  1.2  pgoyette 
    104  1.3  pgoyette 	MODULE_HOOK_UNSET(compat_bio_30_hook);
    105  1.2  pgoyette }
    106