From bdad86fd0c829df918370acdf09006f531e3ff18 Mon Sep 17 00:00:00 2001 From: thorpej Date: Tue, 30 Jun 1998 19:46:00 +0000 Subject: [PATCH] Add pread(2), pwrite(2), preadv(2), pwritev(2) system calls. --- lib/libc/shlib_version | 4 +-- lib/libc/sys/Makefile.inc | 12 ++++---- lib/libc/sys/read.2 | 61 ++++++++++++++++++++++++++++++++++----- lib/libc/sys/write.2 | 55 +++++++++++++++++++++++++++++++---- 4 files changed, 112 insertions(+), 20 deletions(-) diff --git a/lib/libc/shlib_version b/lib/libc/shlib_version index 83c1a2dc3861..b66904b88560 100644 --- a/lib/libc/shlib_version +++ b/lib/libc/shlib_version @@ -1,4 +1,4 @@ -# $NetBSD: shlib_version,v 1.55 1998/06/27 21:23:28 christos Exp $ +# $NetBSD: shlib_version,v 1.56 1998/06/30 19:46:00 thorpej Exp $ # major=12 -minor=28 +minor=29 diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 4d3661a6207f..bd0602842d8c 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.84 1998/06/27 21:22:56 christos Exp $ +# $NetBSD: Makefile.inc,v 1.85 1998/06/30 19:46:01 thorpej Exp $ # @(#)Makefile.inc 8.3 (Berkeley) 10/24/94 # sys sources @@ -46,9 +46,9 @@ ASM= accept.o access.o acct.o adjtime.o bind.o chdir.o chflags.o \ mlock.o mount.o mprotect.o msgctl.o msgget.o msgrcv.o \ msgsnd.o __msync13.o munlock.o munmap.o nanosleep.o \ nfssvc.o ntp_adjtime.o ntp_gettime.o open.o pathconf.o \ - poll.o profil.o quotactl.o read.o readlink.o readv.o \ - reboot.o recvfrom.o recvmsg.o rename.o revoke.o rmdir.o \ - select.o semconfig.o semget.o semop.o sendmsg.o sendto.o \ + poll.o pread.o preadv.o profil.o pwrite.o pwritev.o quotactl.o read.o \ + readlink.o readv.o reboot.o recvfrom.o recvmsg.o rename.o revoke.o \ + rmdir.o select.o semconfig.o semget.o semop.o sendmsg.o sendto.o \ setegid.o seteuid.o setgid.o setgroups.o setitimer.o \ setpgid.o setpriority.o setregid.o setreuid.o setrlimit.o \ setsid.o setsockopt.o settimeofday.o setuid.o shmat.o \ @@ -212,7 +212,7 @@ MLINKS+=lseek.2 seek.2 MLINKS+=mlock.2 munlock.2 MLINKS+=mount.2 unmount.2 MLINKS+=pathconf.2 fpathconf.2 -MLINKS+=read.2 readv.2 +MLINKS+=read.2 readv.2 read.2 pread.2 read.2 preadv.2 MLINKS+=recv.2 recvfrom.2 recv.2 recvmsg.2 MLINKS+=send.2 sendmsg.2 send.2 sendto.2 MLINKS+=setpgid.2 setpgrp.2 @@ -224,4 +224,4 @@ MLINKS+=syscall.2 __syscall.2 MLINKS+=truncate.2 ftruncate.2 MLINKS+=utimes.2 futimes.2 utimes.2 lutimes.2 MLINKS+=wait.2 wait3.2 wait.2 wait4.2 wait.2 waitpid.2 -MLINKS+=write.2 writev.2 +MLINKS+=write.2 writev.2 write.2 pwrite.2 write.2 pwritev.2 diff --git a/lib/libc/sys/read.2 b/lib/libc/sys/read.2 index 46c0559ca052..c9eb9a9ac290 100644 --- a/lib/libc/sys/read.2 +++ b/lib/libc/sys/read.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: read.2,v 1.7 1997/07/14 23:20:10 kleink Exp $ +.\" $NetBSD: read.2,v 1.8 1998/06/30 19:46:01 thorpej Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -38,7 +38,9 @@ .Os BSD 4 .Sh NAME .Nm read , -.Nm readv +.Nm readv , +.Nm pread , +.Nm preadv .Nd read input .Sh SYNOPSIS .Fd #include @@ -48,6 +50,10 @@ .Fn read "int d" "void *buf" "size_t nbytes" .Ft ssize_t .Fn readv "int d" "const struct iovec *iov" "int iovcnt" +.Ft ssize_t +.Fn pread "int d" "void *buf" "size_t nbytes" "off_t offset" +.Ft ssize_t +.Fn preadv "int d" "const struct iovec *iov" "int iovcnt" "off_t offset" .Sh DESCRIPTION .Fn Read attempts to read @@ -63,9 +69,16 @@ into the buffers specified by the members of the .Fa iov array: iov[0], iov[1], ..., iov[iovcnt\|\-\|1]. +.Fn Pread +and +.Fn preadv +perform the same functions, but read from the specified position in +the file without modifying the file pointer. .Pp For -.Fn readv , +.Fn readv +and +.Fn preadv , the .Fa iovec structure is defined as: @@ -101,9 +114,11 @@ position. The value of the pointer associated with such an object is undefined. .Pp Upon successful completion, -.Fn read +.Fn read , +.Fn readv , +.Fn pread , and -.Fn readv +.Fn preadv return the number of bytes actually read and placed in the buffer. The system guarantees to read the number of bytes requested if the descriptor references a normal file that has that many bytes left @@ -117,9 +132,11 @@ Otherwise, a -1 is returned and the global variable .Va errno is set to indicate the error. .Sh ERRORS -.Fn Read +.Fn Read , +.Fn readv , +.Fn pread , and -.Fn readv +.Fn preadv will succeed unless: .Bl -tag -width Er .It Bq Er EBADF @@ -144,6 +161,8 @@ and no data were ready to be read. .Pp In addition, .Fn readv +and +.Fn preadv may return one of the following errors: .Bl -tag -width Er .It Bq Er EINVAL @@ -167,6 +186,18 @@ Part of the .Fa iov points outside the process's allocated address space. .El +.Pp +The +.Fn pread +and +.Fn preadv +calls may also return the following errors: +.Bl -tag -width Er +.It Bq Er EINVAL +The specified file offset is invalid. +.It Bq Er ESPIPE +The file descriptor is associated with a pipe, socket, or FIFO. +.El .Sh SEE ALSO .Xr dup 2 , .Xr fcntl 2 , @@ -180,8 +211,24 @@ The .Fn read function conforms to .St -p1003.1-90 . +The +.Fn readv +and +.Fn pread +functions conform to +.St -xpg4.2 . .Sh HISTORY The +.Fn preadv +function call +appeared in +.Nx 1.4 . +The +.Fn pread +function call +appeared in +.At V.4 . +The .Fn readv function call appeared in diff --git a/lib/libc/sys/write.2 b/lib/libc/sys/write.2 index 3432d46da609..b1499ebe2109 100644 --- a/lib/libc/sys/write.2 +++ b/lib/libc/sys/write.2 @@ -1,4 +1,4 @@ -.\" $NetBSD: write.2,v 1.7 1998/04/28 07:19:29 fair Exp $ +.\" $NetBSD: write.2,v 1.8 1998/06/30 19:46:01 thorpej Exp $ .\" .\" Copyright (c) 1980, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -38,7 +38,9 @@ .Os BSD 4 .Sh NAME .Nm write , -.Nm writev +.Nm writev , +.Nm pwrite , +.Nm pwritev .Nd write output .Sh SYNOPSIS .Fd #include @@ -48,6 +50,10 @@ .Fn write "int d" "const void *buf" "size_t nbytes" .Ft ssize_t .Fn writev "int d" "const struct iovec *iov" "int iovcnt" +.Ft ssize_t +.Fn pwrite "int d" "const void *buf" "size_t nbytes" "off_t offset" +.Ft ssize_t +.Fn pwritev "int d" "const struct iovec *iov" "int iovcnt" "off_t offset" .Sh DESCRIPTION .Fn Write attempts to write @@ -63,9 +69,16 @@ from the buffers specified by the members of the .Fa iov array: iov[0], iov[1], ..., iov[iovcnt\|-\|1]. +.Fn Pwrite +and +.Fn pwritev +perform the same functions, but write to the specified position in +the file without modifying the file pointer. .Pp For -.Fn writev , +.Fn writev +and +.Fn pwritev , the .Fa iovec structure is defined as: @@ -123,9 +136,11 @@ is returned. Otherwise a -1 is returned and the global variable .Va errno is set to indicate the error. .Sh ERRORS -.Fn Write +.Fn Write , +.Fn writev , +.Fn pwrite , and -.Fn writev +.Fn pwritev will fail and the file pointer will remain unchanged if: .Bl -tag -width Er .It Bq Er EBADF @@ -165,6 +180,8 @@ and no data could be written immediately. .Pp In addition, .Fn writev +and +.Fn pwritev may return one of the following errors: .Bl -tag -width Er .It Bq Er EINVAL @@ -184,6 +201,18 @@ values in the .Fa iov array overflowed a 32-bit integer. .El +.Pp +.The +.Fn pwrite +and +.Fn pwritev +calls may also return the following errors: +.Bl -tag -width Er +.It Bq Er EINVAL +The specified file offset is invalid. +.It Bq Er ESPIPE +The file descriptor is associated with a pipe, socket, or FIFO. +.El .Sh SEE ALSO .Xr fcntl 2 , .Xr lseek 2 , @@ -195,7 +224,23 @@ The .Fn write function is expected to conform to .St -p1003.1-88 . +The +.Fn writev +and +.Fn pwrite +functions conform to +.St -xpg4.2 . .Sh HISTORY +the +.Fn pwritev +function call +appeared in +.Nx 1.4 . +The +.Fn pwrite +function call +appeared in +.At V.4 . The .Fn writev function call