Home | History | Annotate | Line # | Download | only in common
rndpseudo_50.c revision 1.1
      1  1.1  apb /*	$NetBSD: rndpseudo_50.c,v 1.1 2011/12/19 21:53:52 apb Exp $	*/
      2  1.1  apb 
      3  1.1  apb /*-
      4  1.1  apb  * Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
      5  1.1  apb  * All rights reserved.
      6  1.1  apb  *
      7  1.1  apb  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  apb  * by Michael Graff <explorer (at) flame.org> and Thor Lancelot Simon.
      9  1.1  apb  *
     10  1.1  apb  * Redistribution and use in source and binary forms, with or without
     11  1.1  apb  * modification, are permitted provided that the following conditions
     12  1.1  apb  * are met:
     13  1.1  apb  * 1. Redistributions of source code must retain the above copyright
     14  1.1  apb  *    notice, this list of conditions and the following disclaimer.
     15  1.1  apb  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  apb  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  apb  *    documentation and/or other materials provided with the distribution.
     18  1.1  apb  *
     19  1.1  apb  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1  apb  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1  apb  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1  apb  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1  apb  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1  apb  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1  apb  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1  apb  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1  apb  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1  apb  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1  apb  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1  apb  */
     31  1.1  apb 
     32  1.1  apb #include <sys/cdefs.h>
     33  1.1  apb __KERNEL_RCSID(0, "$NetBSD: rndpseudo_50.c,v 1.1 2011/12/19 21:53:52 apb Exp $");
     34  1.1  apb 
     35  1.1  apb #if defined(_KERNEL_OPT)
     36  1.1  apb #include "opt_compat_netbsd.h"
     37  1.1  apb #include "opt_compat_netbsd32.h"
     38  1.1  apb #endif
     39  1.1  apb 
     40  1.1  apb #include <sys/param.h>
     41  1.1  apb #include <sys/file.h>
     42  1.1  apb 
     43  1.1  apb #include <sys/rnd.h>
     44  1.1  apb #include <compat/sys/rnd.h>
     45  1.1  apb 
     46  1.1  apb /*
     47  1.1  apb  * Convert from rndsource_t to rndsource50_t, for the results from
     48  1.1  apb  * RNDGETNUM50 and RNDGETNAME50.
     49  1.1  apb  */
     50  1.1  apb static void
     51  1.1  apb rndsource_to_rndsource50(rndsource_t *r, rndsource50_t *r50)
     52  1.1  apb {
     53  1.1  apb 	memset(r50, 0, sizeof(*r50));
     54  1.1  apb 	strlcpy(r50->name, r->name, sizeof(r50->name));
     55  1.1  apb 	r50->total = r->total;
     56  1.1  apb 	r50->type = r->type;
     57  1.1  apb 	r50->flags = r->flags;
     58  1.1  apb }
     59  1.1  apb 
     60  1.1  apb #ifdef COMPAT_NETBSD32
     61  1.1  apb /*
     62  1.1  apb  * Convert from rndsource_t to rndsource50_32_t, for the results from
     63  1.1  apb  * RNDGETNUM50_32 and RNDGETNAME50_32.
     64  1.1  apb  */
     65  1.1  apb static void
     66  1.1  apb rndsource_to_rndsource50_32(rndsource_t *r, rndsource50_32_t *r50_32)
     67  1.1  apb {
     68  1.1  apb 	memset(r50_32, 0, sizeof(*r50_32));
     69  1.1  apb 	strlcpy(r50_32->name, r->name, sizeof(r50_32->name));
     70  1.1  apb 	r50_32->total = r->total;
     71  1.1  apb 	r50_32->type = r->type;
     72  1.1  apb 	r50_32->flags = r->flags;
     73  1.1  apb }
     74  1.1  apb #endif /* COMPAT_NETBSD32 */
     75  1.1  apb 
     76  1.1  apb /*
     77  1.1  apb  * COMPAT_50 handling for rnd_ioctl.  This is called from rnd_ioctl.
     78  1.1  apb  *
     79  1.1  apb  * It also handles the case of (COMPAT_50 && COMPAT_NETBSD32).
     80  1.1  apb  */
     81  1.1  apb int
     82  1.1  apb compat_50_rnd_ioctl(struct file *fp, u_long cmd, void *addr)
     83  1.1  apb {
     84  1.1  apb 	int ret = 0;
     85  1.1  apb 
     86  1.1  apb 	switch (cmd) {
     87  1.1  apb 
     88  1.1  apb 	case RNDGETSRCNUM50:
     89  1.1  apb 	{
     90  1.1  apb 		rndstat_t rstbuf = {.start = 0};
     91  1.1  apb 		rndstat50_t *rst50 = (rndstat50_t *)addr;
     92  1.1  apb 		int count;
     93  1.1  apb 
     94  1.1  apb 		if (rst50->count > RND_MAXSTATCOUNT50)
     95  1.1  apb 			return EINVAL;
     96  1.1  apb 
     97  1.1  apb 		rstbuf.start = rst50->start;
     98  1.1  apb 		rstbuf.count = rst50->count;
     99  1.1  apb 
    100  1.1  apb 		ret = (fp->f_ops->fo_ioctl)(fp, RNDGETSRCNUM, &rstbuf);
    101  1.1  apb 		if (ret != 0)
    102  1.1  apb 			return ret;
    103  1.1  apb 
    104  1.1  apb 		for (count = 0; count < rst50->count; count++) {
    105  1.1  apb 			rndsource_to_rndsource50(&rstbuf.source[count],
    106  1.1  apb 			    &rst50->source[count]);
    107  1.1  apb 		}
    108  1.1  apb 		rst50->count = rstbuf.count;
    109  1.1  apb 
    110  1.1  apb 		break;
    111  1.1  apb 	}
    112  1.1  apb 
    113  1.1  apb #ifdef COMPAT_NETBSD32
    114  1.1  apb 	case RNDGETSRCNUM50_32:
    115  1.1  apb 	{
    116  1.1  apb 		rndstat_t rstbuf = {.start = 0};
    117  1.1  apb 		rndstat50_32_t *rst50_32 = (rndstat50_32_t *)addr;
    118  1.1  apb 		int count;
    119  1.1  apb 
    120  1.1  apb 		if (rst50_32->count > RND_MAXSTATCOUNT50)
    121  1.1  apb 			return (EINVAL);
    122  1.1  apb 
    123  1.1  apb 		rstbuf.start = rst50_32->start;
    124  1.1  apb 		rstbuf.count = rst50_32->count;
    125  1.1  apb 
    126  1.1  apb 		ret = (fp->f_ops->fo_ioctl)(fp, RNDGETSRCNUM, &rstbuf);
    127  1.1  apb 		if (ret != 0)
    128  1.1  apb 			return ret;
    129  1.1  apb 
    130  1.1  apb 		for (count = 0; count < rst50_32->count; count++) {
    131  1.1  apb 			rndsource_to_rndsource50_32(&rstbuf.source[count],
    132  1.1  apb 			    &rst50_32->source[count]);
    133  1.1  apb 		}
    134  1.1  apb 		rst50_32->count = rstbuf.count;
    135  1.1  apb 
    136  1.1  apb 		break;
    137  1.1  apb 	}
    138  1.1  apb #endif /* COMPAT_NETBSD32 */
    139  1.1  apb 
    140  1.1  apb 	case RNDGETSRCNAME50:
    141  1.1  apb 	{
    142  1.1  apb 		rndstat_name_t rstnmbuf = {.name[0] = 0};
    143  1.1  apb 		rndstat_name50_t *rstnm50;
    144  1.1  apb 		rstnm50 = (rndstat_name50_t *)addr;
    145  1.1  apb 
    146  1.1  apb 		strlcpy(rstnmbuf.name, rstnm50->name, sizeof(rstnmbuf.name));
    147  1.1  apb 
    148  1.1  apb 		ret = (fp->f_ops->fo_ioctl)(fp, RNDGETSRCNAME, &rstnmbuf);
    149  1.1  apb 		if (ret != 0)
    150  1.1  apb 			return ret;
    151  1.1  apb 
    152  1.1  apb 		rndsource_to_rndsource50(&rstnmbuf.source, &rstnm50->source);
    153  1.1  apb 
    154  1.1  apb 		break;
    155  1.1  apb 	}
    156  1.1  apb 
    157  1.1  apb #ifdef COMPAT_NETBSD32
    158  1.1  apb 	case RNDGETSRCNAME50_32:
    159  1.1  apb 	{
    160  1.1  apb 		rndstat_name_t rstnmbuf = {.name[0] = 0};
    161  1.1  apb 		rndstat_name50_32_t *rstnm50_32;
    162  1.1  apb 		rstnm50_32 = (rndstat_name50_32_t *)addr;
    163  1.1  apb 
    164  1.1  apb 		strlcpy(rstnmbuf.name, rstnm50_32->name, sizeof(rstnmbuf.name));
    165  1.1  apb 
    166  1.1  apb 		ret = (fp->f_ops->fo_ioctl)(fp, RNDGETSRCNAME, &rstnmbuf);
    167  1.1  apb 		if (ret != 0)
    168  1.1  apb 			return ret;
    169  1.1  apb 
    170  1.1  apb 		rndsource_to_rndsource50_32(&rstnmbuf.source,
    171  1.1  apb 		    &rstnm50_32->source);
    172  1.1  apb 
    173  1.1  apb 		break;
    174  1.1  apb 	}
    175  1.1  apb #endif
    176  1.1  apb 
    177  1.1  apb 	default:
    178  1.1  apb 		return ENOTTY;
    179  1.1  apb 	}
    180  1.1  apb 
    181  1.1  apb 	return ret;
    182  1.1  apb }
    183