xref: /netbsd/share/man/man9/dofileread.9 (revision 6550d01e)
1.\"     $NetBSD: dofileread.9,v 1.9 2010/12/02 12:54:13 wiz 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.\"
18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28.\" POSSIBILITY OF SUCH DAMAGE.
29.\"
30.Dd December 20, 2005
31.Dt DOFILEREAD 9
32.Os
33.Sh NAME
34.Nm dofileread ,
35.Nm dofilereadv ,
36.Nm dofilewrite ,
37.Nm dofilewritev
38.Nd high-level file operations
39.Sh SYNOPSIS
40.In sys/file.h
41.Ft int
42.Fn dofileread "struct lwp *l" "int fd" "struct file *fp" "void *buf" \
43"size_t nbyte" "off_t *offset" "int flags" "register_t *retval"
44.Ft int
45.Fn dofilewrite "struct lwp *l" "int fd" "struct file *fp" \
46"const void *buf" "size_t nbyte" "off_t *offset" "int flags" \
47"register_t *retval"
48.Ft int
49.Fn dofilereadv "struct lwp *l" "int fd" "struct file *fp" \
50"const struct iovec *iovp" "int iovcnt" "off_t *offset" "int flags" \
51"register_t *retval"
52.Ft int
53.Fn dofilewritev "struct lwp *l" "int fd" "struct file *fp" \
54"const struct iovec *iovp" "int iovcnt" "off_t *offset" "int flags" \
55"register_t *retval"
56.Sh DESCRIPTION
57The functions implement the underlying functionality of the
58.Xr read 2 ,
59.Xr write 2 ,
60.Xr readv 2 ,
61and
62.Xr writev 2
63system calls.
64They are also used throughout the kernel as high-level access routines
65for file I/O.
66.Pp
67The
68.Fn dofileread
69function attempts to read
70.Fa nbytes
71of data from the object referenced by file entry
72.Fa fp
73into the buffer pointed to by
74.Fa buf .
75The
76.Fn dofilewrite
77function attempts to write
78.Fa nbytes
79of data to the object referenced by file entry
80.Fa fp
81from the buffer pointed to by
82.Fa buf .
83.Pp
84The
85.Fn dofilereadv
86and
87.Fn dofilewritev
88functions perform the same operations, but scatter the data with the
89.Fa iovcnt
90buffers specified by the members of the
91.Fa iov
92array.
93.Pp
94The offset of the file operations is explicitly specified by
95.Fa *offset .
96The new file offset after the file operation is returned in
97.Fa *offset .
98If the FOF_UPDATE_OFFSET flag is specified in the
99.Fa flags
100argument, the file offset in the file entry
101.Fa fp
102is updated to reflect the new file offset, otherwise it remains
103unchanged after the operation.
104.Pp
105The file descriptor
106.Fa fd
107is largely unused except for use by the ktrace framework for reporting
108to userlevel the process's file descriptor.
109.Pp
110Upon successful completion the number of bytes which were transferred
111is returned in
112.Fa *retval .
113.Sh RETURN VALUES
114Upon successful completion zero is returned, otherwise an appropriate
115error is returned.
116.Sh CODE REFERENCES
117The framework for these file operations is implemented within the file
118.Pa sys/kern/sys_generic.c .
119.Sh SEE ALSO
120.Xr file 9
121