xref: /netbsd-src/share/man/man9/dofileread.9 (revision 9a8c339c780ba464cbff54cbf5ae955d3bde902e)
1.\"     $NetBSD: dofileread.9,v 1.2 2002/10/20 10:46:57 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.\" 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 October 20, 2002
38.Dt DOFILEREAD 9
39.Os
40.Sh NAME
41.Nm dofileread ,
42.Nm dofilewrite ,
43.Nm dofilereadv ,
44.Nm dofilewritev ,
45.Nd high-level file operations
46.Sh SYNOPSIS
47.Fd #include \*[Lt]sys/file.h\*[Gt]
48.Ft int
49.Fn dofileread "struct proc *p" "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 proc *p" "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 proc *p" "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 proc *p" "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 function 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.  They are also used throughout the kernel as high-level
71access routines for file I/O.
72.Pp
73The
74.Fn dofileread
75function
76attempts 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
85attempts to write
86.Fa nbytes
87of data to the object referenced by file entry
88.Fa fp
89from the buffer pointed to by
90.Fa buf .
91.Pp
92The
93.Fn dofilereadv
94and
95.Fn dofilewritev
96functions perform the same operations, but scatters the data with the
97.Fa iovcnt
98buffers specified by the members of the
99.Fa iov
100array.
101.Pp
102The offset of the file operations is explicitly specified by
103.Fa *offset .
104The new file offset after the file operation is returned in
105.Fa *offset .
106If the FOF_UPDATE_OFFSET flag is specified in the
107.Fa flags
108argument, the file offset in the file entry
109.Fa fp
110is updated to reflect the new file offset, otherwise it remains
111unchanged after the operation.
112.Pp
113The file descriptor
114.Fa fd
115is largely unused except for use by the ktrace framework for reporting
116to userlevel the process's file descriptor.
117.Pp
118Upon successful completion the number of bytes which were transferred
119is returned in
120.Fa *retval .
121.Sh RETURN VALUES
122Upon successful complete zero is returned, otherwise and appropriate
123error is returned.
124.Sh CODE REFERENCES
125This section describes places within the
126.Nx
127source tree where actual code implementing or utilising these file
128operations can be found.  All 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