Home | History | Annotate | Line # | Download | only in common
ccd_60.c revision 1.8
      1  1.8  pgoyette /*	$NetBSD: ccd_60.c,v 1.8 2019/01/27 02:08:39 pgoyette Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*-
      4  1.1  christos  * Copyright (c) 2018 The NetBSD Foundation, Inc.
      5  1.1  christos  * All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * Redistribution and use in source and binary forms, with or without
      8  1.1  christos  * modification, are permitted provided that the following conditions
      9  1.1  christos  * are met:
     10  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     11  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     12  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  christos  *    documentation and/or other materials provided with the distribution.
     15  1.1  christos  *
     16  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1  christos  */
     28  1.1  christos #include <sys/cdefs.h>
     29  1.8  pgoyette __KERNEL_RCSID(0, "$NetBSD: ccd_60.c,v 1.8 2019/01/27 02:08:39 pgoyette Exp $");
     30  1.1  christos 
     31  1.1  christos #ifdef _KERNEL_OPT
     32  1.1  christos #include "opt_compat_netbsd.h"
     33  1.1  christos #endif
     34  1.1  christos 
     35  1.1  christos #include <sys/param.h>
     36  1.1  christos #include <sys/systm.h>
     37  1.1  christos #include <sys/disk.h>
     38  1.1  christos #include <sys/lwp.h>
     39  1.8  pgoyette #include <sys/compat_stub.h>
     40  1.1  christos 
     41  1.1  christos #include <dev/ccdvar.h>
     42  1.1  christos #include <compat/sys/ccdvar.h>
     43  1.1  christos 
     44  1.1  christos /*
     45  1.1  christos  * Compat code must not be called if on a platform where
     46  1.1  christos  * sizeof (size_t) == sizeof (uint64_t) as CCDIOCSET will
     47  1.1  christos  * be the same as CCDIOCSET_60
     48  1.1  christos  */
     49  1.7    martin #if 0
     50  1.1  christos static int
     51  1.1  christos compat_60_ccdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l,
     52  1.1  christos     int (*f)(dev_t, u_long, void *, int, struct lwp *))
     53  1.1  christos {
     54  1.1  christos 	switch (cmd) {
     55  1.3  christos #ifdef CCDIOCSET_60
     56  1.1  christos 	case CCDIOCSET_60: {
     57  1.1  christos 		if (data == NULL)
     58  1.1  christos 			return 0;
     59  1.1  christos 
     60  1.1  christos 		struct ccd_ioctl ccio;
     61  1.1  christos        		struct ccd_ioctl_60 *ccio60 = data;
     62  1.1  christos 
     63  1.1  christos 		ccio.ccio_disks = ccio60->ccio_disks;
     64  1.1  christos 		ccio.ccio_ndisks = ccio60->ccio_ndisks;
     65  1.1  christos 		ccio.ccio_ileave = ccio60->ccio_ileave;
     66  1.1  christos 		ccio.ccio_flags = ccio60->ccio_flags;
     67  1.1  christos 		ccio.ccio_unit = ccio60->ccio_unit;
     68  1.3  christos 		int error = (*f)(dev, CCDIOCSET, &ccio, flag, l);
     69  1.1  christos 		if (!error) {
     70  1.1  christos 			/* Copy data back, adjust types if necessary */
     71  1.1  christos 			ccio60->ccio_disks = ccio.ccio_disks;
     72  1.1  christos 			ccio60->ccio_ndisks = ccio.ccio_ndisks;
     73  1.1  christos 			ccio60->ccio_ileave = ccio.ccio_ileave;
     74  1.1  christos 			ccio60->ccio_flags = ccio.ccio_flags;
     75  1.1  christos 			ccio60->ccio_unit = ccio.ccio_unit;
     76  1.1  christos 			ccio60->ccio_size = (size_t)ccio.ccio_size;
     77  1.1  christos 		}
     78  1.1  christos 		return error;
     79  1.1  christos 	}
     80  1.1  christos 
     81  1.1  christos 	case CCDIOCCLR_60:
     82  1.1  christos 		if (data == NULL)
     83  1.1  christos 			return ENOSYS;
     84  1.1  christos 		/*
     85  1.1  christos 		 * ccio_size member not used, so existing struct OK
     86  1.1  christos 		 * drop through to existing non-compat version
     87  1.1  christos 		 */
     88  1.3  christos 		return (*f)(dev, CCDIOCCLR, data, flag, l);
     89  1.3  christos #endif
     90  1.1  christos 	default:
     91  1.1  christos 		return ENOSYS;
     92  1.1  christos 	}
     93  1.1  christos }
     94  1.7    martin #endif
     95  1.1  christos 
     96  1.1  christos void
     97  1.1  christos ccd_60_init(void)
     98  1.1  christos {
     99  1.8  pgoyette 
    100  1.8  pgoyette 	MODULE_SET_HOOK(ccd_ioctl_60_hook, "ccd_60", compat_60_ccdioctl);
    101  1.1  christos }
    102  1.1  christos 
    103  1.1  christos void
    104  1.1  christos ccd_60_fini(void)
    105  1.1  christos {
    106  1.8  pgoyette 
    107  1.8  pgoyette 	MODULE_UNSET_HOOK(ccd_ioctl_60_hook);
    108  1.1  christos }
    109