Home | History | Annotate | Line # | Download | only in common
      1  1.11  pgoyette /*	$NetBSD: ccd_60.c,v 1.11 2019/12/12 02:15:42 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.11  pgoyette __KERNEL_RCSID(0, "$NetBSD: ccd_60.c,v 1.11 2019/12/12 02:15:42 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.1  christos static int
     50   1.1  christos compat_60_ccdioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l,
     51   1.1  christos     int (*f)(dev_t, u_long, void *, int, struct lwp *))
     52   1.1  christos {
     53   1.1  christos 	switch (cmd) {
     54   1.3  christos #ifdef CCDIOCSET_60
     55   1.1  christos 	case CCDIOCSET_60: {
     56   1.1  christos 		if (data == NULL)
     57   1.1  christos 			return 0;
     58   1.1  christos 
     59   1.1  christos 		struct ccd_ioctl ccio;
     60   1.1  christos        		struct ccd_ioctl_60 *ccio60 = data;
     61   1.1  christos 
     62   1.1  christos 		ccio.ccio_disks = ccio60->ccio_disks;
     63   1.1  christos 		ccio.ccio_ndisks = ccio60->ccio_ndisks;
     64   1.1  christos 		ccio.ccio_ileave = ccio60->ccio_ileave;
     65   1.1  christos 		ccio.ccio_flags = ccio60->ccio_flags;
     66   1.1  christos 		ccio.ccio_unit = ccio60->ccio_unit;
     67   1.3  christos 		int error = (*f)(dev, CCDIOCSET, &ccio, flag, l);
     68   1.1  christos 		if (!error) {
     69   1.1  christos 			/* Copy data back, adjust types if necessary */
     70   1.1  christos 			ccio60->ccio_disks = ccio.ccio_disks;
     71   1.1  christos 			ccio60->ccio_ndisks = ccio.ccio_ndisks;
     72   1.1  christos 			ccio60->ccio_ileave = ccio.ccio_ileave;
     73   1.1  christos 			ccio60->ccio_flags = ccio.ccio_flags;
     74   1.1  christos 			ccio60->ccio_unit = ccio.ccio_unit;
     75   1.1  christos 			ccio60->ccio_size = (size_t)ccio.ccio_size;
     76   1.1  christos 		}
     77   1.1  christos 		return error;
     78   1.1  christos 	}
     79   1.1  christos 
     80   1.1  christos 	case CCDIOCCLR_60:
     81   1.1  christos 		if (data == NULL)
     82   1.1  christos 			return ENOSYS;
     83   1.1  christos 		/*
     84   1.1  christos 		 * ccio_size member not used, so existing struct OK
     85   1.1  christos 		 * drop through to existing non-compat version
     86   1.1  christos 		 */
     87   1.3  christos 		return (*f)(dev, CCDIOCCLR, data, flag, l);
     88   1.3  christos #endif
     89   1.1  christos 	default:
     90   1.1  christos 		return ENOSYS;
     91   1.1  christos 	}
     92   1.1  christos }
     93   1.1  christos 
     94   1.1  christos void
     95   1.1  christos ccd_60_init(void)
     96   1.1  christos {
     97   1.8  pgoyette 
     98  1.11  pgoyette 	MODULE_HOOK_SET(ccd_ioctl_60_hook, compat_60_ccdioctl);
     99   1.1  christos }
    100   1.1  christos 
    101   1.1  christos void
    102   1.1  christos ccd_60_fini(void)
    103   1.1  christos {
    104   1.8  pgoyette 
    105  1.10  pgoyette 	MODULE_HOOK_UNSET(ccd_ioctl_60_hook);
    106   1.1  christos }
    107