[BACK]Return to freebsd_misc.c CVS log [TXT][DIR] Up to [local] / sys / compat / freebsd

Annotation of sys/compat/freebsd/freebsd_misc.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: freebsd_misc.c,v 1.10 2007/04/05 15:33:42 tedu Exp $  */
                      2: /*     $NetBSD: freebsd_misc.c,v 1.2 1996/05/03 17:03:10 christos Exp $        */
                      3:
                      4: /*
                      5:  * Copyright (c) 1995 Frank van der Linden
                      6:  * All rights reserved.
                      7:  *
                      8:  * Redistribution and use in source and binary forms, with or without
                      9:  * modification, are permitted provided that the following conditions
                     10:  * are met:
                     11:  * 1. Redistributions of source code must retain the above copyright
                     12:  *    notice, this list of conditions and the following disclaimer.
                     13:  * 2. Redistributions in binary form must reproduce the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer in the
                     15:  *    documentation and/or other materials provided with the distribution.
                     16:  * 3. All advertising materials mentioning features or use of this software
                     17:  *    must display the following acknowledgement:
                     18:  *      This product includes software developed for the NetBSD Project
                     19:  *      by Frank van der Linden
                     20:  * 4. The name of the author may not be used to endorse or promote products
                     21:  *    derived from this software without specific prior written permission
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     24:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     25:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     26:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     27:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     28:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     29:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     30:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     31:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     32:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
                     33:  */
                     34:
                     35: /*
                     36:  * FreeBSD compatibility module. Try to deal with various FreeBSD system calls.
                     37:  */
                     38:
                     39: #include <sys/param.h>
                     40: #include <sys/systm.h>
                     41: #include <sys/proc.h>
                     42: #include <sys/mount.h>
                     43: #include <sys/file.h>
                     44: #include <sys/dirent.h>
                     45: #include <sys/filedesc.h>
                     46: #include <sys/mman.h>
                     47: #include <sys/vnode.h>
                     48:
                     49: #include <sys/syscallargs.h>
                     50:
                     51: #include <compat/freebsd/freebsd_signal.h>
                     52: #include <compat/freebsd/freebsd_syscallargs.h>
                     53: #include <compat/freebsd/freebsd_util.h>
                     54: #include <compat/freebsd/freebsd_rtprio.h>
                     55:
                     56: #include <compat/common/compat_dir.h>
                     57:
                     58: /* just a place holder */
                     59:
                     60: int
                     61: freebsd_sys_rtprio(p, v, retval)
                     62:        struct proc *p;
                     63:        void *v;
                     64:        register_t *retval;
                     65: {
                     66: #ifdef notyet
                     67:        struct freebsd_sys_rtprio_args /* {
                     68:                syscallarg(int) function;
                     69:                syscallarg(pid_t) pid;
                     70:                syscallarg(struct freebsd_rtprio *) rtp;
                     71:        } */ *uap = v;
                     72: #endif
                     73:
                     74:        return ENOSYS;  /* XXX */
                     75: }
                     76:
                     77: /*
                     78:  * Argh.
                     79:  * The syscalls.master mechanism cannot handle a system call that is in
                     80:  * two spots in the table.
                     81:  */
                     82: int
                     83: freebsd_sys_poll2(p, v, retval)
                     84:        struct proc *p;
                     85:        void *v;
                     86:        register_t *retval;
                     87: {
                     88:        return (sys_poll(p, v, retval));
                     89: }
                     90:
                     91: /*
                     92:  * Our madvise is currently dead (always returns EOPNOTSUPP).
                     93:  */
                     94: int
                     95: freebsd_sys_madvise(p, v, retval)
                     96:        struct proc *p;
                     97:        void *v;
                     98:        register_t *retval;
                     99: {
                    100:        return (0);
                    101: }
                    102:
                    103:
                    104: int freebsd_readdir_callback(void *, struct dirent *, off_t);
                    105:
                    106: struct freebsd_readdir_callback_args {
                    107:        caddr_t outp;
                    108:        int     resid;
                    109: };
                    110:
                    111: int
                    112: freebsd_readdir_callback(void *arg, struct dirent *bdp, off_t cookie)
                    113: {
                    114:        struct freebsd_readdir_callback_args *cb = arg;
                    115:        struct dirent idb;
                    116:        int error;
                    117:
                    118:        if (cb->resid < bdp->d_reclen)
                    119:                return (ENOMEM);
                    120:        idb.d_fileno = bdp->d_fileno;
                    121:        idb.d_reclen = bdp->d_reclen;
                    122:        idb.d_type = bdp->d_type;
                    123:        idb.d_namlen = bdp->d_namlen;
                    124:        strlcpy(idb.d_name, bdp->d_name, sizeof(idb.d_name));
                    125:
                    126:        if ((error = copyout((caddr_t)&idb, cb->outp, bdp->d_reclen)))
                    127:                return (error);
                    128:        cb->outp += bdp->d_reclen;
                    129:        cb->resid -= bdp->d_reclen;
                    130:
                    131:        return (0);
                    132: }
                    133:
                    134: int
                    135: freebsd_sys_getdents(struct proc *p, void *v, register_t *retval)
                    136: {
                    137:        struct freebsd_sys_getdents_args /* {
                    138:                syscallarg(int) fd;
                    139:                syscallarg(void *) dirent;
                    140:                syscallarg(unsigned) count;
                    141:        } */ *uap = v;
                    142:        struct vnode *vp;
                    143:        struct file *fp;
                    144:        int error;
                    145:        struct freebsd_readdir_callback_args args;
                    146:
                    147:        if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
                    148:                return (error);
                    149:
                    150:        vp = (struct vnode *)fp->f_data;
                    151:
                    152:        args.resid = SCARG(uap, count);
                    153:        args.outp = (caddr_t)SCARG(uap, dirent);
                    154:
                    155:        error = readdir_with_callback(fp, &fp->f_offset, args.resid,
                    156:            freebsd_readdir_callback, &args);
                    157:
                    158:        FRELE(fp);
                    159:        if (error)
                    160:                return (error);
                    161:
                    162:        *retval = SCARG(uap, count) - args.resid;
                    163:        return (0);
                    164: }
                    165:
                    166: #define FBSD_MAP_NOCORE        0x20000
                    167: int
                    168: freebsd_sys_mmap(struct proc *p, void *v, register_t *retval)
                    169: {
                    170:        struct freebsd_sys_mmap_args /* {
                    171:                syscallarg(caddr_t) addr;
                    172:                syscallarg(size_t) len;
                    173:                syscallarg(int) prot;
                    174:                syscallarg(int) flags;
                    175:                syscallarg(int) fd;
                    176:                syscallarg(long) pad;
                    177:                syscallarg(off_t) pos;
                    178:        } */ *uap = v;
                    179:        SCARG(uap, flags) &= ~FBSD_MAP_NOCORE;
                    180:        return (sys_mmap(p, uap, retval));
                    181: }

CVSweb