Home | History | Annotate | Line # | Download | only in common
ccd_60.c revision 1.1
      1 /*	$NetBSD: ccd_60.c,v 1.1 2018/03/18 20:33:52 christos Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2018 The NetBSD Foundation, Inc.
      5  * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 #include <sys/cdefs.h>
     29 __KERNEL_RCSID(0, "$NetBSD: ccd_60.c,v 1.1 2018/03/18 20:33:52 christos Exp $");
     30 
     31 #ifdef _KERNEL_OPT
     32 #include "opt_compat_netbsd.h"
     33 #endif
     34 
     35 #include <sys/param.h>
     36 #include <sys/systm.h>
     37 #include <sys/disk.h>
     38 #include <sys/lwp.h>
     39 
     40 #include <dev/ccdvar.h>
     41 #include <compat/sys/ccdvar.h>
     42 
     43 /*
     44  * Compat code must not be called if on a platform where
     45  * sizeof (size_t) == sizeof (uint64_t) as CCDIOCSET will
     46  * be the same as CCDIOCSET_60
     47  */
     48 static int
     49 compat_60_ccdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l,
     50     int (*f)(dev_t, u_long, void *, int, struct lwp *))
     51 {
     52 	switch (cmd) {
     53 #if defined(COMPAT_60) && !defined(_LP64)
     54 	case CCDIOCSET_60: {
     55 		if (data == NULL)
     56 			return 0;
     57 
     58 		struct ccd_ioctl ccio;
     59        		struct ccd_ioctl_60 *ccio60 = data;
     60 
     61 		ccio.ccio_disks = ccio60->ccio_disks;
     62 		ccio.ccio_ndisks = ccio60->ccio_ndisks;
     63 		ccio.ccio_ileave = ccio60->ccio_ileave;
     64 		ccio.ccio_flags = ccio60->ccio_flags;
     65 		ccio.ccio_unit = ccio60->ccio_unit;
     66 		error = (*f)(dev, CCDIOCSET, &ccio, flag, l);
     67 		if (!error) {
     68 			/* Copy data back, adjust types if necessary */
     69 			ccio60->ccio_disks = ccio.ccio_disks;
     70 			ccio60->ccio_ndisks = ccio.ccio_ndisks;
     71 			ccio60->ccio_ileave = ccio.ccio_ileave;
     72 			ccio60->ccio_flags = ccio.ccio_flags;
     73 			ccio60->ccio_unit = ccio.ccio_unit;
     74 			ccio60->ccio_size = (size_t)ccio.ccio_size;
     75 		}
     76 		return error;
     77 	}
     78 
     79 	case CCDIOCCLR_60:
     80 		if (data == NULL)
     81 			return ENOSYS;
     82 		/*
     83 		 * ccio_size member not used, so existing struct OK
     84 		 * drop through to existing non-compat version
     85 		 */
     86 		return (*f)(dev, CCDIOCLR, data, flag, l);
     87 #endif /* COMPAT_60 && !_LP64*/
     88 	default:
     89 		return ENOSYS;
     90 	}
     91 }
     92 
     93 void
     94 ccd_60_init(void)
     95 {
     96     compat_ccd_ioctl_60 = compat_60_ccdioctl;
     97 }
     98 
     99 void
    100 ccd_60_fini(void)
    101 {
    102     compat_ccd_ioctl_60 = (void *)enosys;
    103 }
    104