Added getdents/ngetdents.

This commit is contained in:
manu 2001-12-23 20:15:03 +00:00
parent 08f29df58c
commit b8f46be2f6
8 changed files with 270 additions and 27 deletions

View File

@ -1,8 +1,9 @@
# $NetBSD: files.irix,v 1.9 2001/12/22 14:43:43 manu Exp $
# $NetBSD: files.irix,v 1.10 2001/12/23 20:15:03 manu Exp $
#
file arch/mips/mips/irix_syscall.c compat_irix
file compat/irix/irix_dirent.c compat_irix
file compat/irix/irix_errno.c compat_irix
file compat/irix/irix_exec.c compat_irix
file compat/irix/irix_exec_elf32.c compat_irix & exec_elf32

View File

@ -0,0 +1,221 @@
/* $NetBSD: irix_dirent.c,v 1.1 2001/12/23 20:15:03 manu Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Christos Zoulas and Emmanuel Dreyfus.
*
* 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. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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: irix_dirent.c,v 1.1 2001/12/23 20:15:03 manu Exp $");
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/param.h>
#include <sys/proc.h>
#include <sys/dirent.h>
#include <sys/fcntl.h>
#include <sys/file.h>
#include <sys/filedesc.h>
#include <sys/mount.h>
#include <sys/malloc.h>
#include <sys/namei.h>
#include <sys/systm.h>
#include <sys/vnode.h>
#include <compat/common/compat_util.h>
#include <compat/irix/irix_types.h>
#include <compat/irix/irix_syscall.h>
#include <compat/irix/irix_syscallargs.h>
/*
* irix_sys_ngetdents() is nearly a plain copy of svr4_sys_getdents(), from
* sys/compat/svr4/svr4_misc.c. We need a custmized version to handle the
* eof flag.
* Obviously the code should be merged, but it would require some
* change to the way COMPAT_SVR4 code is set up.
*/
#define SVR4_RECLEN(de,namlen) ALIGN((SVR4_NAMEOFF(de) + (namlen) + 1))
#define SVR4_NAMEOFF(dp) ((char *)&(dp)->d_name - (char *)dp)
int
irix_sys_ngetdents(p, v, retval)
struct proc *p;
void *v;
register_t *retval;
{
struct irix_sys_ngetdents_args /* {
syscallarg(int) fildes;
syscallarg(irix_dirent_t *) buf;
syscallarg(unsigned short) nbyte;
syscallarg(int *) eof;
} */ *uap = v;
struct dirent *bdp;
struct vnode *vp;
caddr_t inp, buf; /* BSD-format */
int len, reclen; /* BSD-format */
caddr_t outp; /* SVR4-format */
int resid, svr4_reclen; /* SVR4-format */
struct file *fp;
struct uio auio;
struct iovec aiov;
struct irix_dirent idb;
off_t off; /* true file offset */
int buflen, error, eofflag;
off_t *cookiebuf = NULL, *cookie;
int ncookies;
/* getvnode() will use the descriptor for us */
if ((error = getvnode(p->p_fd, SCARG(uap, fildes), &fp)) != 0)
return (error);
if ((fp->f_flag & FREAD) == 0) {
error = EBADF;
goto out1;
}
vp = (struct vnode *)fp->f_data;
if (vp->v_type != VDIR) {
error = EINVAL;
goto out1;
}
buflen = min(MAXBSIZE, SCARG(uap, nbyte));
buf = malloc(buflen, M_TEMP, M_WAITOK);
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
off = fp->f_offset;
again:
aiov.iov_base = buf;
aiov.iov_len = buflen;
auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
auio.uio_rw = UIO_READ;
auio.uio_segflg = UIO_SYSSPACE;
auio.uio_procp = p;
auio.uio_resid = buflen;
auio.uio_offset = off;
/*
* First we read into the malloc'ed buffer, then
* we massage it into user space, one record at a time.
*/
error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, &cookiebuf,
&ncookies);
if (error)
goto out;
inp = buf;
outp = (char *)SCARG(uap, buf);
resid = SCARG(uap, nbyte);
if ((len = buflen - auio.uio_resid) == 0)
goto eof;
for (cookie = cookiebuf; len > 0; len -= reclen) {
bdp = (struct dirent *)inp;
reclen = bdp->d_reclen;
if (reclen & 3)
panic("irix_getdents: bad reclen");
off = *cookie++; /* each entry points to the next */
if ((off >> 32) != 0) {
compat_offseterr(vp, "irix_getdents");
error = EINVAL;
goto out;
}
if (bdp->d_fileno == 0) {
inp += reclen; /* it is a hole; squish it out */
continue;
}
svr4_reclen = SVR4_RECLEN(&idb, bdp->d_namlen);
if (reclen > len || resid < svr4_reclen) {
/* entry too big for buffer, so just stop */
outp++;
break;
}
/*
* Massage in place to make a SVR4-shaped dirent (otherwise
* we have to worry about touching user memory outside of
* the copyout() call).
*/
idb.d_ino = (irix_ino_t)bdp->d_fileno;
idb.d_off = (irix_off_t)off;
idb.d_reclen = (u_short)svr4_reclen;
strcpy(idb.d_name, bdp->d_name);
if ((error = copyout((caddr_t)&idb, outp, svr4_reclen)))
goto out;
/* advance past this real entry */
inp += reclen;
/* advance output past SVR4-shaped entry */
outp += svr4_reclen;
resid -= svr4_reclen;
}
/* if we squished out the whole block, try again */
if (outp == (char *)SCARG(uap, buf))
goto again;
fp->f_offset = off; /* update the vnode offset */
eof:
*retval = SCARG(uap, nbyte) - resid;
out:
VOP_UNLOCK(vp, 0);
if (cookiebuf)
free(cookiebuf, M_TEMP);
free(buf, M_TEMP);
out1:
FILE_UNUSE(fp, p);
if (SCARG(uap, eof) != NULL)
error = copyout(&eofflag, SCARG(uap, eof), sizeof(int));
return error;
}
int
irix_sys_getdents(p, v, retval)
struct proc *p;
void *v;
register_t *retval;
{
struct irix_sys_ngetdents_args /* {
syscallarg(int) fildes;
syscallarg(irix_dirent_t *) buf;
syscallarg(unsigned short) nbyte;
syscallarg(int *) eof;
} */ *uap = v;
struct irix_sys_ngetdents_args cup;
SCARG(&cup, fildes) = SCARG(uap, fildes);
SCARG(&cup, buf) = SCARG(uap, buf);
SCARG(&cup, nbyte) = SCARG(uap, nbyte);
SCARG(&cup, eof) = NULL;
return irix_sys_ngetdents(p, (void *)&cup, retval);
}

View File

@ -1,10 +1,10 @@
/* $NetBSD: irix_syscall.h,v 1.11 2001/12/22 14:43:44 manu Exp $ */
/* $NetBSD: irix_syscall.h,v 1.12 2001/12/23 20:15:03 manu Exp $ */
/*
* System call numbers.
*
* DO NOT EDIT-- this file is automatically generated.
* created from NetBSD: syscalls.master,v 1.9 2001/12/22 12:09:21 manu Exp
* created from NetBSD: syscalls.master,v 1.10 2001/12/22 14:43:45 manu Exp
*/
/* syscall: "syscall" ret: "int" args: */
@ -161,7 +161,7 @@
/* syscall: "mkdir" ret: "int" args: "char *" "int" */
#define IRIX_SYS_mkdir 80
/* syscall: "getdents" ret: "int" args: "int" "char *" "int" */
/* syscall: "getdents" ret: "int" args: "int" "irix_dirent_t *" "int" */
#define IRIX_SYS_getdents 81
/* syscall: "sginap" ret: "long" args: "long" */
@ -209,5 +209,8 @@
/* syscall: "getmountid" ret: "int" args: "const char *" "irix_mountid_t *" */
#define IRIX_SYS_getmountid 203
/* syscall: "ngetdents" ret: "int" args: "int" "irix_dirent_t *" "unsigned short" "int *" */
#define IRIX_SYS_ngetdents 207
#define IRIX_SYS_MAXSYSCALL 226
#define IRIX_SYS_NSYSENT 226

View File

@ -1,10 +1,10 @@
/* $NetBSD: irix_syscallargs.h,v 1.11 2001/12/22 14:43:44 manu Exp $ */
/* $NetBSD: irix_syscallargs.h,v 1.12 2001/12/23 20:15:03 manu Exp $ */
/*
* System call argument lists.
*
* DO NOT EDIT-- this file is automatically generated.
* created from NetBSD: syscalls.master,v 1.9 2001/12/22 12:09:21 manu Exp
* created from NetBSD: syscalls.master,v 1.10 2001/12/22 14:43:45 manu Exp
*/
#ifndef _IRIX_SYS__SYSCALLARGS_H_
@ -155,9 +155,9 @@ struct svr4_sys_ulimit_args {
syscallarg(long) newlimit;
};
struct svr4_sys_getdents_args {
syscallarg(int) fd;
syscallarg(char *) buf;
struct irix_sys_getdents_args {
syscallarg(int) fildes;
syscallarg(irix_dirent_t *) buf;
syscallarg(int) nbytes;
};
@ -241,6 +241,13 @@ struct irix_sys_getmountid_args {
syscallarg(irix_mountid_t *) buf;
};
struct irix_sys_ngetdents_args {
syscallarg(int) fildes;
syscallarg(irix_dirent_t *) buf;
syscallarg(unsigned short) nbyte;
syscallarg(int *) eof;
};
/*
* System call prototypes.
*/
@ -301,7 +308,7 @@ int svr4_sys_fcntl(struct proc *, void *, register_t *);
int svr4_sys_ulimit(struct proc *, void *, register_t *);
int sys_rmdir(struct proc *, void *, register_t *);
int sys_mkdir(struct proc *, void *, register_t *);
int svr4_sys_getdents(struct proc *, void *, register_t *);
int irix_sys_getdents(struct proc *, void *, register_t *);
int irix_sys_sginap(struct proc *, void *, register_t *);
int svr4_sys_getmsg(struct proc *, void *, register_t *);
int svr4_sys_putmsg(struct proc *, void *, register_t *);
@ -317,4 +324,5 @@ int svr4_sys_sigpending(struct proc *, void *, register_t *);
int svr4_sys_sigprocmask(struct proc *, void *, register_t *);
int svr4_sys_sigsuspend(struct proc *, void *, register_t *);
int irix_sys_getmountid(struct proc *, void *, register_t *);
int irix_sys_ngetdents(struct proc *, void *, register_t *);
#endif /* _IRIX_SYS__SYSCALLARGS_H_ */

View File

@ -1,14 +1,14 @@
/* $NetBSD: irix_syscalls.c,v 1.11 2001/12/22 14:43:44 manu Exp $ */
/* $NetBSD: irix_syscalls.c,v 1.12 2001/12/23 20:15:03 manu Exp $ */
/*
* System call names.
*
* DO NOT EDIT-- this file is automatically generated.
* created from NetBSD: syscalls.master,v 1.9 2001/12/22 12:09:21 manu Exp
* created from NetBSD: syscalls.master,v 1.10 2001/12/22 14:43:45 manu Exp
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: irix_syscalls.c,v 1.11 2001/12/22 14:43:44 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: irix_syscalls.c,v 1.12 2001/12/23 20:15:03 manu Exp $");
#if defined(_KERNEL_OPT)
#if defined(_KERNEL_OPT)
@ -247,7 +247,7 @@ const char *const irix_syscallnames[] = {
"#204 (unimplemented nsproc)", /* 204 = unimplemented nsproc */
"#205 (unimplemented getdents64)", /* 205 = unimplemented getdents64 */
"#206 (unimplemented dfs_XXX)", /* 206 = unimplemented dfs_XXX */
"#207 (unimplemented ngetdents)", /* 207 = unimplemented ngetdents */
"ngetdents", /* 207 = ngetdents */
"#208 (unimplemented ngetdents64)", /* 208 = unimplemented ngetdents64 */
"#209 (unimplemented)", /* 209 = unimplemented */
"#210 (unimplemented pidsprocsp)", /* 210 = unimplemented pidsprocsp */

View File

@ -1,14 +1,14 @@
/* $NetBSD: irix_sysent.c,v 1.11 2001/12/22 14:43:45 manu Exp $ */
/* $NetBSD: irix_sysent.c,v 1.12 2001/12/23 20:15:04 manu Exp $ */
/*
* System call switch table.
*
* DO NOT EDIT-- this file is automatically generated.
* created from NetBSD: syscalls.master,v 1.9 2001/12/22 12:09:21 manu Exp
* created from NetBSD: syscalls.master,v 1.10 2001/12/22 14:43:45 manu Exp
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: irix_sysent.c,v 1.11 2001/12/22 14:43:45 manu Exp $");
__KERNEL_RCSID(0, "$NetBSD: irix_sysent.c,v 1.12 2001/12/23 20:15:04 manu Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ntp.h"
@ -205,8 +205,8 @@ struct sysent irix_sysent[] = {
sys_rmdir }, /* 79 = rmdir */
{ 2, s(struct sys_mkdir_args), 0,
sys_mkdir }, /* 80 = mkdir */
{ 3, s(struct svr4_sys_getdents_args), 0,
svr4_sys_getdents }, /* 81 = getdents */
{ 3, s(struct irix_sys_getdents_args), 0,
irix_sys_getdents }, /* 81 = getdents */
{ 1, s(struct irix_sys_sginap_args), 0,
irix_sys_sginap }, /* 82 = sginap */
{ 0, 0, 0,
@ -457,8 +457,8 @@ struct sysent irix_sysent[] = {
sys_nosys }, /* 205 = unimplemented getdents64 */
{ 0, 0, 0,
sys_nosys }, /* 206 = unimplemented dfs_XXX */
{ 0, 0, 0,
sys_nosys }, /* 207 = unimplemented ngetdents */
{ 4, s(struct irix_sys_ngetdents_args), 0,
irix_sys_ngetdents }, /* 207 = ngetdents */
{ 0, 0, 0,
sys_nosys }, /* 208 = unimplemented ngetdents64 */
{ 0, 0, 0,

View File

@ -1,4 +1,4 @@
/* $NetBSD: irix_types.h,v 1.6 2001/12/22 14:43:45 manu Exp $ */
/* $NetBSD: irix_types.h,v 1.7 2001/12/23 20:15:04 manu Exp $ */
/*-
* Copyright (c) 2001 The NetBSD Foundation, Inc.
@ -55,7 +55,7 @@ typedef __int32_t irix_app32_long_t;
typedef __uint64_t irix_app32_ulong_long_t;
typedef __int64_t irix_app32_long_long_t;
typedef __uint32_t irix_ino_t;
typedef __int64_t irix_off_t;
typedef __int32_t irix_off_t;
#if 1 /* _MIPS_SZLONG == 32 */
typedef unsigned long irix_mode_t;
@ -149,4 +149,12 @@ typedef struct irix_mountid {
unsigned int ival[4];
} irix_mountid_t;
/* From IRIX's <sys/dirent.h> */
typedef struct irix_dirent {
irix_ino_t d_ino;
irix_off_t d_off;
unsigned short d_reclen;
char d_name[1];
} irix_dirent_t;
#endif /* _IRIX_TYPES_H_ */

View File

@ -1,4 +1,4 @@
$NetBSD: syscalls.master,v 1.10 2001/12/22 14:43:45 manu Exp $
$NetBSD: syscalls.master,v 1.11 2001/12/23 20:15:04 manu Exp $
; @(#)syscalls.master 8.1 (Berkeley) 7/19/93
@ -156,8 +156,8 @@
78 UNIMPL rfsys
79 NOARGS { int sys_rmdir(char *path); }
80 NOARGS { int sys_mkdir(char *path, int mode); }
81 STD { int svr4_sys_getdents(int fd, char *buf, \
int nbytes); }
81 STD { int irix_sys_getdents(int fildes, \
irix_dirent_t *buf, int nbytes); }
82 STD { long irix_sys_sginap (long ticks); }
83 UNIMPL sgikopt
84 UNIMPL sysfs
@ -298,7 +298,9 @@
204 UNIMPL nsproc
205 UNIMPL getdents64
206 UNIMPL dfs_XXX
207 UNIMPL ngetdents
207 STD { int irix_sys_ngetdents(int fildes, \
irix_dirent_t *buf, unsigned short nbyte, \
int *eof); }
208 UNIMPL ngetdents64
209 UNIMPL
210 UNIMPL pidsprocsp