Added pread and pwrite. These functions are defined by the X/Open

Threads Extension.  (Note: We use the same syscall numbers as NetBSD.)

Submitted by:	John Plevyak <jplevyak@inktomi.com>
This commit is contained in:
Alan Cox 1999-03-27 21:16:58 +00:00
parent cf5f6adf44
commit 4160ccd978
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=45065
8 changed files with 159 additions and 8 deletions

View file

@ -192,8 +192,8 @@ struct sysent sysent[] = {
{ 6, (sy_call_t *)msgsys }, /* 170 = msgsys */
{ 4, (sy_call_t *)shmsys }, /* 171 = shmsys */
{ 0, (sy_call_t *)nosys }, /* 172 = nosys */
{ 0, (sy_call_t *)nosys }, /* 173 = nosys */
{ 0, (sy_call_t *)nosys }, /* 174 = nosys */
{ 5, (sy_call_t *)pread }, /* 173 = pread */
{ 5, (sy_call_t *)pwrite }, /* 174 = pwrite */
{ 0, (sy_call_t *)nosys }, /* 175 = nosys */
{ 1, (sy_call_t *)ntp_adjtime }, /* 176 = ntp_adjtime */
{ 0, (sy_call_t *)nosys }, /* 177 = sfork */

View file

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)sys_generic.c 8.5 (Berkeley) 1/21/94
* $Id: sys_generic.c,v 1.44 1999/01/27 21:49:57 dillon Exp $
* $Id: sys_generic.c,v 1.45 1999/01/29 08:10:35 bde Exp $
*/
#include "opt_ktrace.h"
@ -131,6 +131,70 @@ read(p, uap)
return (error);
}
/*
* pread system call.
*/
#ifndef _SYS_SYSPROTO_H_
struct pread_args {
int fd;
void *buf;
size_t nbyte;
off_t offset;
};
#endif
/* ARGSUSED */
int
pread(p, uap)
struct proc *p;
register struct pread_args *uap;
{
register struct file *fp;
register struct filedesc *fdp = p->p_fd;
struct uio auio;
struct iovec aiov;
long cnt, error = 0;
#ifdef KTRACE
struct iovec ktriov;
#endif
if (((u_int)uap->fd) >= fdp->fd_nfiles ||
(fp = fdp->fd_ofiles[uap->fd]) == NULL ||
(fp->f_flag & FREAD) == 0)
return (EBADF);
if (fp->f_type != DTYPE_VNODE)
return (ESPIPE);
aiov.iov_base = (caddr_t)uap->buf;
aiov.iov_len = uap->nbyte;
auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
auio.uio_offset = uap->offset;
if (uap->nbyte > INT_MAX)
return (EINVAL);
auio.uio_resid = uap->nbyte;
auio.uio_rw = UIO_READ;
auio.uio_segflg = UIO_USERSPACE;
auio.uio_procp = p;
#ifdef KTRACE
/*
* if tracing, save a copy of iovec
*/
if (KTRPOINT(p, KTR_GENIO))
ktriov = aiov;
#endif
cnt = uap->nbyte;
if ((error = (*fp->f_ops->fo_read)(fp, &auio, fp->f_cred)))
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
error = 0;
cnt -= auio.uio_resid;
#ifdef KTRACE
if (KTRPOINT(p, KTR_GENIO) && error == 0)
ktrgenio(p->p_tracep, uap->fd, UIO_READ, &ktriov, cnt, error);
#endif
p->p_retval[0] = cnt;
return (error);
}
/*
* Scatter read system call.
*/
@ -284,6 +348,73 @@ write(p, uap)
return (error);
}
/*
* pwrite system call
*/
#ifndef _SYS_SYSPROTO_H_
struct pwrite_args {
int fd;
const void *buf;
size_t nbyte;
off_t offset;
};
#endif
int
pwrite(p, uap)
struct proc *p;
register struct pwrite_args *uap;
{
register struct file *fp;
register struct filedesc *fdp = p->p_fd;
struct uio auio;
struct iovec aiov;
long cnt, error = 0;
#ifdef KTRACE
struct iovec ktriov;
#endif
if (((u_int)uap->fd) >= fdp->fd_nfiles ||
(fp = fdp->fd_ofiles[uap->fd]) == NULL ||
(fp->f_flag & FWRITE) == 0)
return (EBADF);
if (fp->f_type != DTYPE_VNODE)
return (ESPIPE);
aiov.iov_base = (caddr_t)uap->buf;
aiov.iov_len = uap->nbyte;
auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
auio.uio_offset = uap->offset;
if (uap->nbyte > INT_MAX)
return (EINVAL);
auio.uio_resid = uap->nbyte;
auio.uio_rw = UIO_WRITE;
auio.uio_segflg = UIO_USERSPACE;
auio.uio_procp = p;
#ifdef KTRACE
/*
* if tracing, save a copy of iovec
*/
if (KTRPOINT(p, KTR_GENIO))
ktriov = aiov;
#endif
cnt = uap->nbyte;
if ((error = (*fp->f_ops->fo_write)(fp, &auio, fp->f_cred))) {
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
error = 0;
if (error == EPIPE)
psignal(p, SIGPIPE);
}
cnt -= auio.uio_resid;
#ifdef KTRACE
if (KTRPOINT(p, KTR_GENIO) && error == 0)
ktrgenio(p->p_tracep, uap->fd, UIO_WRITE,
&ktriov, cnt, error);
#endif
p->p_retval[0] = cnt;
return (error);
}
/*
* Gather write system call
*/

View file

@ -179,8 +179,8 @@ char *syscallnames[] = {
"msgsys", /* 170 = msgsys */
"shmsys", /* 171 = shmsys */
"#172", /* 172 = nosys */
"#173", /* 173 = nosys */
"#174", /* 174 = nosys */
"pread", /* 173 = pread */
"pwrite", /* 174 = pwrite */
"#175", /* 175 = nosys */
"ntp_adjtime", /* 176 = ntp_adjtime */
"#177", /* 177 = sfork */

View file

@ -1,4 +1,4 @@
$Id: syscalls.master,v 1.54 1998/11/05 14:28:24 dg Exp $
$Id: syscalls.master,v 1.55 1998/11/11 12:45:14 peter Exp $
; from: @(#)syscalls.master 8.2 (Berkeley) 1/13/94
;
; System call name/number master file.
@ -266,8 +266,8 @@
171 STD BSD { int shmsys(int which, int a2, int a3, int a4); }
; XXX should be { int shmsys(int which, ...); }
172 UNIMPL NOHIDE nosys
173 UNIMPL NOHIDE nosys
174 UNIMPL NOHIDE nosys
173 STD POSIX { ssize_t pread(int fd, void *buf, size_t nbyte, off_t offset); }
174 STD POSIX { ssize_t pwrite(int fd, const void *buf, size_t nbyte, off_t offset); }
175 UNIMPL NOHIDE nosys
176 STD BSD { int ntp_adjtime(struct timex *tp); }
177 UNIMPL NOHIDE sfork (BSD/OS 2.x)

View file

@ -158,6 +158,8 @@ HIDE_BSD(rtprio)
HIDE_BSD(semsys)
HIDE_BSD(msgsys)
HIDE_BSD(shmsys)
HIDE_POSIX(pread)
HIDE_POSIX(pwrite)
HIDE_BSD(ntp_adjtime)
HIDE_POSIX(setgid)
HIDE_BSD(setegid)

View file

@ -166,6 +166,8 @@
#define SYS_semsys 169
#define SYS_msgsys 170
#define SYS_shmsys 171
#define SYS_pread 173
#define SYS_pwrite 174
#define SYS_ntp_adjtime 176
#define SYS_setgid 181
#define SYS_setegid 182

View file

@ -123,6 +123,8 @@ MIASM = \
semsys.o \
msgsys.o \
shmsys.o \
pread.o \
pwrite.o \
ntp_adjtime.o \
setgid.o \
setegid.o \

View file

@ -542,6 +542,18 @@ struct shmsys_args {
int a3; char a3_[PAD_(int)];
int a4; char a4_[PAD_(int)];
};
struct pread_args {
int fd; char fd_[PAD_(int)];
void * buf; char buf_[PAD_(void *)];
size_t nbyte; char nbyte_[PAD_(size_t)];
off_t offset; char offset_[PAD_(off_t)];
};
struct pwrite_args {
int fd; char fd_[PAD_(int)];
const void * buf; char buf_[PAD_(const void *)];
size_t nbyte; char nbyte_[PAD_(size_t)];
off_t offset; char offset_[PAD_(off_t)];
};
struct ntp_adjtime_args {
struct timex * tp; char tp_[PAD_(struct timex *)];
};
@ -1014,6 +1026,8 @@ int rtprio __P((struct proc *, struct rtprio_args *));
int semsys __P((struct proc *, struct semsys_args *));
int msgsys __P((struct proc *, struct msgsys_args *));
int shmsys __P((struct proc *, struct shmsys_args *));
int pread __P((struct proc *, struct pread_args *));
int pwrite __P((struct proc *, struct pwrite_args *));
int ntp_adjtime __P((struct proc *, struct ntp_adjtime_args *));
int setgid __P((struct proc *, struct setgid_args *));
int setegid __P((struct proc *, struct setegid_args *));