OSDN Git Service

Update release for LDP 3.67
[linuxjm/LDP_man-pages.git] / release / man2 / stat.2
1 .\" t
2 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
3 .\" Parts Copyright (c) 1995 Nicolai Langfeldt (janl@ifi.uio.no), 1/1/95
4 .\" and Copyright (c) 2006, 2007, 2014 Michael Kerrisk <mtk.manpages@gmail.com>
5 .\"
6 .\" %%%LICENSE_START(VERBATIM)
7 .\" Permission is granted to make and distribute verbatim copies of this
8 .\" manual provided the copyright notice and this permission notice are
9 .\" preserved on all copies.
10 .\"
11 .\" Permission is granted to copy and distribute modified versions of this
12 .\" manual under the conditions for verbatim copying, provided that the
13 .\" entire resulting derived work is distributed under the terms of a
14 .\" permission notice identical to this one.
15 .\"
16 .\" Since the Linux kernel and libraries are constantly changing, this
17 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
18 .\" responsibility for errors or omissions, or for damages resulting from
19 .\" the use of the information contained herein.  The author(s) may not
20 .\" have taken the same level of care in the production of this manual,
21 .\" which is licensed free of charge, as they might when working
22 .\" professionally.
23 .\"
24 .\" Formatted or processed versions of this manual, if unaccompanied by
25 .\" the source, must acknowledge the copyright and authors of this work.
26 .\" %%%LICENSE_END
27 .\"
28 .\" Modified by Michael Haardt <michael@moria.de>
29 .\" Modified 1993-07-24 by Rik Faith <faith@cs.unc.edu>
30 .\" Modified 1995-05-18 by Todd Larason <jtl@molehill.org>
31 .\" Modified 1997-01-31 by Eric S. Raymond <esr@thyrsus.com>
32 .\" Modified 1995-01-09 by Richard Kettlewell <richard@greenend.org.uk>
33 .\" Modified 1998-05-13 by Michael Haardt <michael@cantor.informatik.rwth-aachen.de>
34 .\" Modified 1999-07-06 by aeb & Albert Cahalan
35 .\" Modified 2000-01-07 by aeb
36 .\" Modified 2004-06-23 by Michael Kerrisk <mtk.manpages@gmail.com>
37 .\" 2007-06-08 mtk: Added example program
38 .\" 2007-07-05 mtk: Added details on underlying system call interfaces
39 .\"
40 .\"*******************************************************************
41 .\"
42 .\" This file was generated with po4a. Translate the source file.
43 .\"
44 .\"*******************************************************************
45 .\"
46 .\" Japanese Version Copyright (c) 1998-1999 HANATAKA Shinya
47 .\" and Copyright (c) 2005-2008 Akihiro MOTOKI
48 .\" Translated 1998-06-21, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
49 .\" Modified 1999-04-16, HANATAKA Shinya
50 .\" Updated 2000-01-03, Kentaro Shirakata <argrath@ub32.org>
51 .\" Updated 2000-10-06, Kentaro Shirakata
52 .\" Updated 2001-04-09, Kentaro Shirakata
53 .\" Updated 2001-06-25, Kentaro Shirakata
54 .\" Updated 2005-02-28, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
55 .\" Updated 2005-09-06, Akihiro MOTOKI
56 .\" Updated 2005-11-19, Akihiro MOTOKI, catch up to LDP v2.14
57 .\" Updated 2006-07-21, Akihiro MOTOKI, LDP v2.36
58 .\" Updated 2007-06-13, Akihiro MOTOKI, LDP v2.55
59 .\" Updated 2008-09-19, Akihiro MOTOKI, LDP v3.08
60 .\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
61 .\" Updated 2012-05-29, Akihiro MOTOKI <amotoki@gmail.com>
62 .\" Updated 2013-03-26, Akihiro MOTOKI <amotoki@gmail.com>
63 .\"
64 .TH STAT 2 2014\-05\-10 Linux "Linux Programmer's Manual"
65 .SH 名前
66 stat, fstat, lstat, fstatat \- ファイルの状態を取得する
67 .SH 書式
68 .nf
69 \fB#include <sys/types.h>\fP
70 .br
71 \fB#include <sys/stat.h>\fP
72 .br
73 \fB#include <unistd.h>\fP
74 .sp
75 \fBint stat(const char *\fP\fIpathname\fP\fB, struct stat *\fP\fIbuf\fP\fB);\fP
76 .br
77 \fBint fstat(int \fP\fIfd\fP\fB, struct stat *\fP\fIbuf\fP\fB);\fP
78 .br
79 \fBint lstat(const char *\fP\fIpathname\fP\fB, struct stat *\fP\fIbuf\fP\fB);\fP
80 .sp
81 \fB#include <fcntl.h>           \fP/* AT_* 定数の定義 */
82 \fB#include <sys/stat.h>\fP
83 .sp
84 \fBint fstatat(int \fP\fIdirfd\fP\fB, const char *\fP\fIpathname\fP\fB, struct stat *\fP\fIbuf\fP\fB,\fP
85 \fB            int \fP\fIflags\fP\fB);\fP
86 .fi
87 .sp
88 .in -4n
89 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
90 .in
91 .ad l
92 .PD 0
93 .sp
94 \fBlstat\fP():
95 .RS 4
96 /* glibc 2.19 and earlier */ _BSD_SOURCE ||
97 .br
98 /* Since glibc 2.20 */_DEFAULT_SOURCE ||
99 .br
100 _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
101 .br
102 || /* glibc 2.10 以降: */ _POSIX_C_SOURCE\ >=\ 200112L
103 .RE
104 .sp
105 \fBfstatat\fP():
106 .PD 0
107 .ad l
108 .RS 4
109 .TP  4
110 glibc 2.10 以降:
111 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
112 .TP 
113 glibc 2.10 より前:
114 _ATFILE_SOURCE
115 .RE
116 .PD
117 .ad
118 .SH 説明
119 .PP
120 これらの関数は、ファイルについての情報を \fIstat\fP が指すバッファに格納して返す。 ファイルそのものに対するアクセス許可は必要としないが、
121 \(em\fBstat\fP(), \fBfstatat\fP(), \fBlstat\fP() の場合には \(emそのファイルへ至る \fIpathname\fP
122 を構成する全てのディレクトリに対する実行 (検索) 許可が必要である。
123 .PP
124 \fBstat\fP() と \fBfstatat\fP() は \fIpathname\fP が指すファイルに関する情報を取得する。 \fBfstatat\fP()
125 の違いについては後で説明する。
126
127 \fBlstat\fP()  は \fBstat\fP()  と同じであるが、 \fIpathnames\fP
128 がシンボリックリンクの場合、リンクが参照しているファイルではなく、 リンク自身の状態を返す点が異なる。
129
130 \fBfstat\fP()  は \fBstat\fP()  と同じだが、 状態を取得するファイルをファイルディスクリプタ \fIfd\fP で指定する点が異なる。
131 .PP
132 これらのシステムコールはいずれも、結果を \fIstat\fP 構造体に入れて返す。 \fIstat\fP 構造体には以下のフィールドが含まれている:
133 .PP
134 .in +4n
135 .nf
136 struct stat {
137     dev_t     st_dev;     /* ファイルがあるデバイスの ID */
138     ino_t     st_ino;     /* inode 番号 */
139     mode_t    st_mode;    /* アクセス保護 */
140     nlink_t   st_nlink;   /* ハードリンクの数 */
141     uid_t     st_uid;     /* 所有者のユーザ ID */
142     gid_t     st_gid;     /* 所有者のグループ ID */
143     dev_t     st_rdev;    /* デバイス ID (特殊ファイルの場合) */
144     off_t     st_size;    /* 全体のサイズ (バイト単位) */
145     blksize_t st_blksize; /* ファイルシステム I/O での
146                              ブロックサイズ */
147     blkcnt_t  st_blocks;  /* 割り当てられた 512B のブロック数 */
148 };
149
150     /* Linux 2.6 以降では、カーネルは以下のタイムスタンプ
151        フィールドでナノ秒の精度をサポートしている。
152        Linux 2.6 より前のバージョンでの詳細は
153        下記の「注意」を参照。 */
154
155     struct timespec st_atim;  /* 最終アクセス時刻 */
156     struct timespec st_mtim;  /* 最終修正時刻 */
157     struct timespec st_ctim;  /* 最終状態変更時刻 */
158
159 #define st_atime st_atim.tv_sec      /* 後方互換性 */
160 #define st_mtime st_mtim.tv_sec
161 #define st_ctime st_ctim.tv_sec
162 };
163 .fi
164 .in
165
166 \fI注意:\fP \fIstat\fP 構造体のフィールドの順序はアーキテクチャにより様々である。
167 また、上記の定義では、フィールド間に存在することがあるパディングバイトは書かれていない。このパディングバイトはアーキテクチャによっても異なる。詳細を知る必要がある場合は
168 glibc とカーネルのソースを調べてほしい。
169
170 \fIst_dev\fP フィールドは、このファイルが存在するデバイスを示す (マクロ \fBmajor\fP(3), \fBminor\fP(3)
171 は、このフィールドのデバイス ID を分解するのに役立つだろう)。
172
173 \fIst_rdev\fP フィールドは、このファイル (inode) が表すデバイスを示す。
174
175 \fIst_size\fP フィールドは、(通常のファイルかシンボリックリンクの場合に)
176 ファイルの大きさをバイト単位で示す。 シンボリックリンクの大きさは、
177 シンボリックリンクに含まれている パス名の長さ (終端のヌルバイトは含まない)
178 である。
179
180 \fIst_blocks\fP フィールドは、ファイルの大きさを 512 バイトのブロックサイズ単位で示す フィールドは、ファイルに割り当てされたブロック数を
181 512 バイト単位で示す。 (ファイルに穴があるような場合、この値は \fIst_size\fP/512 より小さくなることもある)。
182
183 \fIst_blksize\fP フィールドは、効率的にファイルシステム I/O ができる「好ましい」 ブロックサイズを示す
184 (もっと小さい単位でファイルに書き込みを行うと、 読み出し\-\-修正\-\-再書き込みといった非効率な動作になってしまうかもしれない)。
185 .PP
186 全ての Linux のファイルシステムが全ての時間フィールドを 実装しているわけではない。 ファイルやディレクトリのアクセスが \fIst_atime\fP
187 フィールドを更新しないようなかたちでマウントできるファイルシステムもある。 (\fBmount\fP(8)  の \fInoatime\fP,
188 \fInodiratime\fP, \fIrelatime\fP や \fBmount\fP(2)  の関連する情報を参照)。 また、ファイルが \fBO_NOATIME\fP
189 付きでオープンされている場合には \fIst_atime\fP は更新されない。 \fBopen\fP(2)  参照。
190
191 \fIst_atime\fP フィールドはファイルアクセスがあった場合に変更される (例えば、 \fBexecve\fP(2), \fBmknod\fP(2),
192 \fBpipe\fP(2), \fButime\fP(2)  を使用した場合や \fBread\fP(2)  で 1 バイト以上読み込んだ場合など)。
193 \fBmmap\fP(2)  などの他のルーチンでは、 \fIst_atime\fP は更新されることもあれば、そうでない場合もある。
194
195 \fIst_mtime\fP フィールドは、ファイルが修正された場合に変更される (例えば、 \fBmknod\fP(2), \fBtruncate\fP(2),
196 \fButime\fP(2)  を使用した場合や \fBwrite\fP(2)  で 1 バイト以上書き込みをした場合など)。 さらに、ディレクトリの
197 \fIst_mtime\fP は、そのディレクトリで ファイルが作成されたり削除されたりすると変更される。 \fIst_mtime\fP フィールドは
198 所有者やグループやハード・リンク数やモードの変更では変更 \fIされない。\fP
199
200 \fIst_ctime\fP フィールドは書き込みや inode 情報 (所有者、グループ、リンク数、モードなど) の 設定によって変更される。
201 .PP
202 The following mask values are defined for the file type component of the
203 \fIst_mode\fP field:
204 .in +4n
205 .TS
206 lB l l.
207 S_IFMT  0170000 ファイル種別を示すビット領域を表すビットマスク
208
209 S_IFSOCK        0140000 ソケット
210 S_IFLNK 0120000 シンボリックリンク
211 S_IFREG 0100000 通常のファイル
212 S_IFBLK 0060000 ブロック・デバイス
213 S_IFDIR 0040000 ディレクトリ
214 S_IFCHR 0020000 キャラクター・デバイス
215 S_IFIFO 0010000 FIFO
216 .TE
217 .in
218 .PP
219 Thus, to test for a regular file (for example), one could write:
220
221 .nf
222 .in +4n
223 stat(pathname, &sb);
224 if ((sb.st_mode & S_IFMT) == S_IFREG) {
225     /* Handle regular file */
226 }
227 .in
228 .fi
229 .PP
230 Because tests of the above form are common, additional macros are defined by
231 POSIX to allow the test of the file type in \fIst_mode\fP to be written more
232 concisely:
233 .RS 4
234 .TP  1.2i
235 \fBS_ISREG\fP(m)
236 通常のファイルか?
237 .TP 
238 \fBS_ISDIR\fP(m)
239 ディレクトリか?
240 .TP 
241 \fBS_ISCHR\fP(m)
242 キャラクター・デバイスか?
243 .TP 
244 \fBS_ISBLK\fP(m)
245 ブロック・デバイスか?
246 .TP 
247 \fBS_ISFIFO\fP(m)
248 FIFO (名前付きパイプ) か?
249 .TP 
250 \fBS_ISLNK\fP(m)
251 シンボリックリンクか? (POSIX.1\-1996 にはない)
252 .TP 
253 \fBS_ISSOCK\fP(m)
254 ソケットか? (POSIX.1\-1996 にはない)
255 .RE
256 .PP
257 The preceding code snippet could thus be rewritten as:
258
259 .nf
260 .in +4n
261 stat(pathname, &sb);
262 if (S_ISREG(sb.st_mode)) {
263     /* Handle regular file */
264 }
265 .in
266 .fi
267 .PP
268 The definitions of most of the above file type test macros are provided if
269 any of the following feature test macros are defined: \fB_BSD_SOURCE\fP (in
270 glibc 2.19 and earlier), \fB_SVID_SOURCE\fP (in glibc 2.19 and earlier), or
271 \fB_DEFAULT_SOURCE\fP (in glibc 2.20 and later).  In addition, definitions of
272 all of the above macros except \fBS_IFSOCK\fP and \fBS_ISSOCK\fP()  are provided
273 if \fB_XOPEN_SOURCE\fP is defined.  The definition of \fBS_IFSOCK\fP can also be
274 exposed by defining \fB_XOPEN_SOURCE\fP with a value of 500 or greater.
275
276 The definition of \fBS_ISSOCK\fP()  is exposed if any of the following feature
277 test macros is defined: \fB_BSD_SOURCE\fP (in glibc 2.19 and earlier),
278 \fB_DEFAULT_SOURCE\fP (in glibc 2.20 and later), \fB_XOPEN_SOURCE\fP with a value
279 of 500 or greater, or \fB_POSIX_C_SOURCE\fP with a value of 200112L or greater.
280 .PP
281 The following mask values are defined for the file permissions component of
282 the \fIst_mode\fP field:
283 .in +4n
284 .TS
285 lB l l.
286 S_ISUID 0004000 set\-user\-ID bit
287 S_ISGID 0002000 set\-group\-ID bit (下記参照)
288 S_ISVTX 0001000 スティッキー・ビット (下記参照)
289
290 S_IRWXU   00700 mask for file owner permissions
291 S_IRUSR   00400 owner has read permission
292 S_IWUSR   00200 owner has write permission
293 S_IXUSR   00100 owner has execute permission
294
295 S_IRWXG   00070 mask for group permissions
296 S_IRGRP   00040 group has read permission
297 S_IWGRP   00020 group has write permission
298 S_IXGRP   00010 group has execute permission
299
300 S_IRWXO   00007 T{
301 他人 (others) のアクセス許可用のビットマスク
302 T}
303 S_IROTH   00004 others have read permission
304 S_IWOTH   00002 others have write permission
305 S_IXOTH   00001 others have execute permission
306 .TE
307 .in
308 .P
309 The set\-group\-ID bit (\fBS_ISGID\fP)  has several special uses.  For a
310 directory, it indicates that BSD semantics is to be used for that directory:
311 files created there inherit their group ID from the directory, not from the
312 effective group ID of the creating process, and directories created there
313 will also get the \fBS_ISGID\fP bit set.  For a file that does not have the
314 group execution bit (\fBS_IXGRP\fP)  set, the set\-group\-ID bit indicates
315 mandatory file/record locking.
316 .P
317 .\"
318 .\"
319 ディレクトリにスティッキービット (S_ISVTX) が設定された場合は、 そのディレクトリのファイルの名前を変更したり、削除したりできるのは、
320 そのファイルの所有者か、そのディレクトリの所有者か、特権プロセス だけとなる。
321 .SS fstatat()
322 \fBfstatat\fP() システムコールは \fBstat\fP() と全く同様に動作するが、以下で説明する点が異なる。
323
324 指定された \fIpathname\fP が相対パスの場合、 ファイルディスクリプタ \fIdirfd\fP が参照するディレクトリに対する相対パスと解釈される
325 (\fBstat\fP() に相対パスを渡した場合のように、呼び出したプロセスのカレントワーキングディレクトリに対する相対パスではない)。
326
327 \fIpathname\fP が相対パスで、 \fIdirfd\fP が特別な値 \fBAT_FDCWD\fP の場合、 (\fBstat\fP(2) と同様に)
328 \fIpathname\fP は呼び出したプロセスのカレントワーキングディレクトリに対する相対パスと解釈される。
329
330 \fIpathname\fP で指定されたパス名が絶対パスの場合、 \fIdirfd\fP は無視される。
331
332 この \fIflags\fP 引き数は下記のフラグの 0 個以上の論理和を取ったものである:
333 .TP 
334 \fBAT_EMPTY_PATH\fP (Linux 2.6.39 以降)
335 .\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d
336 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
337 \fIpathname\fP が空文字列の場合、 \fIdirfd\fP が参照するファイルに対して操作を行う (\fIdirfd\fP は \fBopen\fP(2) の
338 \fBO_PATH\fP フラグを使って取得できる)。 \fBdirfd\fP が \fBAT_FDCWD\fP
339 の場合、呼び出しはカレントワーキングディレクトリに対して操作を行う。 この場合、 \fIdirfd\fP
340 は、ディレクトリだけでなく、任意のタイプのファイルを参照することができる。 このフラグは Linux 固有であり、その定義を得るには
341 \fB_GNU_SOURCE\fP を定義すること。
342 .TP 
343 \fBAT_NO_AUTOMOUNT\fP (Linux 2.6.38 以降)
344 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
345 \fIpathname\fP がオートマウントポイントとなっているディレクトリの場合、 \fIpathname\fP の最終 ("basename")
346 要素のオートマウントを行わない。 これにより (マウントされるはずの場所ではなく) オートマウントポイントの属性を取得することができる。
347 このフラグを使うと、 ディレクトリをスキャンするツールがオートマウントポイントのディレクトリを大量にオートマウントしてしまうのを防ぐことができる。
348 マウントポイントがすでにマウントされている場合 \fBAT_NO_AUTOMOUNT\fP フラグは何の効果もない。 このフラグは Linux
349 固有であり、その定義を得るには \fB_GNU_SOURCE\fP を定義すること。
350 .TP 
351 \fBAT_SYMLINK_NOFOLLOW\fP
352 (\fBlstat\fP() 同様) \fIpathname\fP がシンボリックリンクの場合リンクの展開を行わず、 リンク自身の情報を返す (デフォルトでは、
353 \fBfstatat\fP() は、 \fBstat\fP() と同様に、シンボリックリンクの展開を行う)。
354 .PP
355 \fBfstatat\fP() の必要性についての説明については \fBopenat\fP(2) を参照。
356 .SH 返り値
357 成功した場合、0 が返される。 失敗した場合、 \-1 が返され、 \fIerrno\fP に適切な値がセットされる。
358 .SH エラー
359 .TP 
360 \fBEACCES\fP
361 \fIpathname\fP が所属するディレクトリとその上位のディレクトリのいずれかに 対する検索許可がなかった
362 (\fBpath_resolution\fP(7)  も参照のこと)。
363 .TP 
364 \fBEBADF\fP
365 \fIfd\fP が不正である。
366 .TP 
367 \fBEFAULT\fP
368 アドレスが間違っている。
369 .TP 
370 \fBELOOP\fP
371 パスを辿る際に解決すべきシンボリックリンクが多過ぎた。
372 .TP 
373 \fBENAMETOOLONG\fP
374 \fIpathname\fP が長過ぎる。
375 .TP 
376 \fBENOENT\fP
377 \fIpathname\fP の構成要素が存在しないか、 \fIpathname\fP が空文字列である。
378 .TP 
379 \fBENOMEM\fP
380 カーネルのメモリが足りない。
381 .TP 
382 \fBENOTDIR\fP
383 \fIpathname\fP の前半部分 (prefix) の構成要素がディレクトリではない。
384 .TP 
385 \fBEOVERFLOW\fP
386 \fIpathname\fP または \fIfd\fP が、ファイルサイズ、inode 番号、ブロック数が
387 それぞれ \fIoff_t\fP 型、 \fIino_t\fP 型、 \fIblkcnt_t\fP 型で表現できないファイルを
388 参照している。このエラーが起こるのは、例えば、32 ビットプラットフォーム上で
389 \fI\-D_FILE_OFFSET_BITS=64\fP を指定せずにコンパイルされたアプリケーションが、
390 ファイルサイズが \fI(1<<31)\-1\fP バイトを超えるファイルに対して
391 \fBstat\fP() を呼び出した場合である。
392 .PP
393 \fBfstatat\fP() では以下のエラーも発生することがある。
394 .TP 
395 \fBEBADF\fP
396 \fIdirfd\fP が有効なファイルディスクリプタでない。
397 .TP 
398 \fBEINVAL\fP
399 \fIflags\fP に無効なフラグが指定された。
400 .TP 
401 \fBENOTDIR\fP
402 \fIpathname\fP が相対パスで、 \fIdirfd\fP がディレクトリ以外のファイルを参照しているファイルディスクリプタである。
403 .SH バージョン
404 \fBfstatat\fP()  はカーネル 2.6.16 で Linux に追加された。 ライブラリによるサポートはバージョン 2.4 で glibc
405 に追加された。
406 .SH 準拠
407 .\" SVr4 documents additional
408 .\" .BR fstat ()
409 .\" error conditions EINTR, ENOLINK, and EOVERFLOW.  SVr4
410 .\" documents additional
411 .\" .BR stat ()
412 .\" and
413 .\" .BR lstat ()
414 .\" error conditions EINTR, EMULTIHOP, ENOLINK, and EOVERFLOW.
415 \fBstat\fP(), \fBfstat\fP(), \fBlstat\fP(): SVr4, 4.3BSD, POSIX.1\-2001, POSIX.1.2008.
416
417 \fBfstatat\fP(): POSIX.1\-2008.
418
419 POSIX.1\-2001 では、シンボリックリンクに対する \fBlstat\fP() で
420 有効な情報を返すように求められていたのは、 \fIstat\fP 構造体の \fIst_size\fP
421 と \fIst_mode\fP のファイル種別要素だけであった。
422 POSIX.1\-2008 では規定が厳しくなり、 \fBlstat\fP() は \fIst_mode\fP の
423 アクセス許可ビット以外の全てのフィールドに有効な情報を返すことが
424 求められるようになっている。
425
426 \fIst_blocks\fP と \fIst_blksize\fP フィールドの使用はあまり移植性がない
427 (これらのフィールドは BSD によって導入された。 システムごとに解釈が
428 異なっており、 NFS マウントの場合には同じシステムでも異なる可能性がある)。
429 \fI<sys/stat.h>\fP から \fIblkcnt_t\fP の \fIblksize_t\fP 型定義を
430 読み込みたい場合は、(\fIどの\fPヘッダファイルをインクルードするよりも前に)
431 \fB_XOPEN_SOURCE\fP を 500 以上の値で定義すること。
432 .LP
433 POSIX.1\-1990 には \fBS_IFMT\fP, \fBS_IFSOCK\fP, \fBS_IFLNK\fP, \fBS_IFREG\fP,
434 \fBS_IFBLK\fP, \fBS_IFDIR\fP, \fBS_IFCHR\fP, \fBS_IFIFO\fP, \fBS_ISVTX\fP 定数に関する
435 記述はなかったが、代わりに \fBS_ISDIR\fP() のようなマクロを使用するように
436 要求していた。 \fBS_IF*\fP 定数は POSIX.1\-2001 以降には存在する。
437
438 マクロ \fBS_ISLNK\fP() と \fBS_ISSOCK\fP() は POSIX.1\-1996 にはないが、
439 POSIX.1\-2001 には両方とも存在する。 前者は SVID 4 に、後者は SUSv2 に
440 由来している。
441 .LP
442 UNIX\ V7 (とその後のシステム) は \fBS_IREAD\fP, \fBS_IWRITE\fP, \fBS_IEXEC\fP を持っており、
443 POSIX はその同義語として \fBS_IRUSR\fP, \fBS_IWUSR\fP, \fBS_IXUSR\fP を規定している。
444 .SS 他のシステム
445 各種システムで使用されていた(いる)値:
446 .ad l
447 .TS
448 l l l l l.
449 16進   名前  ls      8進数 説明
450 f000    S_IFMT          170000  ファイル種別フィールドのビットマスク
451 0000                    000000  T{
452 SCO では 使用不能 inode; BSD では不明なファイル種別;
453 SVID\-v2 と XPG2 では 0 と 0100000 の両方が通常のファイル
454 T}
455 1000    S_IFIFO p|      010000  FIFO (名前付きパイプ)
456 2000    S_IFCHR c       020000  キャラクタ特殊ファイル (V7)
457 3000    S_IFMPC         030000  多重化されたキャラクタ特殊ファイル (V7)
458 4000    S_IFDIR d/      040000  ディレクトリ (V7)
459 5000    S_IFNAM         050000  T{
460 XENIX の二つの副型を持つ名前付きの特殊ファイル
461 副型は \fIst_rdev\fP の値 1, 2 で区別される
462 T}
463 0001    S_INSEM s       000001  XENIX の IFNAM セマフォ副型
464 0002    S_INSHD m       000002  XENIX の IFNAM 共有データ副型
465 6000    S_IFBLK b       060000  ブロック特殊ファイル (V7)
466 7000    S_IFMPB         070000  多重化されたブロック特殊ファイル (V7)
467 8000    S_IFREG \-      100000  通常ファイル (V7)
468 9000    S_IFCMP         110000  VxFS 圧縮ファイル
469 9000    S_IFNWK n       110000  ネットワーク特殊ファイル (HP\-UX)
470 a000    S_IFLNK l@      120000  シンボリックリンク (BSD)
471 b000    S_IFSHAD                130000  T{
472 Solaris の ACL 用の隠し inode (ユーザ空間からは見えない)
473 T}
474 c000    S_IFSOCK        s=      140000  ソケット (BSD; VxFS の "S_IFSOC")
475 d000    S_IFDOOR        D>      150000  Solaris の door ファイル
476 e000    S_IFWHT w%      160000  BSD の空白ファイル (inode を使用しない)
477 0200    S_ISVTX         001000  T{
478 スティッキービット: 使用後もスワップに残す (V7)
479 .br
480 予約 (SVID\-v2)
481 .br
482 ディレクトリ以外: ファイルをキャッシュしない (SunOS)
483 .br
484 ディレクトリの場合: 削除制限フラグ (SVID\-v4.2)
485 T}
486 0400    S_ISGID         002000  T{
487 実行時の set\-group\-ID (V7)
488 .br
489 ディレクトリの場合: GID の伝搬に BSD 方式を使用する
490 T}
491 0400    S_ENFMT         002000  T{
492 System V ファイルロックを強制する (S_ISGID と共有)
493 T}
494 0800    S_ISUID         004000  実行時の set\-user\-ID (V7)
495 0800    S_CDF           004000  T{
496 ディレクトリがコンテキスト依存ファイル (HP\-UX)
497 T}
498 .TE
499 .ad
500
501 スティッキー コマンドは Version 32V AT&T UNIX で登場した。
502 .SH 注意
503 Linux では、 \fBlstat\fP() は一般には自動マウント動作 (automounter action) の
504 きっかけとならないが、 \fBstat\fP() はきっかけとなる (\fBfstatat\fP(2) を参照)。
505
506 \fI/proc\fP ディレクトリ以下にあるファイルのほとんどでは、 \fBstat\fP()  を呼び出した際に、 \fIst_size\fP
507 フィールドにファイルサイズが返されない。 代わりに \fIst_size\fP フィールドには 0 が返される。
508 .SS タイムスタンプフィールド
509 古いカーネルや古い標準では、ナノ秒精度のタイムスタンプフィールドはサポートされていなかった。 代わりに 3 つの \fItime_t\fP
510 型のタイムスタンプフィールド \fIst_atime\fP, \fIst_mtime\fP, and \fIst_ctime\fP があった。これらのフィールドには 1
511 秒単位のタイムスタンプが記録されていた。
512
513 カーネル 2.5.48 以降では、 \fIstat\fP 構造体は 3 つのファイルのタイムスタンプ関連のフィールドでナノ秒単位の精度に対応している。
514 機能検査マクロ \fB_BSD_SOURCE\fP か \fB_SVID_SOURCE\fP が定義された場合に、各タイムスタンプのナノ秒の情報は
515 \fIst_atim.tv_nsec\fP という形式の名前で参照できる。 ナノ秒のタイムスタンプは現在では標準化されており、 POSIX.1\-2008
516 からである。 バージョン 2.12 以降の glibc では、 \fB_POSIX_C_SOURCE\fP が 200809L 以上の値で定義されるか、
517 \fB_XOPEN_SOURCE\fP が 700 以上の値で定義された場合にも、 このナノ秒のタイムスタンプが公開される。
518 上記のマクロのいずれも定義されていない場合、ナノ秒の値は \fIst_atimensec\fP という形式の名前で公開される。
519
520 .\" commit ef7f38359ea8b3e9c7f2cae9a4d4935f55ca9e80
521 ナノ秒のタイムスタンプは XFS, JFS, Btrfs, ext4 でサポートされている (Linux 2.6.23 以降)。
522 ナノ秒のタイムスタンプは ext2, ext3, Reiserfs ではサポートされていない。
523 サブ秒のタイムスタンプをサポートしていないファイルシステムでは、 ナノ秒のフィールドには値 0 が入る。
524 .SS 背後のカーネル・インタフェース
525 .\"
526 .\" A note from Andries Brouwer, July 2007
527 .\"
528 .\" > Is the story not rather more complicated for some calls like
529 .\" > stat(2)?
530 .\"
531 .\" Yes and no, mostly no. See /usr/include/sys/stat.h .
532 .\"
533 .\" The idea is here not so much that syscalls change, but that
534 .\" the definitions of struct stat and of the types dev_t and mode_t change.
535 .\" This means that libc (even if it does not call the kernel
536 .\" but only calls some internal function) must know what the
537 .\" format of dev_t or of struct stat is.
538 .\" The communication between the application and libc goes via
539 .\" the include file <sys/stat.h> that defines a _STAT_VER and
540 .\" _MKNOD_VER describing the layout of the data that user space
541 .\" uses. Each (almost each) occurrence of stat() is replaced by
542 .\" an occurrence of xstat() where the first parameter of xstat()
543 .\" is this version number _STAT_VER.
544 .\"
545 .\" Now, also the definitions used by the kernel change.
546 .\" But glibc copes with this in the standard way, and the
547 .\" struct stat as returned by the kernel is repacked into
548 .\" the struct stat as expected by the application.
549 .\" Thus, _STAT_VER and this setup cater for the application-libc
550 .\" interface, rather than the libc-kernel interface.
551 .\"
552 .\" (Note that the details depend on gcc being used as c compiler.)
553 時間の経過とともに、 \fIstat\fP 構造体のサイズが大きくなり、この影響で \fBstat\fP()  には 3つのバージョンが存在する:
554 \fIsys_stat\fP()  (スロットは \fI__NR_oldstat\fP)、 \fIsys_newstat\fP()  (スロットは
555 \fI__NR_stat\fP)、 \fIsys_stat64\fP()  (カーネル 2.4 で導入; スロットは \fI__NR_stat64\fP).  glibc
556 の \fBstat\fP()  ラッパー関数はこれらの詳細をアプリケーションから隠蔽してくれる。
557 具体的には、カーネルが提供しているシステムコールのうち最新のバージョンを 起動し、古いバイナリの場合には必要に応じて返された情報を再構成
558 (repack) する。 \fBfstat\fP()  と \fBlstat\fP()  についても同様である。
559
560 glibc の \fBfstatat\fP() ラッパー関数が内部で利用するシステムコールは、実際には \fBfstatat64\fP() である。
561 .SH 例
562 以下のプログラムは \fBstat\fP()  を呼び出し、返ってきた \fIstat\fP 構造体のフィールドのいくつかを表示する。
563 .nf
564
565 #include <sys/types.h>
566 #include <sys/stat.h>
567 #include <time.h>
568 #include <stdio.h>
569 #include <stdlib.h>
570
571 int
572 main(int argc, char *argv[])
573 {
574     struct stat sb;
575
576     if (argc != 2) {
577         fprintf(stderr, "Usage: %s <pathname>\en", argv[0]);
578         exit(EXIT_FAILURE);
579     }
580
581     if (stat(argv[1], &sb) == \-1) {
582         perror("stat");
583         exit(EXIT_FAILURE);
584     }
585
586     printf("File type:                ");
587
588     switch (sb.st_mode & S_IFMT) {
589     case S_IFBLK:  printf("block device\en");            break;
590     case S_IFCHR:  printf("character device\en");        break;
591     case S_IFDIR:  printf("directory\en");               break;
592     case S_IFIFO:  printf("FIFO/pipe\en");               break;
593     case S_IFLNK:  printf("symlink\en");                 break;
594     case S_IFREG:  printf("regular file\en");            break;
595     case S_IFSOCK: printf("socket\en");                  break;
596     default:       printf("unknown?\en");                break;
597     }
598
599     printf("I\-node number:            %ld\en", (long) sb.st_ino);
600
601     printf("Mode:                     %lo (octal)\en",
602             (unsigned long) sb.st_mode);
603
604     printf("Link count:               %ld\en", (long) sb.st_nlink);
605     printf("Ownership:                UID=%ld   GID=%ld\en",
606             (long) sb.st_uid, (long) sb.st_gid);
607
608     printf("Preferred I/O block size: %ld bytes\en",
609             (long) sb.st_blksize);
610     printf("File size:                %lld bytes\en",
611             (long long) sb.st_size);
612     printf("Blocks allocated:         %lld\en",
613             (long long) sb.st_blocks);
614
615     printf("Last status change:       %s", ctime(&sb.st_ctime));
616     printf("Last file access:         %s", ctime(&sb.st_atime));
617     printf("Last file modification:   %s", ctime(&sb.st_mtime));
618
619     exit(EXIT_SUCCESS);
620 }
621 .fi
622 .SH 関連項目
623 \fBls\fP(1), \fBstat\fP(1), \fBaccess\fP(2), \fBchmod\fP(2), \fBchown\fP(2),
624 \fBreadlink\fP(2), \fButime\fP(2), \fBcapabilities\fP(7), \fBsymlink\fP(7)
625 .SH この文書について
626 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.67 の一部
627 である。プロジェクトの説明とバグ報告に関する情報は
628 http://www.kernel.org/doc/man\-pages/ に書かれている。