File: readv.2

package info (click to toggle)
manpages-ja 0.5.0.0.20221215%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 29,304 kB
  • sloc: perl: 161; makefile: 61
file content (266 lines) | stat: -rw-r--r-- 14,533 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
.\" Copyright (C) 2007, 2010 Michael Kerrisk <mtk.manpages@gmail.com>
.\" and Copyright (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de)
.\"
.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date.  The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein.  The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\" %%%LICENSE_END
.\"
.\" Modified Sat Jul 24 18:34:44 1993 by Rik Faith (faith@cs.unc.edu)
.\" Merged readv.[23], 2002-10-17, aeb
.\" 2007-04-30 mtk, A fairly major rewrite to fix errors and
.\"     add more details.
.\" 2010-11-16, mtk, Added documentation of preadv() and pwritev()
.\"
.\"*******************************************************************
.\"
.\" This file was generated with po4a. Translate the source file.
.\"
.\"*******************************************************************
.\"
.\" Japanese Version Copyright (c) 1997-1999 HANATAKA Shinya
.\"         all rights reserved.
.\" Translated 1997-02-23, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
.\" Updated 1999-04-03, HANATAKA Shinya
.\" Updated 2003-01-14, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
.\" Updated 2005-10-07, Akihiro MOTOKI
.\" Updated 2007-06-01, Akihiro MOTOKI, LDP v2.50
.\" Updated 2012-05-08, Akihiro MOTOKI <amotoki@gmail.com>
.\" Updated 2013-03-26, Akihiro MOTOKI <amotoki@gmail.com>
.\"
.TH READV 2 2020\-12\-21 Linux "Linux Programmer's Manual"
.SH 名前
readv, writev, preadv, pwritev, preadv2, pwritev2 \- 複数のバッファーへの読み書きを行なう
.SH 書式
.nf
\fB#include <sys/uio.h>\fP
.PP
\fBssize_t readv(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB);\fP
.PP
\fBssize_t writev(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB);\fP
.PP
\fBssize_t preadv(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB,\fP
\fB               off_t \fP\fIoffset\fP\fB);\fP
.PP
\fBssize_t pwritev(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB,\fP
\fB                off_t \fP\fIoffset\fP\fB);\fP
.PP
 \fBssize_t preadv2(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB,\fP
\fB                off_t \fP\fIoffset\fP\fB, int \fP\fIflags\fP\fB);\fP
.PP
 \fBssize_t pwritev2(int \fP\fIfd\fP\fB, const struct iovec *\fP\fIiov\fP\fB, int \fP\fIiovcnt\fP\fB,\fP
\fB                 off_t \fP\fIoffset\fP\fB, int \fP\fIflags\fP\fB);\fP
.fi
.PP
.RS -4
glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
.RE
.PP
\fBpreadv\fP(),
\fBpwritev\fP():
    Since glibc 2.19:
        _DEFAULT_SOURCE
    Glibc 2.19 and earlier:
        _BSD_SOURCE
.SH 説明
\fBreadv\fP() システムコールは、ファイルディスクリプター \fIfd\fP に関連付けられた
ファイルから、 \fIiovcnt\fP 個のバッファー分のデータを読み込み、 \fIiov\fP で指定
されたバッファーに格納する ("scatter input";「ばらまき入力」)。
.PP
\fBwritev\fP() システムコールは、 \fIiov\fP で指定されたバッファーから最大 \fIiovcnt\fP
個のバッファー分のデータを取り出し、 ファイルディスクリプター \fIfd\fP に関連付けら
れたファイルに書き込む ("gather output";「かき集め出力」)。
.PP
ポインター \fIiov\fP は \fIiovec\fP 構造体の配列へのポインターである。 \fIiovec\fP 構造体は
\fI<sys/uio.h>\fP で以下のように定義されている:
.PP
.in +4n
.EX
struct iovec {
    void  *iov_base;    /* Starting address */
    size_t iov_len;     /* Number of bytes to transfer */
};
.EE
.in
.PP
\fBreadv\fP() システムコールは、複数のバッファーにデータを読み込む点を除いて
\fBread\fP(2) と全く同様の動作を行う。
.PP
\fBwritev\fP() システムコールは、複数のバッファーのデータを書き出す点以外は
\fBwrite\fP(2) と全く同様の動作を行う。
.PP
バッファーは配列の順序で処理される。これは、 \fBreadv\fP()  が \fIiov\fP[0] が完全に一杯になるまでデータを詰めてから、
\fIiov\fP[1] などに進むことを意味する (データが十分ない場合は、 \fIiov\fP が指すバッファーのいずれも一杯にならない)。 同様に、
\fBwritev\fP()  は \fIiov\fP[0] の内容を全部書き出してから \fIiov\fP[1] などに進む。
.PP
.\" Regarding atomicity, see https://bugzilla.kernel.org/show_bug.cgi?id=10596
\fBreadv\fP()  と \fBwritev\fP()  によるデータ転送は atomic に行われる。つまり、 \fBwritev\fP()
によるデータ書き込みは一つのブロックとして行われ、他のプロセスの write による書き込みと混ざり合うことはない (例外に関しては
\fBpipe\fP(7)  を参照のこと)。同様に、 \fBreadv\fP()  はファイルから連続するデータブロックが読み出すことが保証され、
同じファイル記述 (file description; \fBopen\fP(2)  参照) を参照するファイルディスクリプターを持つ他のスレッドやプロセスが
実行した read 操作の影響を受けることはない。
.SS "preadv() と pwritev()"
\fBpreadv\fP() システムコールは \fBreadv\fP() と \fBpread\fP(2) の機能を
組み合わせたものである。
\fBreadv\fP() と同じ処理を実行するが、
4 番目の引数 \fIoffset\fP が追加されており、
この引数は入力操作を行うファイルオフセットを指定する。
.PP
\fBpwritev\fP() システムコールは \fBwritev\fP() と \fBpwrite\fP(2) の機能を
組み合わせたものである。
\fBwritev\fP() と同じ処理を実行するが、
4 番目の引数 \fIoffset\fP が追加されており、
この引数は出力操作を行うファイルオフセットを指定する。
.PP
これらのシステムコールで、ファイルオフセットは変更されない。
\fIfd\fP が参照するファイルは seek 可能でなければならない。
.SS "preadv2() と pwritev2()"
These system calls are similar to \fBpreadv\fP()  and \fBpwritev\fP()  calls, but
add a fifth argument, \fIflags\fP, which modifies the behavior on a per\-call
basis.
.PP
Unlike \fBpreadv\fP()  and \fBpwritev\fP(), if the \fIoffset\fP argument is \-1, then
the current file offset is used and updated.
.PP
The \fIflags\fP argument contains a bitwise OR of zero or more of the following
flags:
.TP 
\fBRWF_DSYNC\fP (Linux 4.7 以降)
.\" commit e864f39569f4092c2b2bc72c773b6e486c7e3bd9
Provide a per\-write equivalent of the \fBO_DSYNC\fP \fBopen\fP(2)  flag.  This
flag is meaningful only for \fBpwritev2\fP(), and its effect applies only to
the data range written by the system call.
.TP 
\fBRWF_HIPRI\fP (Linux 4.6 以降)
High priority read/write.  Allows block\-based filesystems to use polling of
the device, which provides lower latency, but may use additional resources.
(Currently, this feature is usable only on a file descriptor opened using
the \fBO_DIRECT\fP flag.)
.TP 
\fBRWF_SYNC\fP (Linux 4.7 以降)
.\" commit e864f39569f4092c2b2bc72c773b6e486c7e3bd9
Provide a per\-write equivalent of the \fBO_SYNC\fP \fBopen\fP(2)  flag.  This flag
is meaningful only for \fBpwritev2\fP(), and its effect applies only to the
data range written by the system call.
.TP 
\fBRWF_NOWAIT\fP (Linux 4.14 以降)
.\" commit 3239d834847627b6634a4139cf1dc58f6f137a46
.\" commit 91f9943e1c7b6638f27312d03fe71fcc67b23571
Do not wait for data which is not immediately available.  If this flag is
specified, the \fBpreadv2\fP()  system call will return instantly if it would
have to read data from the backing storage or wait for a lock.  If some data
was successfully read, it will return the number of bytes read.  If no bytes
were read, it will return \-1 and set \fIerrno\fP to \fBEAGAIN\fP.  Currently, this
flag is meaningful only for \fBpreadv2\fP().
.TP 
\fBRWF_APPEND\fP (Linux 4.16 以降)
.\" commit e1fc742e14e01d84d9693c4aca4ab23da65811fb
Provide a per\-write equivalent of the \fBO_APPEND\fP \fBopen\fP(2)  flag.  This
flag is meaningful only for \fBpwritev2\fP(), and its effect applies only to
the data range written by the system call.  The \fIoffset\fP argument does not
affect the write operation; the data is always appended to the end of the
file.  However, if the \fIoffset\fP argument is \-1, the current file offset is
updated.
.SH 返り値
成功した場合、 \fBreadv\fP(), \fBpreadv\fP, \fBpreadv2\fP は読み込んだバイト数を返し、 \fBwritev\fP(),
\fBpwritev\fP(), \fBpwritev2\fP は書き込んだバイト数を返す。
.PP
Note that it is not an error for a successful call to transfer fewer bytes
than requested (see \fBread\fP(2)  and \fBwrite\fP(2)).
.PP
エラーの場合は \-1 が返され、 \fIerrno\fP が適切に設定される。
.SH エラー
\fBread\fP(2)  や \fBwrite\fP(2)  と同じエラーが定義されている。さらに、 \fBpreadv\fP(), \fBpreadv2\fP,
\fBpwritev\fP(), \fBpwritev2\fP は \fBlseek\fP(2) と同じ理由でも失敗する。また、追加で以下のエラーが定義されている:
.TP 
\fBEINVAL\fP
\fIiov_len\fP の合計が \fIssize_t\fP の範囲をオーバーフローした。
.TP 
\fBEINVAL\fP
ベクタ数 \fIiovcnt\fP が 0 より小さいか許可された最大値よりも大きかった。
.TP 
\fBEOPNOTSUPP\fP
未知のフラグが \fIflags\fP に指定された。
.SH バージョン
\fBpreadv\fP() と \fBpwritev\fP() は Linux 2.6.30 で初めて登場した。
ライブラリによるサポートは glibc 2.10 で追加された。
.PP
\fBpreadv2\fP() と \fBpwritev2\fP() は Linux 4.6 で初めて登場した。ライブラリによるサポートは glibc 2.26
で追加された。
.SH 準拠
.\" Linux libc5 used \fIsize_t\fP as the type of the \fIiovcnt\fP argument,
.\" and \fIint\fP as the return type.
.\" The readv/writev system calls were buggy before Linux 1.3.40.
.\" (Says release.libc.)
\fBreadv\fP(), \fBwritev\fP(): POSIX.1\-2001, POSIX.1\-2008, 4.4BSD (これらのシステムコールは
4.2BSD で初めて登場した)
.PP
\fBpreadv\fP(), \fBpwritev\fP(): 非標準だが、最近の BSD にも存在する。
.PP
\fBpreadv2\fP(), \fBpwritev2\fP(): 非標準の Linux による拡張。
.SH 注意
.\"
.\"
POSIX.1 では、 \fIiov\fP で渡すことができる要素数に上限を設ける実装が認められている。 実装はこの上限値を広告することができ、
\fI<limits.h>\fP の \fBIOV_MAX\fP を定義することや、 実行時に \fIsysconf(_SC_IOV_MAX)\fP
の返り値経由で知ることができる。 最近の Linux では、 この上限値は 1024 である。 Linux 2.0 の頃は、 この値は 16 であった。
.SS "C ライブラリとカーネルの違い"
素のシステムコール \fBpreadv\fP() と \fBpwritev\fP() のシグネチャーは、 「書式」に書かれている対応する GNU C
ライブラリのラッパー関数のものとは少し異なる。 最後の引数 \fIoffset\fP はラッパー関数によりシステムコールの 2 つの引数に展開される。
.PP
\fB unsigned long \fP\fIpos_l\fP\fB, unsigned long \fP\fIpos\fP
.PP
これらの引数は、それぞれ、 \fIoffset\fP の下位 32 ビットと上位 32 ビットである。
.SS "以前の C ライブラリとカーネルの違い"
古いバージョンの Linux では \fBIOV_MAX\fP が非常に小さかったという事実に対処するため、 glibc の \fBreadv\fP() と
\fBwritev\fP() のラッパー関数は、 その関数の内部で呼ばれるカーネルシステムコールがこの上限を超過して失敗したことを検出すると、
追加の動作をしていた。 \fBreadv\fP() の場合、 ラッパー関数は \fIiov\fP
で指定された全ての要素を格納できる大きさの一時バッファーを割り当て、 \fBread\fP(2) を呼び出す際にそのバッファーを渡し、
そのバッファーのデータを \fIiov\fP の各要素の \fIiov_base\fP フィールドが指定する場所にコピーしてから、 そのバッファーを解放していた。
\fBwritev\fP() のラッパー関数も、 同じように一時バッファーを使って \fBwrite\fP(2) を呼び出していた。
.PP
glibc ラッパー関数でのこの追加の動作は Linux 2.2 以降では必要なくなった。 しかし、 glibc はバージョン 2.10
まではこの動作を続けていた。 glibc 2.9 以降では、 システムがバージョン 2.6.18 より前の Linux カーネル (2.6.18
は勝手に選択したカーネルバージョンである) を実行しているとライブラリが検出した場合にのみ、 ラッパー関数はこの動作を行う。 glibc 2.20
以降では、 (Linux カーネルのバージョン 2.6.32 以降が必須条件となり) glibc
のラッパー関数は常にシステムコールを直接呼び出すようになっている。
.SH 例
以下のサンプルコードは \fBwritev\fP()  の使用方法を示すものである。
.PP
.in +4n
.EX
char *str0 = "hello ";
char *str1 = "world\en";
struct iovec iov[2];
ssize_t nwritten;

iov[0].iov_base = str0;
iov[0].iov_len = strlen(str0);
iov[1].iov_base = str1;
iov[1].iov_len = strlen(str1);

nwritten = writev(STDOUT_FILENO, iov, 2);
.EE
.in
.SH 関連項目
\fBpread\fP(2), \fBread\fP(2), \fBwrite\fP(2)
.SH この文書について
この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告に関する情報は
\%https://www.kernel.org/doc/man\-pages/ に書かれている。