summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2005-07-07 18:17:55 +0000
committerjhb <jhb@FreeBSD.org>2005-07-07 18:17:55 +0000
commitcf15cbb1b695b3bfb61d396be49bbf6ea3e889c1 (patch)
treec30d76b42af5454db3e0f1a3a40342b16e62fe4e /lib
parent909e7ff886fb519c878c02fa47955048637cc7e7 (diff)
downloadFreeBSD-src-cf15cbb1b695b3bfb61d396be49bbf6ea3e889c1.zip
FreeBSD-src-cf15cbb1b695b3bfb61d396be49bbf6ea3e889c1.tar.gz
- Add two new system calls: preadv() and pwritev() which are like readv()
and writev() except that they take an additional offset argument and do not change the current file position. In SAT speak: preadv:readv::pread:read and pwritev:writev::pwrite:write. - Try to reduce code duplication some by merging most of the old kern_foov() and dofilefoo() functions into new dofilefoo() functions that are called by kern_foov() and kern_pfoov(). The non-v functions now all generate a simple uio on the stack from the passed in arguments and then call kern_foov(). For example, read() now just builds a uio and calls kern_readv() and pwrite() just builds a uio and calls kern_pwritev(). PR: kern/80362 Submitted by: Marc Olzheim marcolz at stack dot nl (1) Approved by: re (scottl) MFC after: 1 week
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/sys/Makefile.inc4
-rw-r--r--lib/libc/sys/read.233
-rw-r--r--lib/libc/sys/write.227
3 files changed, 48 insertions, 16 deletions
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index 64836b9..53ac26b 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -127,7 +127,7 @@ MLINKS+=mlockall.2 munlockall.2
MLINKS+=modnext.2 modfnext.2
MLINKS+=mount.2 nmount.2 mount.2 unmount.2
MLINKS+=pathconf.2 fpathconf.2
-MLINKS+=read.2 pread.2 read.2 readv.2
+MLINKS+=read.2 pread.2 read.2 readv.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
@@ -141,7 +141,7 @@ MLINKS+=swapon.2 swapoff.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 pwrite.2 write.2 writev.2
+MLINKS+=write.2 pwrite.2 write.2 writev.2 write.2 pwritev.2
.if !defined(NO_P1003_1B)
MLINKS+=sched_get_priority_max.2 sched_get_priority_min.2 \
sched_get_priority_max.2 sched_rr_get_interval.2
diff --git a/lib/libc/sys/read.2 b/lib/libc/sys/read.2
index 8dd7731..fb452e9 100644
--- a/lib/libc/sys/read.2
+++ b/lib/libc/sys/read.2
@@ -38,7 +38,8 @@
.Sh NAME
.Nm read ,
.Nm readv ,
-.Nm pread
+.Nm pread ,
+.Nm preadv
.Nd read input
.Sh LIBRARY
.Lb libc
@@ -49,9 +50,11 @@
.Ft ssize_t
.Fn read "int d" "void *buf" "size_t nbytes"
.Ft ssize_t
+.Fn pread "int d" "void *buf" "size_t nbytes" "off_t offset"
+.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"
+.Fn preadv "int d" "const struct iovec *iov" "int iovcnt" "off_t offset"
.Sh DESCRIPTION
The
.Fn read
@@ -73,12 +76,16 @@ buffers specified by the members of the
array: iov[0], iov[1], ..., iov[iovcnt\|\-\|1].
The
.Fn pread
-system call
-performs the same function, but reads from the specified position in
+and
+.Fn preadv
+system calls
+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:
@@ -119,8 +126,9 @@ object is undefined.
Upon successful completion,
.Fn read ,
.Fn readv ,
-and
.Fn pread
+and
+.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
@@ -137,8 +145,9 @@ is set to indicate the error.
The
.Fn read ,
.Fn readv ,
-and
.Fn pread
+and
+.Fn preadv
system calls
will succeed unless:
.Bl -tag -width Er
@@ -189,6 +198,8 @@ is greater than
.Pp
In addition,
.Fn readv
+and
+.Fn preadv
may return one of the following errors:
.Bl -tag -width Er
.It Bq Er EINVAL
@@ -217,7 +228,9 @@ array points outside the process's allocated address space.
.Pp
The
.Fn pread
-system call may also return the following errors:
+and
+.Fn preadv
+system calls may also return the following errors:
.Bl -tag -width Er
.It Bq Er EINVAL
The
@@ -250,6 +263,10 @@ system calls are expected to conform to
.St -xpg4.2 .
.Sh HISTORY
The
+.Fn preadv
+system call appeared in
+.Fx 6.0 .
+The
.Fn pread
function appeared in
.At V.4 .
diff --git a/lib/libc/sys/write.2 b/lib/libc/sys/write.2
index 7a7cd79..050e2a0 100644
--- a/lib/libc/sys/write.2
+++ b/lib/libc/sys/write.2
@@ -49,9 +49,11 @@
.Ft ssize_t
.Fn write "int d" "const void *buf" "size_t nbytes"
.Ft ssize_t
+.Fn pwrite "int d" "const void *buf" "size_t nbytes" "off_t offset"
+.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"
+.Fn pwritev "int d" "const struct iovec *iov" "int iovcnt" "off_t offset"
.Sh DESCRIPTION
The
.Fn write
@@ -73,12 +75,16 @@ buffers specified by the members of the
array: iov[0], iov[1], ..., iov[iovcnt\|-\|1].
The
.Fn pwrite
-system call
-performs the same function, but writes to the specified position in
+and
+.Fn pwritev
+system calls
+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:
@@ -143,8 +149,9 @@ is set to indicate the error.
The
.Fn write ,
.Fn writev ,
-and
.Fn pwrite
+and
+.Fn pwritev
system calls
will fail and the file pointer will remain unchanged if:
.Bl -tag -width Er
@@ -201,6 +208,8 @@ is greater than
.Pp
In addition,
.Fn writev
+and
+.Fn pwritev
may return one of the following errors:
.Bl -tag -width Er
.It Bq Er EDESTADDRREQ
@@ -233,7 +242,9 @@ The mbuf pool has been completely exhausted when writing to a socket.
.Pp
The
.Fn pwrite
-system call may also return the following errors:
+and
+.Fn pwritev
+system calls may also return the following errors:
.Bl -tag -width Er
.It Bq Er EINVAL
The
@@ -261,6 +272,10 @@ system calls are expected to conform to
.St -xpg4.2 .
.Sh HISTORY
The
+.Fn pwritev
+system call appeared in
+.Fx 6.0 .
+The
.Fn pwrite
function appeared in
.At V.4 .
OpenPOWER on IntegriCloud