OSDN Git Service

49c4d6a89a848d36e307e02b78c0c44c3736889c
[linuxjm/LDP_man-pages.git] / release / man2 / lseek.2
1 .\" t
2 .\" Copyright (c) 1980, 1991 Regents of the University of California.
3 .\" and Copyright (c) 2011, Michael Kerrisk <mtk.manpages@gmail.com>
4 .\" All rights reserved.
5 .\"
6 .\" %%%LICENSE_START(BSD_4_CLAUSE_UCB)
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgement:
17 .\"     This product includes software developed by the University of
18 .\"     California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\"    may be used to endorse or promote products derived from this software
21 .\"    without specific prior written permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\" %%%LICENSE_END
35 .\"
36 .\"     @(#)lseek.2     6.5 (Berkeley) 3/10/91
37 .\"
38 .\" Modified 1993-07-23 by Rik Faith <faith@cs.unc.edu>
39 .\" Modified 1995-06-10 by Andries Brouwer <aeb@cwi.nl>
40 .\" Modified 1996-10-31 by Eric S. Raymond <esr@thyrsus.com>
41 .\" Modified 1998-01-17 by Michael Haardt
42 .\"   <michael@cantor.informatik.rwth-aachen.de>
43 .\" Modified 2001-09-24 by Michael Haardt <michael@moria.de>
44 .\" Modified 2003-08-21 by Andries Brouwer <aeb@cwi.nl>
45 .\" 2011-09-18, mtk, Added SEEK_DATA + SEEK_HOLE
46 .\"
47 .\"*******************************************************************
48 .\"
49 .\" This file was generated with po4a. Translate the source file.
50 .\"
51 .\"*******************************************************************
52 .TH LSEEK 2 2013\-03\-27 Linux "Linux Programmer's Manual"
53 .SH 名前
54 lseek \- ファイルの読み書きオフセットの位置を変える
55 .SH 書式
56 \fB#include <sys/types.h>\fP
57 .br
58 \fB#include <unistd.h>\fP
59 .sp
60 \fBoff_t lseek(int \fP\fIfd\fP\fB, off_t \fP\fIoffset\fP\fB, int \fP\fIwhence\fP\fB);\fP
61 .SH 説明
62 \fBlseek\fP()  関数は、ファイルディスクリプタ (descriptor)  \fIfd\fP に対応するオープンされたファイルのオフセットを、
63 \fIwhence\fP に基づき \fIoffset\fP 引き数の位置へ以下のように変更する:
64 .TP 
65 \fBSEEK_SET\fP
66 オフセットは \fIoffset\fP バイトに設定される。
67 .TP 
68 \fBSEEK_CUR\fP
69 オフセットは現在位置に \fIoffset\fP バイトを足した位置になる。
70 .TP 
71 \fBSEEK_END\fP
72 オフセットはファイルのサイズに \fIoffset\fP バイトを足した位置になる。
73 .PP
74 \fBlseek\fP()  関数は、オフセットをファイルの末尾を越えた位置に設定できる (但し、これによりファイルのサイズが変わらない)。
75 もしデータがこのオフセット位置以降に書き込まれた場合、 間の空隙の部分 ("穴 (hole)") の読み出しがあると、
76 実際にそこにデータを書き込まれるまでは NULL バイト (\(aq\e0\(aq) の列が返される。
77 .SS "Seeking file data and holes"
78 Linux バージョン 3.1 以降では、
79 \fIwhence\fP に以下の値も指定することができる。
80 .TP 
81 \fBSEEK_DATA\fP
82 Adjust the file offset to the next location in the file greater than or
83 equal to \fIoffset\fP containing data.  If \fIoffset\fP points to data, then the
84 file offset is set to \fIoffset\fP.
85 .TP 
86 \fBSEEK_HOLE\fP
87 Adjust the file offset to the next hole in the file greater than or equal to
88 \fIoffset\fP.  If \fIoffset\fP points into the middle of a hole, then the file
89 offset is set to \fIoffset\fP.  If there is no hole past \fIoffset\fP, then the
90 file offset is adjusted to the end of the file (i.e., there is an implicit
91 hole at the end of any file).
92 .PP
93 In both of the above cases, \fBlseek\fP()  fails if \fIoffset\fP points past the
94 end of the file.
95
96 These operations allow applications to map holes in a sparsely allocated
97 file.  This can be useful for applications such as file backup tools, which
98 can save space when creating backups and preserve holes, if they have a
99 mechanism for discovering holes.
100
101 .\" https://lkml.org/lkml/2011/4/22/79
102 .\" http://lwn.net/Articles/440255/
103 .\" http://blogs.oracle.com/bonwick/entry/seek_hole_and_seek_data
104 For the purposes of these operations, a hole is a sequence of zeros that
105 (normally) has not been allocated in the underlying file storage.  However,
106 a file system is not obliged to report holes, so these operations are not a
107 guaranteed mechanism for mapping the storage space actually allocated to a
108 file.  (Furthermore, a sequence of zeros that actually has been written to
109 the underlying storage may not be reported as a hole.)  In the simplest
110 implementation, a file system can support the operations by making
111 \fBSEEK_HOLE\fP always return the offset of the end of the file, and making
112 \fBSEEK_DATA\fP always return \fIoffset\fP (i.e., even if the location referred to
113 by \fIoffset\fP is a hole, it can be considered to consist of data that is a
114 sequence of zeros).
115
116 The \fB_GNU_SOURCE\fP feature test macro must be defined in order to obtain the
117 definitions of \fBSEEK_DATA\fP and \fBSEEK_HOLE\fP from \fI<unistd.h>\fP.
118 .SH 返り値
119 成功した場合、 \fBlseek\fP()  は結果のファイル位置をファイルの先頭からのバイト数で返す。 エラーの場合、値 \fI(off_t)\ \-1\fP
120 が返され、 \fIerrno\fP にエラーが指示される。
121 .SH エラー
122 .TP 
123 \fBEBADF\fP
124 \fIfd\fP がオープンされたファイルディスクリプタでない。
125 .TP 
126 \fBEINVAL\fP
127 .\" Some systems may allow negative offsets for character devices
128 .\" and/or for remote file systems.
129 \fIwhence\fP が有効な値ではない。または、seek の結果、ファイルオフセットが負に
130 なってしまうか、 seek 可能なデバイスの末尾を越えてしまう。
131 .TP 
132 \fBEOVERFLOW\fP
133 .\" HP-UX 11 says EINVAL for this case (but POSIX.1 says EOVERFLOW)
134 結果のファイルオフセットを \fIoff_t\fP 型で表現することができない。
135 .TP 
136 \fBESPIPE\fP
137 \fIfd\fP がパイプ、ソケット、FIFO を参照している。
138 .TP 
139 \fBENXIO\fP
140 \fIwhence\fP が \fBSEEK_DATA\fP か \fBSEEK_HOLE\fP で、
141 現在のファイルオフセットがファイルの末尾を超えた位置である。
142 .SH 準拠
143 SVr4, 4.3BSD, POSIX.1\-2001.
144
145 .\" FIXME . Review http://austingroupbugs.net/view.php?id=415 in the future
146 \fBSEEK_DATA\fP and \fBSEEK_HOLE\fP are nonstandard extensions also present in
147 Solaris, FreeBSD, and DragonFly BSD; they are proposed for inclusion in the
148 next POSIX revision (Issue 8).
149 .SH 注意
150 いくつかのデバイスでは seek ができない。 POSIX はどのデバイスが \fBlseek\fP()  に対応すべきかは規定していない。
151
152 .\" Other systems return the number of written characters,
153 .\" using SEEK_SET to set the counter. (Of written characters.)
154 Linux では、端末 (terminal) デバイスに \fBlseek\fP() を使用すると \fBESPIPE\fP が返る。
155
156 古いコードを変換する時は \fIwhence\fP の値を以下のマクロに置き換えること:
157 .TS
158 c c
159 l l.
160 old     new
161 0       SEEK_SET
162 1       SEEK_CUR
163 2       SEEK_END
164 L_SET   SEEK_SET
165 L_INCR  SEEK_CUR
166 L_XTND  SEEK_END
167 .TE
168 .\" .PP
169 .\" SVr1-3 returns \fIlong\fP instead of \fIoff_t\fP,
170 .\" (ancient) BSD returns \fIint\fP.
171 .PP
172 \fBdup\fP(2)  や \fBfork\fP(2)  で作成されたファイルディスクリプタは、現在のファイル位置ポインタ (current file
173 position pointer) を共有しているので、 このようなファイルで移動を行うと競合状態を引き起こす可能性がある。
174 .SH 関連項目
175 \fBdup\fP(2), \fBfork\fP(2), \fBopen\fP(2), \fBfseek\fP(3), \fBlseek64\fP(3),
176 \fBposix_fallocate\fP(3)
177 .SH この文書について
178 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.51 の一部
179 である。プロジェクトの説明とバグ報告に関する情報は
180 http://www.kernel.org/doc/man\-pages/ に書かれている。