201 lines
5.3 KiB
C
201 lines
5.3 KiB
C
/* $NetBSD: netbsd32_compat_30.c,v 1.2 2005/08/19 04:24:38 christos Exp $ */
|
|
|
|
/*
|
|
* Copyright (c) 1998, 2001 Matthew R. Green
|
|
* All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the distribution.
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
* derived from this software without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
* SUCH DAMAGE.
|
|
*/
|
|
|
|
#include <sys/cdefs.h>
|
|
__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_30.c,v 1.2 2005/08/19 04:24:38 christos Exp $");
|
|
|
|
#if defined(_KERNEL_OPT)
|
|
#include "opt_ktrace.h"
|
|
#endif
|
|
|
|
#include <sys/param.h>
|
|
#include <sys/systm.h>
|
|
#include <sys/malloc.h>
|
|
#include <sys/mount.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/socketvar.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/time.h>
|
|
#include <sys/ktrace.h>
|
|
#include <sys/resourcevar.h>
|
|
#include <sys/vnode.h>
|
|
#include <sys/file.h>
|
|
#include <sys/filedesc.h>
|
|
#include <sys/namei.h>
|
|
#include <sys/sa.h>
|
|
#include <sys/statvfs.h>
|
|
#include <sys/syscallargs.h>
|
|
#include <sys/proc.h>
|
|
#include <sys/dirent.h>
|
|
|
|
#include <compat/netbsd32/netbsd32.h>
|
|
#include <compat/netbsd32/netbsd32_syscallargs.h>
|
|
#include <compat/netbsd32/netbsd32_conv.h>
|
|
|
|
|
|
int
|
|
netbsd32_getdents(l, v, retval)
|
|
struct lwp *l;
|
|
void *v;
|
|
register_t *retval;
|
|
{
|
|
struct netbsd32_getdents_args /* {
|
|
syscallarg(int) fd;
|
|
syscallarg(netbsd32_charp) buf;
|
|
syscallarg(netbsd32_size_t) count;
|
|
} */ *uap = v;
|
|
struct file *fp;
|
|
int error, done;
|
|
char *buf;
|
|
struct proc *p = l->l_proc;
|
|
|
|
/* getvnode() will use the descriptor for us */
|
|
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
|
|
return (error);
|
|
if ((fp->f_flag & FREAD) == 0) {
|
|
error = EBADF;
|
|
goto out;
|
|
}
|
|
buf = malloc(SCARG(uap, count), M_TEMP, M_WAITOK);
|
|
error = vn_readdir(fp, buf,
|
|
UIO_SYSSPACE, SCARG(uap, count), &done, p, 0, 0);
|
|
if (error == 0) {
|
|
*retval = netbsd32_to_dirent12(buf, done);
|
|
error = copyout(buf, NETBSD32PTR64(SCARG(uap, buf)), *retval);
|
|
}
|
|
free(buf, M_TEMP);
|
|
out:
|
|
FILE_UNUSE(fp, p);
|
|
return (error);
|
|
}
|
|
|
|
int
|
|
netbsd32___stat13(l, v, retval)
|
|
struct lwp *l;
|
|
void *v;
|
|
register_t *retval;
|
|
{
|
|
struct netbsd32___stat13_args /* {
|
|
syscallarg(const netbsd32_charp) path;
|
|
syscallarg(netbsd32_stat13p_t) ub;
|
|
} */ *uap = v;
|
|
struct netbsd32_stat13 sb32;
|
|
struct stat sb;
|
|
int error;
|
|
struct nameidata nd;
|
|
caddr_t sg;
|
|
const char *path;
|
|
struct proc *p = l->l_proc;
|
|
|
|
path = (char *)NETBSD32PTR64(SCARG(uap, path));
|
|
sg = stackgap_init(p, 0);
|
|
CHECK_ALT_EXIST(p, &sg, path);
|
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, path, p);
|
|
if ((error = namei(&nd)) != 0)
|
|
return (error);
|
|
error = vn_stat(nd.ni_vp, &sb, p);
|
|
vput(nd.ni_vp);
|
|
if (error)
|
|
return (error);
|
|
netbsd32_from___stat13(&sb, &sb32);
|
|
error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, ub)),
|
|
sizeof(sb32));
|
|
return (error);
|
|
}
|
|
|
|
int
|
|
netbsd32___fstat13(l, v, retval)
|
|
struct lwp *l;
|
|
void *v;
|
|
register_t *retval;
|
|
{
|
|
struct netbsd32___fstat13_args /* {
|
|
syscallarg(int) fd;
|
|
syscallarg(netbsd32_stat13p_t) sb;
|
|
} */ *uap = v;
|
|
int fd = SCARG(uap, fd);
|
|
struct proc *p = l->l_proc;
|
|
struct filedesc *fdp = p->p_fd;
|
|
struct file *fp;
|
|
struct netbsd32_stat13 sb32;
|
|
struct stat ub;
|
|
int error = 0;
|
|
|
|
if ((fp = fd_getfile(fdp, fd)) == NULL)
|
|
return (EBADF);
|
|
|
|
FILE_USE(fp);
|
|
error = (*fp->f_ops->fo_stat)(fp, &ub, p);
|
|
FILE_UNUSE(fp, p);
|
|
|
|
if (error == 0) {
|
|
netbsd32_from___stat13(&ub, &sb32);
|
|
error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, sb)),
|
|
sizeof(sb32));
|
|
}
|
|
return (error);
|
|
}
|
|
|
|
int
|
|
netbsd32___lstat13(l, v, retval)
|
|
struct lwp *l;
|
|
void *v;
|
|
register_t *retval;
|
|
{
|
|
struct netbsd32___lstat13_args /* {
|
|
syscallarg(const netbsd32_charp) path;
|
|
syscallarg(netbsd32_stat13p_t) ub;
|
|
} */ *uap = v;
|
|
struct netbsd32_stat13 sb32;
|
|
struct stat sb;
|
|
int error;
|
|
struct nameidata nd;
|
|
caddr_t sg;
|
|
const char *path;
|
|
struct proc *p = l->l_proc;
|
|
|
|
path = (char *)NETBSD32PTR64(SCARG(uap, path));
|
|
sg = stackgap_init(p, 0);
|
|
CHECK_ALT_EXIST(p, &sg, path);
|
|
|
|
NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF, UIO_USERSPACE, path, p);
|
|
if ((error = namei(&nd)) != 0)
|
|
return (error);
|
|
error = vn_stat(nd.ni_vp, &sb, p);
|
|
vput(nd.ni_vp);
|
|
if (error)
|
|
return (error);
|
|
netbsd32_from___stat13(&sb, &sb32);
|
|
error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, ub)),
|
|
sizeof(sb32));
|
|
return (error);
|
|
}
|