1.\" $NetBSD: dofileread.9,v 1.6 2005/12/20 19:53:15 rpaulo Exp $ 2.\" 3.\" Copyright (c) 2002 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to The NetBSD Foundation 7.\" by Gregory McGarry. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 3. All advertising materials mentioning features or use of this software 18.\" must display the following acknowledgement: 19.\" This product includes software developed by the NetBSD 20.\" Foundation, Inc. and its contributors. 21.\" 4. Neither the name of The NetBSD Foundation nor the names of its 22.\" contributors may be used to endorse or promote products derived 23.\" from this software without specific prior written permission. 24.\" 25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35.\" POSSIBILITY OF SUCH DAMAGE. 36.\" 37.Dd December 20, 2005 38.Dt DOFILEREAD 9 39.Os 40.Sh NAME 41.Nm dofileread , 42.Nm dofilereadv , 43.Nm dofilewrite , 44.Nm dofilewritev , 45.Nd high-level file operations 46.Sh SYNOPSIS 47.In sys/file.h 48.Ft int 49.Fn dofileread "struct lwp *l" "int fd" "struct file *fp" "void *buf" \ 50"size_t nbyte" "off_t *offset" "int flags" "register_t *retval" 51.Ft int 52.Fn dofilewrite "struct lwp *l" "int fd" "struct file *fp" \ 53"const void *buf" "size_t nbyte" "off_t *offset" "int flags" \ 54"register_t *retval" 55.Ft int 56.Fn dofilereadv "struct lwp *l" "int fd" "struct file *fp" \ 57"const struct iovec *iovp" "int iovcnt" "off_t *offset" "int flags" \ 58"register_t *retval" 59.Ft int 60.Fn dofilewritev "struct lwp *l" "int fd" "struct file *fp" \ 61"const struct iovec *iovp" "int iovcnt" "off_t *offset" "int flags" \ 62"register_t *retval" 63.Sh DESCRIPTION 64The functions implement the underlying functionality of the 65.Xr read 2 , 66.Xr write 2 , 67.Xr readv 2 , 68and 69.Xr writev 2 70system calls. 71They are also used throughout the kernel as high-level access routines 72for file I/O. 73.Pp 74The 75.Fn dofileread 76function attempts to read 77.Fa nbytes 78of data from the object referenced by file entry 79.Fa fp 80into the buffer pointed to by 81.Fa buf . 82The 83.Fn dofilewrite 84function attempts to write 85.Fa nbytes 86of data to the object referenced by file entry 87.Fa fp 88from the buffer pointed to by 89.Fa buf . 90.Pp 91The 92.Fn dofilereadv 93and 94.Fn dofilewritev 95functions perform the same operations, but scatter the data with the 96.Fa iovcnt 97buffers specified by the members of the 98.Fa iov 99array. 100.Pp 101The offset of the file operations is explicitly specified by 102.Fa *offset . 103The new file offset after the file operation is returned in 104.Fa *offset . 105If the FOF_UPDATE_OFFSET flag is specified in the 106.Fa flags 107argument, the file offset in the file entry 108.Fa fp 109is updated to reflect the new file offset, otherwise it remains 110unchanged after the operation. 111.Pp 112The file descriptor 113.Fa fd 114is largely unused except for use by the ktrace framework for reporting 115to userlevel the process's file descriptor. 116.Pp 117Upon successful completion the number of bytes which were transferred 118is returned in 119.Fa *retval . 120.Sh RETURN VALUES 121Upon successful completion zero is returned, otherwise an appropriate 122error is returned. 123.Sh CODE REFERENCES 124This section describes places within the 125.Nx 126source tree where actual code implementing or using these file 127operations can be found. 128All pathnames are relative to 129.Pa /usr/src . 130.Pp 131The framework for these file operations is implemented within the file 132.Pa sys/kern/sys_generic.c . 133.Sh SEE ALSO 134.Xr file 9 135