2004-06-17 22:29:40 +04:00
|
|
|
/* $NetBSD: netbsd32_fs.c,v 1.18 2004/06/17 18:29:40 cube Exp $ */
|
2001-02-08 16:19:33 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 05:07:52 +03:00
|
|
|
#include <sys/cdefs.h>
|
2004-06-17 22:29:40 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: netbsd32_fs.c,v 1.18 2004/06/17 18:29:40 cube Exp $");
|
2001-11-13 05:07:52 +03:00
|
|
|
|
2001-05-30 15:37:21 +04:00
|
|
|
#if defined(_KERNEL_OPT)
|
2001-02-08 16:19:33 +03:00
|
|
|
#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>
|
2003-01-18 11:28:25 +03:00
|
|
|
#include <sys/sa.h>
|
2004-06-17 22:29:40 +04:00
|
|
|
#include <sys/statvfs.h>
|
2001-02-08 16:19:33 +03:00
|
|
|
#include <sys/syscallargs.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
|
|
|
#include <compat/netbsd32/netbsd32.h>
|
|
|
|
#include <compat/netbsd32/netbsd32_syscallargs.h>
|
|
|
|
#include <compat/netbsd32/netbsd32_conv.h>
|
|
|
|
|
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
static int dofilereadv32 __P((struct proc *, int, struct file *, struct netbsd32_iovec *,
|
2001-02-08 16:19:33 +03:00
|
|
|
int, off_t *, int, register_t *));
|
2003-06-30 02:28:00 +04:00
|
|
|
static int dofilewritev32 __P((struct proc *, int, struct file *, struct netbsd32_iovec *,
|
2001-02-08 16:19:33 +03:00
|
|
|
int, off_t *, int, register_t *));
|
2003-06-30 02:28:00 +04:00
|
|
|
static int change_utimes32 __P((struct vnode *, netbsd32_timevalp_t, struct proc *));
|
2001-02-08 16:19:33 +03:00
|
|
|
|
|
|
|
int
|
2003-01-18 11:28:25 +03:00
|
|
|
netbsd32_readv(l, v, retval)
|
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct netbsd32_readv_args /* {
|
|
|
|
syscallarg(int) fd;
|
|
|
|
syscallarg(const netbsd32_iovecp_t) iovp;
|
|
|
|
syscallarg(int) iovcnt;
|
|
|
|
} */ *uap = v;
|
|
|
|
int fd = SCARG(uap, fd);
|
2003-01-18 11:28:25 +03:00
|
|
|
struct proc *p = l->l_proc;
|
2001-02-08 16:19:33 +03:00
|
|
|
struct file *fp;
|
|
|
|
struct filedesc *fdp = p->p_fd;
|
|
|
|
|
2001-06-15 00:32:41 +04:00
|
|
|
if ((fp = fd_getfile(fdp, fd)) == NULL)
|
|
|
|
return (EBADF);
|
|
|
|
|
|
|
|
if ((fp->f_flag & FREAD) == 0)
|
2001-02-08 16:19:33 +03:00
|
|
|
return (EBADF);
|
|
|
|
|
2002-03-24 18:19:24 +03:00
|
|
|
FILE_USE(fp);
|
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
return (dofilereadv32(p, fd, fp,
|
2002-10-23 17:16:38 +04:00
|
|
|
(struct netbsd32_iovec *)NETBSD32PTR64(SCARG(uap, iovp)),
|
|
|
|
SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
|
2001-02-08 16:19:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Damn thing copies in the iovec! */
|
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
dofilereadv32(p, fd, fp, iovp, iovcnt, offset, flags, retval)
|
|
|
|
struct proc *p;
|
2001-02-08 16:19:33 +03:00
|
|
|
int fd;
|
|
|
|
struct file *fp;
|
|
|
|
struct netbsd32_iovec *iovp;
|
|
|
|
int iovcnt;
|
|
|
|
off_t *offset;
|
|
|
|
int flags;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct uio auio;
|
|
|
|
struct iovec *iov;
|
|
|
|
struct iovec *needfree;
|
|
|
|
struct iovec aiov[UIO_SMALLIOV];
|
|
|
|
long i, cnt, error = 0;
|
|
|
|
u_int iovlen;
|
|
|
|
#ifdef KTRACE
|
|
|
|
struct iovec *ktriov = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* note: can't use iovlen until iovcnt is validated */
|
|
|
|
iovlen = iovcnt * sizeof(struct iovec);
|
|
|
|
if ((u_int)iovcnt > UIO_SMALLIOV) {
|
2002-03-24 18:19:24 +03:00
|
|
|
if ((u_int)iovcnt > IOV_MAX) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
iov = malloc(iovlen, M_IOV, M_WAITOK);
|
2001-02-08 16:19:33 +03:00
|
|
|
needfree = iov;
|
|
|
|
} else if ((u_int)iovcnt > 0) {
|
|
|
|
iov = aiov;
|
|
|
|
needfree = NULL;
|
2002-03-24 18:19:24 +03:00
|
|
|
} else {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-02-08 16:19:33 +03:00
|
|
|
|
|
|
|
auio.uio_iov = iov;
|
|
|
|
auio.uio_iovcnt = iovcnt;
|
|
|
|
auio.uio_rw = UIO_READ;
|
|
|
|
auio.uio_segflg = UIO_USERSPACE;
|
2003-06-30 02:28:00 +04:00
|
|
|
auio.uio_procp = p;
|
2001-02-08 16:19:33 +03:00
|
|
|
error = netbsd32_to_iovecin(iovp, iov, iovcnt);
|
|
|
|
if (error)
|
|
|
|
goto done;
|
|
|
|
auio.uio_resid = 0;
|
|
|
|
for (i = 0; i < iovcnt; i++) {
|
|
|
|
auio.uio_resid += iov->iov_len;
|
|
|
|
/*
|
|
|
|
* Reads return ssize_t because -1 is returned on error.
|
|
|
|
* Therefore we must restrict the length to SSIZE_MAX to
|
|
|
|
* avoid garbage return values.
|
|
|
|
*/
|
|
|
|
if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
iov++;
|
|
|
|
}
|
|
|
|
#ifdef KTRACE
|
|
|
|
/*
|
|
|
|
* if tracing, save a copy of iovec
|
|
|
|
*/
|
2003-06-30 02:28:00 +04:00
|
|
|
if (KTRPOINT(p, KTR_GENIO)) {
|
2002-03-24 18:19:24 +03:00
|
|
|
ktriov = malloc(iovlen, M_TEMP, M_WAITOK);
|
2001-02-08 16:19:33 +03:00
|
|
|
memcpy((caddr_t)ktriov, (caddr_t)auio.uio_iov, iovlen);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
cnt = auio.uio_resid;
|
|
|
|
error = (*fp->f_ops->fo_read)(fp, offset, &auio, fp->f_cred, flags);
|
|
|
|
if (error)
|
|
|
|
if (auio.uio_resid != cnt && (error == ERESTART ||
|
|
|
|
error == EINTR || error == EWOULDBLOCK))
|
|
|
|
error = 0;
|
|
|
|
cnt -= auio.uio_resid;
|
|
|
|
#ifdef KTRACE
|
2003-06-30 02:28:00 +04:00
|
|
|
if (KTRPOINT(p, KTR_GENIO))
|
2001-02-08 16:19:33 +03:00
|
|
|
if (error == 0) {
|
2003-06-30 02:28:00 +04:00
|
|
|
ktrgenio(p, fd, UIO_READ, ktriov, cnt,
|
2001-02-08 16:19:33 +03:00
|
|
|
error);
|
2002-03-24 18:19:24 +03:00
|
|
|
free(ktriov, M_TEMP);
|
2001-02-08 16:19:33 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
*retval = cnt;
|
|
|
|
done:
|
|
|
|
if (needfree)
|
2002-03-24 18:19:24 +03:00
|
|
|
free(needfree, M_IOV);
|
|
|
|
out:
|
2003-06-30 02:28:00 +04:00
|
|
|
FILE_UNUSE(fp, p);
|
2001-02-08 16:19:33 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-01-18 11:28:25 +03:00
|
|
|
netbsd32_writev(l, v, retval)
|
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct netbsd32_writev_args /* {
|
|
|
|
syscallarg(int) fd;
|
|
|
|
syscallarg(const netbsd32_iovecp_t) iovp;
|
|
|
|
syscallarg(int) iovcnt;
|
|
|
|
} */ *uap = v;
|
|
|
|
int fd = SCARG(uap, fd);
|
|
|
|
struct file *fp;
|
2003-01-18 11:28:25 +03:00
|
|
|
struct proc *p = l->l_proc;
|
2001-02-08 16:19:33 +03:00
|
|
|
struct filedesc *fdp = p->p_fd;
|
|
|
|
|
2001-06-15 00:32:41 +04:00
|
|
|
if ((fp = fd_getfile(fdp, fd)) == NULL)
|
|
|
|
return (EBADF);
|
|
|
|
|
|
|
|
if ((fp->f_flag & FWRITE) == 0)
|
2001-02-08 16:19:33 +03:00
|
|
|
return (EBADF);
|
|
|
|
|
2002-03-24 18:19:24 +03:00
|
|
|
FILE_USE(fp);
|
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
return (dofilewritev32(p, fd, fp,
|
2002-10-23 17:16:38 +04:00
|
|
|
(struct netbsd32_iovec *)NETBSD32PTR64(SCARG(uap, iovp)),
|
|
|
|
SCARG(uap, iovcnt), &fp->f_offset, FOF_UPDATE_OFFSET, retval));
|
2001-02-08 16:19:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
dofilewritev32(p, fd, fp, iovp, iovcnt, offset, flags, retval)
|
|
|
|
struct proc *p;
|
2001-02-08 16:19:33 +03:00
|
|
|
int fd;
|
|
|
|
struct file *fp;
|
|
|
|
struct netbsd32_iovec *iovp;
|
|
|
|
int iovcnt;
|
|
|
|
off_t *offset;
|
|
|
|
int flags;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct uio auio;
|
|
|
|
struct iovec *iov;
|
|
|
|
struct iovec *needfree;
|
|
|
|
struct iovec aiov[UIO_SMALLIOV];
|
|
|
|
long i, cnt, error = 0;
|
|
|
|
u_int iovlen;
|
|
|
|
#ifdef KTRACE
|
|
|
|
struct iovec *ktriov = NULL;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* note: can't use iovlen until iovcnt is validated */
|
|
|
|
iovlen = iovcnt * sizeof(struct iovec);
|
|
|
|
if ((u_int)iovcnt > UIO_SMALLIOV) {
|
2002-03-24 18:19:24 +03:00
|
|
|
if ((u_int)iovcnt > IOV_MAX) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
iov = malloc(iovlen, M_IOV, M_WAITOK);
|
2001-02-08 16:19:33 +03:00
|
|
|
needfree = iov;
|
|
|
|
} else if ((u_int)iovcnt > 0) {
|
|
|
|
iov = aiov;
|
|
|
|
needfree = NULL;
|
2002-03-24 18:19:24 +03:00
|
|
|
} else {
|
|
|
|
error = EINVAL;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-02-08 16:19:33 +03:00
|
|
|
|
|
|
|
auio.uio_iov = iov;
|
|
|
|
auio.uio_iovcnt = iovcnt;
|
|
|
|
auio.uio_rw = UIO_WRITE;
|
|
|
|
auio.uio_segflg = UIO_USERSPACE;
|
2003-06-30 02:28:00 +04:00
|
|
|
auio.uio_procp = p;
|
2001-02-08 16:19:33 +03:00
|
|
|
error = netbsd32_to_iovecin(iovp, iov, iovcnt);
|
|
|
|
if (error)
|
|
|
|
goto done;
|
|
|
|
auio.uio_resid = 0;
|
|
|
|
for (i = 0; i < iovcnt; i++) {
|
|
|
|
auio.uio_resid += iov->iov_len;
|
|
|
|
/*
|
|
|
|
* Writes return ssize_t because -1 is returned on error.
|
|
|
|
* Therefore we must restrict the length to SSIZE_MAX to
|
|
|
|
* avoid garbage return values.
|
|
|
|
*/
|
|
|
|
if (iov->iov_len > SSIZE_MAX || auio.uio_resid > SSIZE_MAX) {
|
|
|
|
error = EINVAL;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
iov++;
|
|
|
|
}
|
|
|
|
#ifdef KTRACE
|
|
|
|
/*
|
|
|
|
* if tracing, save a copy of iovec
|
|
|
|
*/
|
2003-06-30 02:28:00 +04:00
|
|
|
if (KTRPOINT(p, KTR_GENIO)) {
|
2002-03-24 18:19:24 +03:00
|
|
|
ktriov = malloc(iovlen, M_TEMP, M_WAITOK);
|
2001-02-08 16:19:33 +03:00
|
|
|
memcpy((caddr_t)ktriov, (caddr_t)auio.uio_iov, iovlen);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
cnt = auio.uio_resid;
|
|
|
|
error = (*fp->f_ops->fo_write)(fp, offset, &auio, fp->f_cred, flags);
|
|
|
|
if (error) {
|
|
|
|
if (auio.uio_resid != cnt && (error == ERESTART ||
|
|
|
|
error == EINTR || error == EWOULDBLOCK))
|
|
|
|
error = 0;
|
|
|
|
if (error == EPIPE)
|
2003-06-30 02:28:00 +04:00
|
|
|
psignal(p, SIGPIPE);
|
2001-02-08 16:19:33 +03:00
|
|
|
}
|
|
|
|
cnt -= auio.uio_resid;
|
|
|
|
#ifdef KTRACE
|
2003-06-30 02:28:00 +04:00
|
|
|
if (KTRPOINT(p, KTR_GENIO))
|
2001-02-08 16:19:33 +03:00
|
|
|
if (error == 0) {
|
2003-06-30 02:28:00 +04:00
|
|
|
ktrgenio(p, fd, UIO_WRITE, ktriov, cnt,
|
2001-02-08 16:19:33 +03:00
|
|
|
error);
|
2002-03-24 18:19:24 +03:00
|
|
|
free(ktriov, M_TEMP);
|
2001-02-08 16:19:33 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
*retval = cnt;
|
|
|
|
done:
|
|
|
|
if (needfree)
|
2002-03-24 18:19:24 +03:00
|
|
|
free(needfree, M_IOV);
|
|
|
|
out:
|
2003-06-30 02:28:00 +04:00
|
|
|
FILE_UNUSE(fp, p);
|
2001-02-08 16:19:33 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-01-18 11:28:25 +03:00
|
|
|
netbsd32_utimes(l, v, retval)
|
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct netbsd32_utimes_args /* {
|
|
|
|
syscallarg(const netbsd32_charp) path;
|
|
|
|
syscallarg(const netbsd32_timevalp_t) tptr;
|
|
|
|
} */ *uap = v;
|
|
|
|
int error;
|
|
|
|
struct nameidata nd;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p = l->l_proc;
|
2001-02-08 16:19:33 +03:00
|
|
|
|
2002-10-23 17:16:38 +04:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE,
|
2003-06-30 02:28:00 +04:00
|
|
|
(char *)NETBSD32PTR64(SCARG(uap, path)), p);
|
2001-02-08 16:19:33 +03:00
|
|
|
if ((error = namei(&nd)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
error = change_utimes32(nd.ni_vp, SCARG(uap, tptr), p);
|
2001-02-08 16:19:33 +03:00
|
|
|
|
|
|
|
vrele(nd.ni_vp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common routine to set access and modification times given a vnode.
|
|
|
|
*/
|
|
|
|
static int
|
2003-06-30 02:28:00 +04:00
|
|
|
change_utimes32(vp, tptr, p)
|
2001-02-08 16:19:33 +03:00
|
|
|
struct vnode *vp;
|
|
|
|
netbsd32_timevalp_t tptr;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p;
|
2001-02-08 16:19:33 +03:00
|
|
|
{
|
|
|
|
struct netbsd32_timeval tv32[2];
|
|
|
|
struct timeval tv[2];
|
|
|
|
struct vattr vattr;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
VATTR_NULL(&vattr);
|
2003-10-21 05:20:12 +04:00
|
|
|
if (tptr == 0) {
|
2001-02-08 16:19:33 +03:00
|
|
|
microtime(&tv[0]);
|
|
|
|
tv[1] = tv[0];
|
|
|
|
vattr.va_vaflags |= VA_UTIMES_NULL;
|
|
|
|
} else {
|
2002-10-23 17:16:38 +04:00
|
|
|
error = copyin((caddr_t)NETBSD32PTR64(tptr), tv32,
|
|
|
|
sizeof(tv32));
|
2001-02-08 16:19:33 +03:00
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
netbsd32_to_timeval(&tv32[0], &tv[0]);
|
|
|
|
netbsd32_to_timeval(&tv32[1], &tv[1]);
|
|
|
|
}
|
2003-06-30 02:28:00 +04:00
|
|
|
VOP_LEASE(vp, p, p->p_ucred, LEASE_WRITE);
|
2001-02-08 16:19:33 +03:00
|
|
|
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
|
|
|
|
vattr.va_atime.tv_sec = tv[0].tv_sec;
|
|
|
|
vattr.va_atime.tv_nsec = tv[0].tv_usec * 1000;
|
|
|
|
vattr.va_mtime.tv_sec = tv[1].tv_sec;
|
|
|
|
vattr.va_mtime.tv_nsec = tv[1].tv_usec * 1000;
|
2003-06-30 02:28:00 +04:00
|
|
|
error = VOP_SETATTR(vp, &vattr, p->p_ucred, p);
|
2001-02-08 16:19:33 +03:00
|
|
|
VOP_UNLOCK(vp, 0);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-06-17 22:29:40 +04:00
|
|
|
netbsd32_statvfs1(l, v, retval)
|
2003-01-18 11:28:25 +03:00
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
2004-06-17 22:29:40 +04:00
|
|
|
struct netbsd32_statvfs1_args /* {
|
2001-02-08 16:19:33 +03:00
|
|
|
syscallarg(const netbsd32_charp) path;
|
2004-06-17 22:29:40 +04:00
|
|
|
syscallarg(netbsd32_statvfsp_t) buf;
|
|
|
|
syscallarg(int) flags;
|
2001-02-08 16:19:33 +03:00
|
|
|
} */ *uap = v;
|
2004-06-17 22:29:40 +04:00
|
|
|
struct proc *p = l->l_proc;
|
2001-02-08 16:19:33 +03:00
|
|
|
struct mount *mp;
|
2004-06-17 22:29:40 +04:00
|
|
|
struct statvfs *sbuf;
|
|
|
|
struct netbsd32_statvfs *s32;
|
2001-02-08 16:19:33 +03:00
|
|
|
struct nameidata nd;
|
2004-06-17 22:29:40 +04:00
|
|
|
int error;
|
2001-02-08 16:19:33 +03:00
|
|
|
|
2002-10-23 17:16:38 +04:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE,
|
2003-06-30 02:28:00 +04:00
|
|
|
(char *)NETBSD32PTR64(SCARG(uap, path)), p);
|
2001-02-08 16:19:33 +03:00
|
|
|
if ((error = namei(&nd)) != 0)
|
|
|
|
return (error);
|
2004-06-17 22:29:40 +04:00
|
|
|
/* Allocating on the stack would blow it up */
|
|
|
|
sbuf = (struct statvfs *)malloc(sizeof(struct statvfs), M_TEMP,
|
|
|
|
M_WAITOK);
|
2001-02-08 16:19:33 +03:00
|
|
|
mp = nd.ni_vp->v_mount;
|
|
|
|
vrele(nd.ni_vp);
|
2004-06-17 22:29:40 +04:00
|
|
|
if ((error = dostatvfs(mp, sbuf, p, SCARG(uap, flags), 1)) != 0)
|
|
|
|
goto out;
|
|
|
|
s32 = (struct netbsd32_statvfs *)
|
|
|
|
malloc(sizeof(struct netbsd32_statvfs), M_TEMP, M_WAITOK);
|
|
|
|
netbsd32_from_statvfs(sbuf, s32);
|
|
|
|
error = copyout(s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
|
|
|
|
sizeof(struct netbsd32_statvfs));
|
|
|
|
free(s32, M_TEMP);
|
|
|
|
out:
|
|
|
|
free(sbuf, M_TEMP);
|
|
|
|
return (error);
|
2001-02-08 16:19:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-06-17 22:29:40 +04:00
|
|
|
netbsd32_fstatvfs1(l, v, retval)
|
2003-01-18 11:28:25 +03:00
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
2004-06-17 22:29:40 +04:00
|
|
|
struct netbsd32_fstatvfs1_args /* {
|
2001-02-08 16:19:33 +03:00
|
|
|
syscallarg(int) fd;
|
2004-06-17 22:29:40 +04:00
|
|
|
syscallarg(netbsd32_statvfsp_t) buf;
|
|
|
|
syscallarg(int) flags;
|
2001-02-08 16:19:33 +03:00
|
|
|
} */ *uap = v;
|
2004-06-17 22:29:40 +04:00
|
|
|
struct proc *p = l->l_proc;
|
2001-02-08 16:19:33 +03:00
|
|
|
struct file *fp;
|
|
|
|
struct mount *mp;
|
2004-06-17 22:29:40 +04:00
|
|
|
struct statvfs *sbuf;
|
|
|
|
struct netbsd32_statvfs *s32;
|
2001-02-08 16:19:33 +03:00
|
|
|
int error;
|
|
|
|
|
|
|
|
/* getvnode() will use the descriptor for us */
|
2003-06-30 02:28:00 +04:00
|
|
|
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
|
2001-02-08 16:19:33 +03:00
|
|
|
return (error);
|
|
|
|
mp = ((struct vnode *)fp->f_data)->v_mount;
|
2004-06-17 22:29:40 +04:00
|
|
|
sbuf = (struct statvfs *)malloc(sizeof(struct statvfs), M_TEMP,
|
|
|
|
M_WAITOK);
|
|
|
|
if ((error = dostatvfs(mp, sbuf, p, SCARG(uap, flags), 1)) != 0)
|
2001-02-08 16:19:33 +03:00
|
|
|
goto out;
|
2004-06-17 22:29:40 +04:00
|
|
|
s32 = (struct netbsd32_statvfs *)
|
|
|
|
malloc(sizeof(struct netbsd32_statvfs), M_TEMP, M_WAITOK);
|
|
|
|
netbsd32_from_statvfs(sbuf, s32);
|
|
|
|
error = copyout(s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
|
|
|
|
sizeof(struct netbsd32_statvfs));
|
|
|
|
free(s32, M_TEMP);
|
2001-02-08 16:19:33 +03:00
|
|
|
out:
|
2004-06-17 22:29:40 +04:00
|
|
|
free(sbuf, M_TEMP);
|
2003-06-30 02:28:00 +04:00
|
|
|
FILE_UNUSE(fp, p);
|
2004-06-17 22:29:40 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
netbsd32_getvfsstat(l, v, retval)
|
|
|
|
struct lwp *l;
|
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct netbsd32_getvfsstat_args /* {
|
|
|
|
syscallarg(netbsd32_statvfsp_t) buf;
|
|
|
|
syscallarg(netbsd32_size_t) bufsize;
|
|
|
|
syscallarg(int) flags;
|
|
|
|
} */ *uap = v;
|
|
|
|
int root = 0;
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
struct mount *mp, *nmp;
|
|
|
|
struct statvfs *sbuf;
|
|
|
|
struct netbsd32_statvfs *sfsp;
|
|
|
|
struct netbsd32_statvfs *s32;
|
|
|
|
size_t count, maxcount;
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
maxcount = SCARG(uap, bufsize) / sizeof(struct netbsd32_statvfs);
|
|
|
|
sfsp = (struct netbsd32_statvfs *)NETBSD32PTR64(SCARG(uap, buf));
|
|
|
|
simple_lock(&mountlist_slock);
|
|
|
|
count = 0;
|
|
|
|
sbuf = (struct statvfs *)malloc(sizeof(struct statvfs), M_TEMP,
|
|
|
|
M_WAITOK);
|
|
|
|
s32 = (struct netbsd32_statvfs *)
|
|
|
|
malloc(sizeof(struct netbsd32_statvfs), M_TEMP, M_WAITOK);
|
|
|
|
for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist;
|
|
|
|
mp = nmp) {
|
|
|
|
if (vfs_busy(mp, LK_NOWAIT, &mountlist_slock)) {
|
|
|
|
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (sfsp && count < maxcount) {
|
|
|
|
error = dostatvfs(mp, sbuf, p, SCARG(uap, flags), 0);
|
|
|
|
if (error) {
|
|
|
|
simple_lock(&mountlist_slock);
|
|
|
|
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
|
|
|
vfs_unbusy(mp);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
netbsd32_from_statvfs(sbuf, s32);
|
|
|
|
error = copyout(s32, sfsp, sizeof(*sfsp));
|
|
|
|
if (error) {
|
|
|
|
vfs_unbusy(mp);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
sfsp++;
|
|
|
|
root |= strcmp(sbuf->f_mntonname, "/") == 0;
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
simple_lock(&mountlist_slock);
|
|
|
|
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
|
|
|
vfs_unbusy(mp);
|
|
|
|
}
|
|
|
|
simple_unlock(&mountlist_slock);
|
|
|
|
if (root == 0 && p->p_cwdi->cwdi_rdir) {
|
|
|
|
/*
|
|
|
|
* fake a root entry
|
|
|
|
*/
|
|
|
|
if ((error = dostatvfs(p->p_cwdi->cwdi_rdir->v_mount, sbuf, p,
|
|
|
|
SCARG(uap, flags), 1)) != 0)
|
|
|
|
goto out;
|
|
|
|
if (sfsp) {
|
|
|
|
netbsd32_from_statvfs(sbuf, s32);
|
|
|
|
error = copyout(s32, sfsp, sizeof(*sfsp));
|
|
|
|
}
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
if (sfsp && count > maxcount)
|
|
|
|
*retval = maxcount;
|
|
|
|
else
|
|
|
|
*retval = count;
|
|
|
|
|
|
|
|
out:
|
|
|
|
free(s32, M_TEMP);
|
|
|
|
free(sbuf, M_TEMP);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
netbsd32_fhstatvfs1(l, v, retval)
|
|
|
|
struct lwp *l;
|
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct netbsd32_fhstatvfs1_args /* {
|
|
|
|
syscallarg(const netbsd32_fhandlep_t) fhp;
|
|
|
|
syscallarg(netbsd32_statvfsp_t) buf;
|
|
|
|
syscallarg(int) flags;
|
|
|
|
} */ *uap = v;
|
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
struct statvfs *sbuf;
|
|
|
|
struct netbsd32_statvfs *s32;
|
|
|
|
fhandle_t fh;
|
|
|
|
struct mount *mp;
|
|
|
|
struct vnode *vp;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Must be super user
|
|
|
|
*/
|
|
|
|
if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if ((error = copyin((caddr_t)NETBSD32PTR64(SCARG(uap, fhp)), &fh,
|
|
|
|
sizeof(fhandle_t))) != 0)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
if ((mp = vfs_getvfs(&fh.fh_fsid)) == NULL)
|
|
|
|
return ESTALE;
|
|
|
|
if ((error = VFS_FHTOVP(mp, &fh.fh_fid, &vp)))
|
|
|
|
return error;
|
|
|
|
|
|
|
|
sbuf = (struct statvfs *)malloc(sizeof(struct statvfs), M_TEMP,
|
|
|
|
M_WAITOK);
|
|
|
|
mp = vp->v_mount;
|
|
|
|
if ((error = dostatvfs(mp, sbuf, p, SCARG(uap, flags), 1)) != 0) {
|
|
|
|
vput(vp);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
vput(vp);
|
|
|
|
|
|
|
|
s32 = (struct netbsd32_statvfs *)
|
|
|
|
malloc(sizeof(struct netbsd32_statvfs), M_TEMP, M_WAITOK);
|
|
|
|
netbsd32_from_statvfs(sbuf, s32);
|
|
|
|
error = copyout(s32, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
|
|
|
|
sizeof(struct netbsd32_statvfs));
|
|
|
|
free(s32, M_TEMP);
|
|
|
|
|
|
|
|
out:
|
|
|
|
free(sbuf, M_TEMP);
|
2001-02-08 16:19:33 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-01-18 11:28:25 +03:00
|
|
|
netbsd32_futimes(l, v, retval)
|
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct netbsd32_futimes_args /* {
|
|
|
|
syscallarg(int) fd;
|
|
|
|
syscallarg(const netbsd32_timevalp_t) tptr;
|
|
|
|
} */ *uap = v;
|
|
|
|
int error;
|
|
|
|
struct file *fp;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p = l->l_proc;
|
2001-02-08 16:19:33 +03:00
|
|
|
|
|
|
|
/* getvnode() will use the descriptor for us */
|
2003-06-30 02:28:00 +04:00
|
|
|
if ((error = getvnode(p->p_fd, SCARG(uap, fd), &fp)) != 0)
|
2001-02-08 16:19:33 +03:00
|
|
|
return (error);
|
|
|
|
|
|
|
|
error = change_utimes32((struct vnode *)fp->f_data,
|
2003-06-30 02:28:00 +04:00
|
|
|
SCARG(uap, tptr), p);
|
|
|
|
FILE_UNUSE(fp, p);
|
2001-02-08 16:19:33 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-01-18 11:28:25 +03:00
|
|
|
netbsd32_getdents(l, v, retval)
|
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
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;
|
2003-01-18 11:28:25 +03:00
|
|
|
struct proc *p = l->l_proc;
|
2001-02-08 16:19:33 +03:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
}
|
2002-10-23 17:16:38 +04:00
|
|
|
error = vn_readdir(fp, (caddr_t)NETBSD32PTR64(SCARG(uap, buf)),
|
2003-06-30 02:28:00 +04:00
|
|
|
UIO_USERSPACE, SCARG(uap, count), &done, p, 0, 0);
|
2001-02-08 16:19:33 +03:00
|
|
|
*retval = done;
|
|
|
|
out:
|
2003-06-30 02:28:00 +04:00
|
|
|
FILE_UNUSE(fp, p);
|
2001-02-08 16:19:33 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-01-18 11:28:25 +03:00
|
|
|
netbsd32_lutimes(l, v, retval)
|
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct netbsd32_lutimes_args /* {
|
|
|
|
syscallarg(const netbsd32_charp) path;
|
|
|
|
syscallarg(const netbsd32_timevalp_t) tptr;
|
|
|
|
} */ *uap = v;
|
|
|
|
int error;
|
|
|
|
struct nameidata nd;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p = l->l_proc;
|
2001-02-08 16:19:33 +03:00
|
|
|
|
2002-10-23 17:16:38 +04:00
|
|
|
NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE,
|
2003-06-30 02:28:00 +04:00
|
|
|
(caddr_t)NETBSD32PTR64(SCARG(uap, path)), p);
|
2001-02-08 16:19:33 +03:00
|
|
|
if ((error = namei(&nd)) != 0)
|
|
|
|
return (error);
|
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
error = change_utimes32(nd.ni_vp, SCARG(uap, tptr), p);
|
2001-02-08 16:19:33 +03:00
|
|
|
|
|
|
|
vrele(nd.ni_vp);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-01-18 11:28:25 +03:00
|
|
|
netbsd32___stat13(l, v, retval)
|
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct netbsd32___stat13_args /* {
|
|
|
|
syscallarg(const netbsd32_charp) path;
|
|
|
|
syscallarg(netbsd32_statp_t) ub;
|
|
|
|
} */ *uap = v;
|
|
|
|
struct netbsd32_stat sb32;
|
|
|
|
struct stat sb;
|
|
|
|
int error;
|
|
|
|
struct nameidata nd;
|
|
|
|
caddr_t sg;
|
|
|
|
const char *path;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p = l->l_proc;
|
2001-02-08 16:19:33 +03:00
|
|
|
|
2002-10-23 17:16:38 +04:00
|
|
|
path = (char *)NETBSD32PTR64(SCARG(uap, path));
|
2003-06-30 02:28:00 +04:00
|
|
|
sg = stackgap_init(p, 0);
|
|
|
|
CHECK_ALT_EXIST(p, &sg, path);
|
2001-02-08 16:19:33 +03:00
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, path, p);
|
2001-02-08 16:19:33 +03:00
|
|
|
if ((error = namei(&nd)) != 0)
|
|
|
|
return (error);
|
2003-06-30 02:28:00 +04:00
|
|
|
error = vn_stat(nd.ni_vp, &sb, p);
|
2001-02-08 16:19:33 +03:00
|
|
|
vput(nd.ni_vp);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
netbsd32_from___stat13(&sb, &sb32);
|
2002-10-23 17:16:38 +04:00
|
|
|
error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, ub)),
|
|
|
|
sizeof(sb32));
|
2001-02-08 16:19:33 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-01-18 11:28:25 +03:00
|
|
|
netbsd32___fstat13(l, v, retval)
|
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct netbsd32___fstat13_args /* {
|
|
|
|
syscallarg(int) fd;
|
|
|
|
syscallarg(netbsd32_statp_t) sb;
|
|
|
|
} */ *uap = v;
|
|
|
|
int fd = SCARG(uap, fd);
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
struct filedesc *fdp = p->p_fd;
|
2001-02-08 16:19:33 +03:00
|
|
|
struct file *fp;
|
|
|
|
struct netbsd32_stat sb32;
|
|
|
|
struct stat ub;
|
|
|
|
int error = 0;
|
|
|
|
|
2001-06-15 00:32:41 +04:00
|
|
|
if ((fp = fd_getfile(fdp, fd)) == NULL)
|
2001-02-08 16:19:33 +03:00
|
|
|
return (EBADF);
|
|
|
|
|
2001-04-09 13:39:09 +04:00
|
|
|
FILE_USE(fp);
|
2003-06-30 02:28:00 +04:00
|
|
|
error = (*fp->f_ops->fo_stat)(fp, &ub, p);
|
|
|
|
FILE_UNUSE(fp, p);
|
2001-02-08 16:19:33 +03:00
|
|
|
|
|
|
|
if (error == 0) {
|
|
|
|
netbsd32_from___stat13(&ub, &sb32);
|
2002-10-23 17:16:38 +04:00
|
|
|
error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, sb)),
|
|
|
|
sizeof(sb32));
|
2001-02-08 16:19:33 +03:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-01-18 11:28:25 +03:00
|
|
|
netbsd32___lstat13(l, v, retval)
|
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct netbsd32___lstat13_args /* {
|
|
|
|
syscallarg(const netbsd32_charp) path;
|
|
|
|
syscallarg(netbsd32_statp_t) ub;
|
|
|
|
} */ *uap = v;
|
|
|
|
struct netbsd32_stat sb32;
|
|
|
|
struct stat sb;
|
|
|
|
int error;
|
|
|
|
struct nameidata nd;
|
|
|
|
caddr_t sg;
|
|
|
|
const char *path;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p = l->l_proc;
|
2001-02-08 16:19:33 +03:00
|
|
|
|
2002-10-23 17:16:38 +04:00
|
|
|
path = (char *)NETBSD32PTR64(SCARG(uap, path));
|
2003-06-30 02:28:00 +04:00
|
|
|
sg = stackgap_init(p, 0);
|
|
|
|
CHECK_ALT_EXIST(p, &sg, path);
|
2001-02-08 16:19:33 +03:00
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_USERSPACE, path, p);
|
2001-02-08 16:19:33 +03:00
|
|
|
if ((error = namei(&nd)) != 0)
|
|
|
|
return (error);
|
2003-06-30 02:28:00 +04:00
|
|
|
error = vn_stat(nd.ni_vp, &sb, p);
|
2001-02-08 16:19:33 +03:00
|
|
|
vput(nd.ni_vp);
|
|
|
|
if (error)
|
|
|
|
return (error);
|
|
|
|
netbsd32_from___stat13(&sb, &sb32);
|
2002-10-23 17:16:38 +04:00
|
|
|
error = copyout(&sb32, (caddr_t)NETBSD32PTR64(SCARG(uap, ub)),
|
|
|
|
sizeof(sb32));
|
2001-02-08 16:19:33 +03:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-01-18 11:28:25 +03:00
|
|
|
netbsd32_preadv(l, v, retval)
|
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct netbsd32_preadv_args /* {
|
|
|
|
syscallarg(int) fd;
|
|
|
|
syscallarg(const netbsd32_iovecp_t) iovp;
|
|
|
|
syscallarg(int) iovcnt;
|
|
|
|
syscallarg(int) pad;
|
|
|
|
syscallarg(off_t) offset;
|
|
|
|
} */ *uap = v;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
struct filedesc *fdp = p->p_fd;
|
2001-02-08 16:19:33 +03:00
|
|
|
struct file *fp;
|
|
|
|
struct vnode *vp;
|
|
|
|
off_t offset;
|
|
|
|
int error, fd = SCARG(uap, fd);
|
|
|
|
|
2001-06-15 00:32:41 +04:00
|
|
|
if ((fp = fd_getfile(fdp, fd)) == NULL)
|
|
|
|
return (EBADF);
|
|
|
|
|
|
|
|
if ((fp->f_flag & FREAD) == 0)
|
2001-02-08 16:19:33 +03:00
|
|
|
return (EBADF);
|
|
|
|
|
2002-03-24 18:19:24 +03:00
|
|
|
FILE_USE(fp);
|
|
|
|
|
2001-02-08 16:19:33 +03:00
|
|
|
vp = (struct vnode *)fp->f_data;
|
2002-03-24 18:19:24 +03:00
|
|
|
if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
|
|
|
|
error = ESPIPE;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-02-08 16:19:33 +03:00
|
|
|
|
|
|
|
offset = SCARG(uap, offset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX This works because no file systems actually
|
|
|
|
* XXX take any action on the seek operation.
|
|
|
|
*/
|
|
|
|
if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
|
2002-03-24 18:19:24 +03:00
|
|
|
goto out;
|
2001-02-08 16:19:33 +03:00
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
return (dofilereadv32(p, fd, fp,
|
2002-10-23 17:16:38 +04:00
|
|
|
(struct netbsd32_iovec *)NETBSD32PTR64(SCARG(uap, iovp)),
|
|
|
|
SCARG(uap, iovcnt), &offset, 0, retval));
|
2002-03-24 18:19:24 +03:00
|
|
|
|
|
|
|
out:
|
2003-06-30 02:28:00 +04:00
|
|
|
FILE_UNUSE(fp, p);
|
2002-03-24 18:19:24 +03:00
|
|
|
return (error);
|
2001-02-08 16:19:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-01-18 11:28:25 +03:00
|
|
|
netbsd32_pwritev(l, v, retval)
|
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct netbsd32_pwritev_args /* {
|
|
|
|
syscallarg(int) fd;
|
|
|
|
syscallarg(const netbsd32_iovecp_t) iovp;
|
|
|
|
syscallarg(int) iovcnt;
|
|
|
|
syscallarg(int) pad;
|
|
|
|
syscallarg(off_t) offset;
|
|
|
|
} */ *uap = v;
|
2003-06-30 02:28:00 +04:00
|
|
|
struct proc *p = l->l_proc;
|
|
|
|
struct filedesc *fdp = p->p_fd;
|
2001-02-08 16:19:33 +03:00
|
|
|
struct file *fp;
|
|
|
|
struct vnode *vp;
|
|
|
|
off_t offset;
|
|
|
|
int error, fd = SCARG(uap, fd);
|
|
|
|
|
2001-06-15 00:32:41 +04:00
|
|
|
if ((fp = fd_getfile(fdp, fd)) == NULL)
|
|
|
|
return (EBADF);
|
|
|
|
|
|
|
|
if ((fp->f_flag & FWRITE) == 0)
|
2001-02-08 16:19:33 +03:00
|
|
|
return (EBADF);
|
|
|
|
|
2002-03-24 18:19:24 +03:00
|
|
|
FILE_USE(fp);
|
|
|
|
|
2001-02-08 16:19:33 +03:00
|
|
|
vp = (struct vnode *)fp->f_data;
|
2002-03-24 18:19:24 +03:00
|
|
|
if (fp->f_type != DTYPE_VNODE || vp->v_type == VFIFO) {
|
|
|
|
error = ESPIPE;
|
|
|
|
goto out;
|
|
|
|
}
|
2001-02-08 16:19:33 +03:00
|
|
|
|
|
|
|
offset = SCARG(uap, offset);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX This works because no file systems actually
|
|
|
|
* XXX take any action on the seek operation.
|
|
|
|
*/
|
|
|
|
if ((error = VOP_SEEK(vp, fp->f_offset, offset, fp->f_cred)) != 0)
|
2002-03-24 18:19:24 +03:00
|
|
|
goto out;
|
2001-02-08 16:19:33 +03:00
|
|
|
|
2003-06-30 02:28:00 +04:00
|
|
|
return (dofilewritev32(p, fd, fp,
|
2002-10-23 17:16:38 +04:00
|
|
|
(struct netbsd32_iovec *)NETBSD32PTR64(SCARG(uap, iovp)),
|
|
|
|
SCARG(uap, iovcnt), &offset, 0, retval));
|
2002-03-24 18:19:24 +03:00
|
|
|
|
|
|
|
out:
|
2003-06-30 02:28:00 +04:00
|
|
|
FILE_UNUSE(fp, p);
|
2002-03-24 18:19:24 +03:00
|
|
|
return (error);
|
2001-02-08 16:19:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find pathname of process's current directory.
|
|
|
|
*
|
|
|
|
* Use vfs vnode-to-name reverse cache; if that fails, fall back
|
|
|
|
* to reading directory contents.
|
|
|
|
*/
|
2003-06-30 02:28:00 +04:00
|
|
|
int
|
|
|
|
getcwd_common __P((struct vnode *, struct vnode *,
|
|
|
|
char **, char *, int, int, struct proc *));
|
|
|
|
|
2003-01-18 11:28:25 +03:00
|
|
|
int netbsd32___getcwd(l, v, retval)
|
|
|
|
struct lwp *l;
|
2001-02-08 16:19:33 +03:00
|
|
|
void *v;
|
|
|
|
register_t *retval;
|
|
|
|
{
|
|
|
|
struct netbsd32___getcwd_args /* {
|
|
|
|
syscallarg(char *) bufp;
|
|
|
|
syscallarg(size_t) length;
|
|
|
|
} */ *uap = v;
|
2003-01-18 11:28:25 +03:00
|
|
|
struct proc *p = l->l_proc;
|
2001-02-08 16:19:33 +03:00
|
|
|
int error;
|
|
|
|
char *path;
|
|
|
|
char *bp, *bend;
|
|
|
|
int len = (int)SCARG(uap, length);
|
|
|
|
int lenused;
|
|
|
|
|
|
|
|
if (len > MAXPATHLEN*4)
|
|
|
|
len = MAXPATHLEN*4;
|
|
|
|
else if (len < 2)
|
|
|
|
return ERANGE;
|
|
|
|
|
|
|
|
path = (char *)malloc(len, M_TEMP, M_WAITOK);
|
|
|
|
if (!path)
|
|
|
|
return ENOMEM;
|
|
|
|
|
|
|
|
bp = &path[len];
|
|
|
|
bend = bp;
|
|
|
|
*(--bp) = '\0';
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 5th argument here is "max number of vnodes to traverse".
|
|
|
|
* Since each entry takes up at least 2 bytes in the output buffer,
|
|
|
|
* limit it to N/2 vnodes for an N byte buffer.
|
|
|
|
*/
|
|
|
|
#define GETCWD_CHECK_ACCESS 0x0001
|
|
|
|
error = getcwd_common (p->p_cwdi->cwdi_cdir, NULL, &bp, path, len/2,
|
2003-06-30 02:28:00 +04:00
|
|
|
GETCWD_CHECK_ACCESS, p);
|
2001-02-08 16:19:33 +03:00
|
|
|
|
|
|
|
if (error)
|
|
|
|
goto out;
|
|
|
|
lenused = bend - bp;
|
|
|
|
*retval = lenused;
|
|
|
|
/* put the result into user buffer */
|
2002-10-23 17:16:38 +04:00
|
|
|
error = copyout(bp, (caddr_t)NETBSD32PTR64(SCARG(uap, bufp)), lenused);
|
2001-02-08 16:19:33 +03:00
|
|
|
|
|
|
|
out:
|
|
|
|
free(path, M_TEMP);
|
|
|
|
return error;
|
|
|
|
}
|