OSDN Git Service

(split) LDP: Update draft and release for LDP 3.65
[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\-03\-19 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 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
97 .br
98 || /* glibc 2.10 以降: */ _POSIX_C_SOURCE\ >=\ 200112L
99 .RE
100 .sp
101 \fBfstatat\fP():
102 .PD 0
103 .ad l
104 .RS 4
105 .TP  4
106 glibc 2.10 以降:
107 _XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
108 .TP 
109 glibc 2.10 より前:
110 _ATFILE_SOURCE
111 .RE
112 .PD
113 .ad
114 .SH 説明
115 .PP
116 これらの関数は、ファイルについての情報を \fIstat\fP が指すバッファに格納して返す。 ファイルそのものに対するアクセス許可は必要としないが、
117 \(em\fBstat\fP(), \fBfstatat\fP(), \fBlstat\fP() の場合には \(emそのファイルへ至る \fIpathname\fP
118 を構成する全てのディレクトリに対する実行 (検索) 許可が必要である。
119 .PP
120 \fBstat\fP()  and \fBfstatat\fP()  retrieve information about the file pointed to
121 by \fIpathname\fP; the differences for \fBfstatat\fP()  are described below.
122
123 \fBlstat\fP()  は \fBstat\fP()  と同じであるが、 \fIpathnames\fP
124 がシンボリックリンクの場合、リンクが参照しているファイルではなく、 リンク自身の状態を返す点が異なる。
125
126 \fBfstat\fP()  は \fBstat\fP()  と同じだが、 状態を取得するファイルをファイルディスクリプタ \fIfd\fP で指定する点が異なる。
127 .PP
128 これらのシステムコールはいずれも、結果を \fIstat\fP 構造体に入れて返す。 \fIstat\fP 構造体には以下のフィールドが含まれている:
129 .PP
130 .in +4n
131 .nf
132 struct stat {
133     dev_t     st_dev;     /* ファイルがあるデバイスの ID */
134     ino_t     st_ino;     /* inode 番号 */
135     mode_t    st_mode;    /* アクセス保護 */
136     nlink_t   st_nlink;   /* ハードリンクの数 */
137     uid_t     st_uid;     /* 所有者のユーザ ID */
138     gid_t     st_gid;     /* 所有者のグループ ID */
139     dev_t     st_rdev;    /* デバイス ID (特殊ファイルの場合) */
140     off_t     st_size;    /* 全体のサイズ (バイト単位) */
141     blksize_t st_blksize; /* ファイルシステム I/O での
142                              ブロックサイズ */
143     blkcnt_t  st_blocks;  /* 割り当てられた 512B のブロック数 */
144 };
145
146     /* Since Linux 2.6, the kernel supports nanosecond
147        precision for the following timestamp fields.
148        For the details before Linux 2.6, see NOTES. */
149
150     struct timespec st_atim;  /* 最終アクセス時刻 */
151     struct timespec st_mtim;  /* 最終修正時刻 */
152     struct timespec st_ctim;  /* 最終状態変更時刻 */
153
154 #define st_atime st_atim.tv_sec      /* Backward compatibility */
155 #define st_mtime st_mtim.tv_sec
156 #define st_ctime st_ctim.tv_sec
157 };
158 .fi
159 .in
160
161 \fINote:\fP the order of fields in the \fIstat\fP structure varies somewhat across
162 architectures.  In addition, the definition above does not show the padding
163 bytes that may be present between some fields on various architectures.
164 Consult the the glibc and kernel source code if you need to know the
165 details.
166
167 \fIst_dev\fP フィールドは、このファイルが存在するデバイスを示す (マクロ \fBmajor\fP(3), \fBminor\fP(3)
168 は、このフィールドのデバイス ID を分解するのに役立つだろう)。
169
170 \fIst_rdev\fP フィールドは、このファイル (inode) が表すデバイスを示す。
171
172 \fIst_size\fP フィールドは、(通常のファイルかシンボリックリンクの場合に)
173 ファイルの大きさをバイト単位で示す。 シンボリックリンクの大きさは、
174 シンボリックリンクに含まれている パス名の長さ (終端の NULL バイトは含まない)
175 である。
176
177 \fIst_blocks\fP フィールドは、ファイルの大きさを 512 バイトのブロックサイズ単位で示す フィールドは、ファイルに割り当てされたブロック数を
178 512 バイト単位で示す。 (ファイルに穴があるような場合、この値は \fIst_size\fP/512 より小さくなることもある)。
179
180 \fIst_blksize\fP フィールドは、効率的にファイルシステム I/O ができる「好ましい」 ブロックサイズを示す
181 (もっと小さい単位でファイルに書き込みを行うと、 読み出し\-\-修正\-\-再書き込みといった非効率な動作になってしまうかもしれない)。
182 .PP
183 全ての Linux のファイルシステムが全ての時間フィールドを 実装しているわけではない。 ファイルやディレクトリのアクセスが \fIst_atime\fP
184 フィールドを更新しないようなかたちでマウントできるファイルシステムもある。 (\fBmount\fP(8)  の \fInoatime\fP,
185 \fInodiratime\fP, \fIrelatime\fP や \fBmount\fP(2)  の関連する情報を参照)。 また、ファイルが \fBO_NOATIME\fP
186 付きでオープンされている場合には \fIst_atime\fP は更新されない。 \fBopen\fP(2)  参照。
187
188 \fIst_atime\fP フィールドはファイルアクセスがあった場合に変更される (例えば、 \fBexecve\fP(2), \fBmknod\fP(2),
189 \fBpipe\fP(2), \fButime\fP(2)  を使用した場合や \fBread\fP(2)  で 1 バイト以上読み込んだ場合など)。
190 \fBmmap\fP(2)  などの他のルーチンでは、 \fIst_atime\fP は更新されることもあれば、そうでない場合もある。
191
192 \fIst_mtime\fP フィールドは、ファイルが修正された場合に変更される (例えば、 \fBmknod\fP(2), \fBtruncate\fP(2),
193 \fButime\fP(2)  を使用した場合や \fBwrite\fP(2)  で 1 バイト以上書き込みをした場合など)。 さらに、ディレクトリの
194 \fIst_mtime\fP は、そのディレクトリで ファイルが作成されたり削除されたりすると変更される。 \fIst_mtime\fP フィールドは
195 所有者やグループやハード・リンク数やモードの変更では変更 \fIされない。\fP
196
197 \fIst_ctime\fP フィールドは書き込みや inode 情報 (所有者、グループ、リンク数、モードなど) の 設定によって変更される。
198 .PP
199 以下の POSIX マクロは、 \fIst_mode\fP フィールド で使用されるファイル種別のチェックのために定義されている :
200 .RS 4
201 .TP  1.2i
202 \fBS_ISREG\fP(m)
203 通常のファイルか?
204 .TP 
205 \fBS_ISDIR\fP(m)
206 ディレクトリか?
207 .TP 
208 \fBS_ISCHR\fP(m)
209 キャラクター・デバイスか?
210 .TP 
211 \fBS_ISBLK\fP(m)
212 ブロック・デバイスか?
213 .TP 
214 \fBS_ISFIFO\fP(m)
215 FIFO (名前付きパイプ) か?
216 .TP 
217 \fBS_ISLNK\fP(m)
218 シンボリックリンクか? (POSIX.1\-1996 にはない)
219 .TP 
220 \fBS_ISSOCK\fP(m)
221 ソケットか? (POSIX.1\-1996 にはない)
222 .RE
223 .PP
224 以下のフラグが \fIst_mode\fP フィールド用に定義されている:
225 .in +4n
226 .TS
227 lB l l.
228 S_IFMT  0170000 ファイル種別を示すビット領域を表すビットマスク
229 S_IFSOCK        0140000 ソケット
230 S_IFLNK 0120000 シンボリックリンク
231 S_IFREG 0100000 通常のファイル
232 S_IFBLK 0060000 ブロック・デバイス
233 S_IFDIR 0040000 ディレクトリ
234 S_IFCHR 0020000 キャラクター・デバイス
235 S_IFIFO 0010000 FIFO
236 S_ISUID 0004000 set\-user\-ID bit
237 S_ISGID 0002000 set\-group\-ID bit (下記参照)
238 S_ISVTX 0001000 スティッキー・ビット (下記参照)
239 S_IRWXU 00700   ファイル所有者のアクセス許可用のビットマスク
240 S_IRUSR 00400   所有者の読み込み許可
241 S_IWUSR 00200   所有者の書き込み許可
242 S_IXUSR 00100   所有者の実行許可
243 S_IRWXG 00070   グループのアクセス許可用のビットマスク
244 S_IRGRP 00040   グループの読み込み許可
245 S_IWGRP 00020   グループの書き込み許可
246 S_IXGRP 00010   グループの実行許可
247 S_IRWXO 00007   T{
248 他人 (others) のアクセス許可用のビットマスク
249 T}
250 S_IROTH 00004   他人の読み込み許可
251 S_IWOTH 00002   他人の書き込み許可
252 S_IXOTH 00001   他人の実行許可
253 .TE
254 .in
255 .P
256 set\-group\-ID bit (\fBS_ISGID\fP)  にはいくつかの特殊な使用法がある: ディレクトリに設定した場合には、そのディレクトリが
257 BSD 方式で使用される ことを示す。つまり、そのディレクトリに作成されたファイルのグループID は 作成したプロセスの実効 (effective)
258 グループID ではなく、ディレクトリの グループID を継承する。また、そのディレクトリに作成されたディレクトリにも \fBS_ISGID\fP
259 ビットが設定される。グループ実行ビット (\fBS_IXGRP\fP)  が設定されていないファイルに設定された場合は、 set\-group\-ID
260 ビットはファイル/レコードの 強制的な (mandatory) ロックを表す。
261 .P
262 .\"
263 .\"
264 ディレクトリにスティッキービット (S_ISVTX) が設定された場合は、 そのディレクトリのファイルの名前を変更したり、削除したりできるのは、
265 そのファイルの所有者か、そのディレクトリの所有者か、特権プロセス だけとなる。
266 .SS fstatat()
267 \fBfstatat\fP() システムコールは \fBstat\fP() と全く同様に動作するが、以下で説明する点が異なる。
268
269 If the pathname given in \fIpathname\fP is relative, then it is interpreted
270 relative to the directory referred to by the file descriptor \fIdirfd\fP
271 (rather than relative to the current working directory of the calling
272 process, as is done by \fBstat\fP()  for a relative pathname).
273
274 If \fIpathname\fP is relative and \fIdirfd\fP is the special value \fBAT_FDCWD\fP,
275 then \fIpathname\fP is interpreted relative to the current working directory of
276 the calling process (like \fBstat\fP()).
277
278 If \fIpathname\fP is absolute, then \fIdirfd\fP is ignored.
279
280 この \fIflags\fP 引き数は下記のフラグの 0 個以上の論理和を取ったものである:
281 .TP 
282 \fBAT_EMPTY_PATH\fP (Linux 2.6.39 以降)
283 .\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d
284 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
285 If \fIpathname\fP is an empty string, operate on the file referred to by
286 \fIdirfd\fP (which may have been obtained using the \fBopen\fP(2)  \fBO_PATH\fP
287 flag).  If \fIdirfd\fP is \fBAT_FDCWD\fP, the call operates on the current working
288 directory.  In this case, \fIdirfd\fP can refer to any type of file, not just a
289 directory.  This flag is Linux\-specific; define \fB_GNU_SOURCE\fP to obtain its
290 definition.
291 .TP 
292 \fBAT_NO_AUTOMOUNT\fP (Linux 2.6.38 以降)
293 .\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
294 Don't automount the terminal ("basename") component of \fIpathname\fP if it is
295 a directory that is an automount point.  This allows the caller to gather
296 attributes of an automount point (rather than the location it would mount).
297 This flag can be used in tools that scan directories to prevent
298 mass\-automounting of a directory of automount points.  The
299 \fBAT_NO_AUTOMOUNT\fP flag has no effect if the mount point has already been
300 mounted over.  This flag is Linux\-specific; define \fB_GNU_SOURCE\fP to obtain
301 its definition.
302 .TP 
303 \fBAT_SYMLINK_NOFOLLOW\fP
304 If \fIpathname\fP is a symbolic link, do not dereference it: instead return
305 information about the link itself, like \fBlstat\fP().  (By default,
306 \fBfstatat\fP()  dereferences symbolic links, like \fBstat\fP().)
307 .PP
308 See \fBopenat\fP(2)  for an explanation of the need for \fBfstatat\fP().
309 .SH 返り値
310 成功した場合、0 が返される。 失敗した場合、 \-1 が返され、 \fIerrno\fP に適切な値がセットされる。
311 .SH エラー
312 .TP 
313 \fBEACCES\fP
314 \fIpathname\fP が所属するディレクトリとその上位のディレクトリのいずれかに 対する検索許可がなかった
315 (\fBpath_resolution\fP(7)  も参照のこと)。
316 .TP 
317 \fBEBADF\fP
318 \fIfd\fP が不正である。
319 .TP 
320 \fBEFAULT\fP
321 アドレスが間違っている。
322 .TP 
323 \fBELOOP\fP
324 パスを辿る際に解決すべきシンボリックリンクが多過ぎた。
325 .TP 
326 \fBENAMETOOLONG\fP
327 \fIpathname\fP が長過ぎる。
328 .TP 
329 \fBENOENT\fP
330 \fIpathname\fP の構成要素が存在しないか、 \fIpathname\fP が空文字列である。
331 .TP 
332 \fBENOMEM\fP
333 カーネルのメモリが足りない。
334 .TP 
335 \fBENOTDIR\fP
336 \fIpathname\fP の前半部分 (prefix) の構成要素がディレクトリではない。
337 .TP 
338 \fBEOVERFLOW\fP
339 \fIpathname\fP または \fIfd\fP が、ファイルサイズ、inode 番号、ブロック数が
340 それぞれ \fIoff_t\fP 型、 \fIino_t\fP 型、 \fIblkcnt_t\fP 型で表現できないファイルを
341 参照している。このエラーが起こるのは、例えば、32 ビットプラットフォーム上で
342 \fI\-D_FILE_OFFSET_BITS=64\fP を指定せずにコンパイルされたアプリケーションが、
343 ファイルサイズが \fI(1<<31)\-1\fP バイトを超えるファイルに対して
344 \fBstat\fP() を呼び出した場合である。
345 .PP
346 The following additional errors can occur for \fBfstatat\fP():
347 .TP 
348 \fBEBADF\fP
349 \fIdirfd\fP が有効なファイルディスクリプタでない。
350 .TP 
351 \fBEINVAL\fP
352 \fIflags\fP に無効なフラグが指定された。
353 .TP 
354 \fBENOTDIR\fP
355 \fIpathname\fP is relative and \fIdirfd\fP is a file descriptor referring to a
356 file other than a directory.
357 .SH バージョン
358 \fBfstatat\fP()  はカーネル 2.6.16 で Linux に追加された。 ライブラリによるサポートはバージョン 2.4 で glibc
359 に追加された。
360 .SH 準拠
361 .\" SVr4 documents additional
362 .\" .BR fstat ()
363 .\" error conditions EINTR, ENOLINK, and EOVERFLOW.  SVr4
364 .\" documents additional
365 .\" .BR stat ()
366 .\" and
367 .\" .BR lstat ()
368 .\" error conditions EINTR, EMULTIHOP, ENOLINK, and EOVERFLOW.
369 \fBstat\fP(), \fBfstat\fP(), \fBlstat\fP(): SVr4, 4.3BSD, POSIX.1\-2001, POSIX.1.2008.
370
371 \fBfstatat\fP(): POSIX.1\-2008.
372
373 POSIX.1\-2001 では、シンボリックリンクに対する \fBlstat\fP() で
374 有効な情報を返すように求められていたのは、 \fIstat\fP 構造体の \fIst_size\fP
375 と \fIst_mode\fP のファイル種別要素だけであった。
376 POSIX.1\-2008 では規定が厳しくなり、 \fBlstat\fP() は \fIst_mode\fP の
377 アクセス許可ビット以外の全てのフィールドに有効な情報を返すことが
378 求められるようになっている。
379
380 \fIst_blocks\fP と \fIst_blksize\fP フィールドの使用はあまり移植性がない
381 (これらのフィールドは BSD によって導入された。 システムごとに解釈が
382 異なっており、 NFS マウントの場合には同じシステムでも異なる可能性がある)。
383 \fI<sys/stat.h>\fP から \fIblkcnt_t\fP の \fIblksize_t\fP 型定義を
384 読み込みたい場合は、(\fIどの\fPヘッダファイルをインクルードするよりも前に)
385 \fB_XOPEN_SOURCE\fP を 500 以上の値で定義すること。
386 .LP
387 POSIX.1\-1990 には \fBS_IFMT\fP, \fBS_IFSOCK\fP, \fBS_IFLNK\fP, \fBS_IFREG\fP,
388 \fBS_IFBLK\fP, \fBS_IFDIR\fP, \fBS_IFCHR\fP, \fBS_IFIFO\fP, \fBS_ISVTX\fP 定数に関する
389 記述はなかったが、代わりに \fBS_ISDIR\fP() のようなマクロを使用するように
390 要求していた。 \fBS_IF*\fP 定数は POSIX.1\-2001 以降には存在する。
391
392 マクロ \fBS_ISLNK\fP() と \fBS_ISSOCK\fP() は POSIX.1\-1996 にはないが、
393 POSIX.1\-2001 には両方とも存在する。 前者は SVID 4 に、後者は SUSv2 に
394 由来している。
395 .LP
396 UNIX V7 (とその後のシステム) は \fBS_IREAD\fP, \fBS_IWRITE\fP, \fBS_IEXEC\fP を持っており、
397 POSIX はその同義語として \fBS_IRUSR\fP, \fBS_IWUSR\fP, \fBS_IXUSR\fP を規定している。
398 .SS 他のシステム
399 各種システムで使用されていた(いる)値:
400 .ad l
401 .TS
402 l l l l l.
403 16進   名前  ls      8進数 説明
404 f000    S_IFMT          170000  ファイル種別フィールドのビットマスク
405 0000                    000000  T{
406 SCO では 使用不能 inode; BSD では不明なファイル種別;
407 SVID\-v2 と XPG2 では 0 と 0100000 の両方が通常のファイル
408 T}
409 1000    S_IFIFO p|      010000  FIFO (名前付きパイプ)
410 2000    S_IFCHR c       020000  キャラクタ特殊ファイル (V7)
411 3000    S_IFMPC         030000  多重化されたキャラクタ特殊ファイル (V7)
412 4000    S_IFDIR d/      040000  ディレクトリ (V7)
413 5000    S_IFNAM         050000  T{
414 XENIX の二つの副型を持つ名前付きの特殊ファイル
415 副型は \fIst_rdev\fP の値 1, 2 で区別される
416 T}
417 0001    S_INSEM s       000001  XENIX の IFNAM セマフォ副型
418 0002    S_INSHD m       000002  XENIX の IFNAM 共有データ副型
419 6000    S_IFBLK b       060000  ブロック特殊ファイル (V7)
420 7000    S_IFMPB         070000  多重化されたブロック特殊ファイル (V7)
421 8000    S_IFREG \-      100000  通常ファイル (V7)
422 9000    S_IFCMP         110000  VxFS 圧縮ファイル
423 9000    S_IFNWK n       110000  ネットワーク特殊ファイル (HP\-UX)
424 a000    S_IFLNK l@      120000  シンボリックリンク (BSD)
425 b000    S_IFSHAD                130000  T{
426 Solaris の ACL 用の隠し inode (ユーザ空間からは見えない)
427 T}
428 c000    S_IFSOCK        s=      140000  ソケット (BSD; VxFS の "S_IFSOC")
429 d000    S_IFDOOR        D>      150000  Solaris の door ファイル
430 e000    S_IFWHT w%      160000  BSD の空白ファイル (inode を使用しない)
431 0200    S_ISVTX         001000  T{
432 スティッキービット: 使用後もスワップに残す (V7)
433 .br
434 予約 (SVID\-v2)
435 .br
436 ディレクトリ以外: ファイルをキャッシュしない (SunOS)
437 .br
438 ディレクトリの場合: 削除制限フラグ (SVID\-v4.2)
439 T}
440 0400    S_ISGID         002000  T{
441 実行時の set\-group\-ID (V7)
442 .br
443 ディレクトリの場合: GID の伝搬に BSD 方式を使用する
444 T}
445 0400    S_ENFMT         002000  T{
446 System V ファイルロックを強制する (S_ISGID と共有)
447 T}
448 0800    S_ISUID         004000  実行時の set\-user\-ID (V7)
449 0800    S_CDF           004000  T{
450 ディレクトリがコンテキスト依存ファイル (HP\-UX)
451 T}
452 .TE
453 .ad
454
455 スティッキー コマンドは Version 32V AT&T UNIX で登場した。
456 .SH 注意
457 Linux では、 \fBlstat\fP() は一般には自動マウント動作 (automounter action) の
458 きっかけとならないが、 \fBstat\fP() はきっかけとなる (\fBfstatat\fP(2) を参照)。
459
460 \fI/proc\fP ディレクトリ以下にあるファイルのほとんどでは、 \fBstat\fP()  を呼び出した際に、 \fIst_size\fP
461 フィールドにファイルサイズが返されない。 代わりに \fIst_size\fP フィールドには 0 が返される。
462 .SS タイムスタンプフィールド
463 Older kernels and older standards did not support nanosecond timestamp
464 fields.  Instead, there were three timestamp fields\(em\fIst_atime\fP,
465 \fIst_mtime\fP, and \fIst_ctime\fP\(emtyped as \fItime_t\fP that recorded timestamps
466 with one\-second precision.
467
468 カーネル 2.5.48 以降では、 \fIstat\fP 構造体は 3 つのファイルのタイムスタンプ関連のフィールドでナノ秒単位の精度に対応している。
469 機能検査マクロ \fB_BSD_SOURCE\fP か \fB_SVID_SOURCE\fP が定義された場合に、各タイムスタンプのナノ秒の情報は
470 \fIst_atim.tv_nsec\fP という形式の名前で参照できる。 ナノ秒のタイムスタンプは現在では標準化されており、 POSIX.1\-2008
471 からである。 バージョン 2.12 以降の glibc では、 \fB_POSIX_C_SOURCE\fP が 200809L 以上の値で定義されるか、
472 \fB_XOPEN_SOURCE\fP が 700 以上の値で定義された場合にも、 このナノ秒のタイムスタンプが公開される。
473 上記のマクロのいずれも定義されていない場合、ナノ秒の値は \fIst_atimensec\fP という形式の名前で公開される。
474
475 .\" commit ef7f38359ea8b3e9c7f2cae9a4d4935f55ca9e80
476 Nanosecond timestamps are supported on XFS, JFS, Btrfs, and ext4 (since
477 Linux 2.6.23).  Nanosecond timestamps are not supported in ext2, ext3, and
478 Resierfs.  On filesystems that do not support subsecond timestamps, the
479 nanosecond fields are returned with the value 0.
480 .SS 背後のカーネル・インタフェース
481 .\"
482 .\" A note from Andries Brouwer, July 2007
483 .\"
484 .\" > Is the story not rather more complicated for some calls like
485 .\" > stat(2)?
486 .\"
487 .\" Yes and no, mostly no. See /usr/include/sys/stat.h .
488 .\"
489 .\" The idea is here not so much that syscalls change, but that
490 .\" the definitions of struct stat and of the types dev_t and mode_t change.
491 .\" This means that libc (even if it does not call the kernel
492 .\" but only calls some internal function) must know what the
493 .\" format of dev_t or of struct stat is.
494 .\" The communication between the application and libc goes via
495 .\" the include file <sys/stat.h> that defines a _STAT_VER and
496 .\" _MKNOD_VER describing the layout of the data that user space
497 .\" uses. Each (almost each) occurrence of stat() is replaced by
498 .\" an occurrence of xstat() where the first parameter of xstat()
499 .\" is this version number _STAT_VER.
500 .\"
501 .\" Now, also the definitions used by the kernel change.
502 .\" But glibc copes with this in the standard way, and the
503 .\" struct stat as returned by the kernel is repacked into
504 .\" the struct stat as expected by the application.
505 .\" Thus, _STAT_VER and this setup cater for the application-libc
506 .\" interface, rather than the libc-kernel interface.
507 .\"
508 .\" (Note that the details depend on gcc being used as c compiler.)
509 時間の経過とともに、 \fIstat\fP 構造体のサイズが大きくなり、この影響で \fBstat\fP()  には 3つのバージョンが存在する:
510 \fIsys_stat\fP()  (スロットは \fI__NR_oldstat\fP)、 \fIsys_newstat\fP()  (スロットは
511 \fI__NR_stat\fP)、 \fIsys_stat64\fP()  (カーネル 2.4 で導入; スロットは \fI__NR_stat64\fP).  glibc
512 の \fBstat\fP()  ラッパー関数はこれらの詳細をアプリケーションから隠蔽してくれる。
513 具体的には、カーネルが提供しているシステムコールのうち最新のバージョンを 起動し、古いバイナリの場合には必要に応じて返された情報を再構成
514 (repack) する。 \fBfstat\fP()  と \fBlstat\fP()  についても同様である。
515
516 glibc の \fBfstatat\fP() ラッパー関数が内部で利用するシステムコールは、実際には \fBfstatat64\fP() である。
517 .SH 例
518 以下のプログラムは \fBstat\fP()  を呼び出し、返ってきた \fIstat\fP 構造体のフィールドのいくつかを表示する。
519 .nf
520
521 #include <sys/types.h>
522 #include <sys/stat.h>
523 #include <time.h>
524 #include <stdio.h>
525 #include <stdlib.h>
526
527 int
528 main(int argc, char *argv[])
529 {
530     struct stat sb;
531
532     if (argc != 2) {
533         fprintf(stderr, "Usage: %s <pathname>\en", argv[0]);
534         exit(EXIT_FAILURE);
535     }
536
537     if (stat(argv[1], &sb) == \-1) {
538         perror("stat");
539         exit(EXIT_FAILURE);
540     }
541
542     printf("File type:                ");
543
544     switch (sb.st_mode & S_IFMT) {
545     case S_IFBLK:  printf("block device\en");            break;
546     case S_IFCHR:  printf("character device\en");        break;
547     case S_IFDIR:  printf("directory\en");               break;
548     case S_IFIFO:  printf("FIFO/pipe\en");               break;
549     case S_IFLNK:  printf("symlink\en");                 break;
550     case S_IFREG:  printf("regular file\en");            break;
551     case S_IFSOCK: printf("socket\en");                  break;
552     default:       printf("unknown?\en");                break;
553     }
554
555     printf("I\-node number:            %ld\en", (long) sb.st_ino);
556
557     printf("Mode:                     %lo (octal)\en",
558             (unsigned long) sb.st_mode);
559
560     printf("Link count:               %ld\en", (long) sb.st_nlink);
561     printf("Ownership:                UID=%ld   GID=%ld\en",
562             (long) sb.st_uid, (long) sb.st_gid);
563
564     printf("Preferred I/O block size: %ld bytes\en",
565             (long) sb.st_blksize);
566     printf("File size:                %lld bytes\en",
567             (long long) sb.st_size);
568     printf("Blocks allocated:         %lld\en",
569             (long long) sb.st_blocks);
570
571     printf("Last status change:       %s", ctime(&sb.st_ctime));
572     printf("Last file access:         %s", ctime(&sb.st_atime));
573     printf("Last file modification:   %s", ctime(&sb.st_mtime));
574
575     exit(EXIT_SUCCESS);
576 }
577 .fi
578 .SH 関連項目
579 \fBls\fP(1), \fBstat\fP(1), \fBaccess\fP(2), \fBchmod\fP(2), \fBchown\fP(2),
580 \fBreadlink\fP(2), \fButime\fP(2), \fBcapabilities\fP(7), \fBsymlink\fP(7)
581 .SH この文書について
582 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.65 の一部
583 である。プロジェクトの説明とバグ報告に関する情報は
584 http://www.kernel.org/doc/man\-pages/ に書かれている。