OSDN Git Service

0dd06f994c86afcc5394ac7ccdce44a9527be947
[linuxjm/LDP_man-pages.git] / draft / man2 / stat.2
1 '\" t
2 .\" Hey Emacs! This file is -*- nroff -*- source.
3 .\"
4 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
5 .\" Parts Copyright (c) 1995 Nicolai Langfeldt (janl@ifi.uio.no), 1/1/95
6 .\" and Copyright (c) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
7 .\"
8 .\" Permission is granted to make and distribute verbatim copies of this
9 .\" manual provided the copyright notice and this permission notice are
10 .\" preserved on all copies.
11 .\"
12 .\" Permission is granted to copy and distribute modified versions of this
13 .\" manual under the conditions for verbatim copying, provided that the
14 .\" entire resulting derived work is distributed under the terms of a
15 .\" permission notice identical to this one.
16 .\"
17 .\" Since the Linux kernel and libraries are constantly changing, this
18 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
19 .\" responsibility for errors or omissions, or for damages resulting from
20 .\" the use of the information contained herein.  The author(s) may not
21 .\" have taken the same level of care in the production of this manual,
22 .\" which is licensed free of charge, as they might when working
23 .\" professionally.
24 .\"
25 .\" Formatted or processed versions of this manual, if unaccompanied by
26 .\" the source, must acknowledge the copyright and authors of this work.
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 .\" Japanese Version Copyright (c) 1998-1999 HANATAKA Shinya
41 .\" and Copyright (c) 2005-2008 Akihiro MOTOKI
42 .\"
43 .\" Translated 1998-06-21, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
44 .\" Modified 1999-04-16, HANATAKA Shinya
45 .\" Updated 2000-01-03, Kentaro Shirakata <argrath@ub32.org>
46 .\" Updated 2000-10-06, Kentaro Shirakata
47 .\" Updated 2001-04-09, Kentaro Shirakata
48 .\" Updated 2001-06-25, Kentaro Shirakata
49 .\" Updated 2005-02-28, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
50 .\" Updated 2005-09-06, Akihiro MOTOKI
51 .\" Updated 2005-11-19, Akihiro MOTOKI, catch up to LDP v2.14
52 .\" Updated 2006-07-21, Akihiro MOTOKI, LDP v2.36
53 .\" Updated 2007-06-13, Akihiro MOTOKI, LDP v2.55
54 .\" Updated 2008-09-19, Akihiro MOTOKI, LDP v3.08
55 .\"
56 .\"WORD:        status                  状態
57 .\"WORD:        directory               ディレクトリ
58 .\"WORD:        open                    オープン
59 .\"WORD:        implement               実装
60 .\"WORD:        owner                   所有者
61 .\"WORD:        group                   グループ
62 .\"WORD:        user                    ユーザー
63 .\"WORD:        other                   他人
64 .\"WORD:        hard link count         ハード・リンク数
65 .\"WORD:        symbolic link           シンボリック・リンク
66 .\"WORD:        socket                  ソケット
67 .\"WORD:        device                  デバイス
68 .\"WORD:        sticky bit              スティッキー・ビット
69 .\"WORD:        mandatory locking       強制ロック
70 .\"
71 .TH STAT 2 2010-12-03 "Linux" "Linux Programmer's Manual"
72 .\"O .SH NAME
73 .SH 名前
74 .\"O stat, fstat, lstat \- get file status
75 stat, fstat, lstat \- ファイルの状態を取得する
76 .\"O .SH SYNOPSIS
77 .SH 書式
78 .B #include <sys/types.h>
79 .br
80 .B #include <sys/stat.h>
81 .br
82 .B #include <unistd.h>
83 .sp
84 .BI "int stat(const char *" path ", struct stat *" buf );
85 .br
86 .BI "int fstat(int " fd ", struct stat *" buf );
87 .br
88 .BI "int lstat(const char *" path ", struct stat *" buf );
89 .sp
90 .in -4n
91 .\"O Feature Test Macro Requirements for glibc (see
92 .\"O .BR feature_test_macros (7)):
93 glibc 向けの機能検査マクロの要件
94 .RB ( feature_test_macros (7)
95 参照):
96 .in
97 .sp
98 .BR lstat ():
99 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500
100 .\"O .SH DESCRIPTION
101 .SH 説明
102 .PP
103 .\"O These functions return information about a file.
104 .\"O No permissions are required on the file itself, but \(em in the case of
105 .\"O .BR stat ()
106 .\"O and
107 .\"O .BR lstat ()
108 .\"O \(em
109 .\"O execute (search) permission is required on all of the directories in
110 .\"O .I path
111 .\"O that lead to the file.
112 これらの関数はファイルについての情報を返す。
113 ファイルそのものに対するアクセス許可は必要としないが、
114 \(em
115 .BR stat ()
116
117 .BR lstat ()
118 の場合には
119 \(em
120 そのファイルへ至る
121 .I path
122 を構成する全てのディレクトリに対する実行 (検索) 許可が必要である。
123 .PP
124 .\"O .BR stat ()
125 .\"O stats the file pointed to by
126 .\"O .I path
127 .\"O and fills in
128 .\"O .IR buf .
129 .BR stat ()
130
131 .I path
132 で指定されたファイルの状態を取得して
133 .I buf
134 へ格納する。
135
136 .\"O .BR lstat ()
137 .\"O is identical to
138 .\"O .BR stat (),
139 .\"O except that if
140 .\"O .I path
141 .\"O is a symbolic link, then the link itself is stat-ed,
142 .\"O not the file that it refers to.
143 .BR lstat ()
144
145 .BR stat ()
146 と同じであるが、
147 .I path
148 がシンボリックリンクの場合、リンクが参照しているファイルではなく、
149 リンク自身の状態を取得する点が異なる。
150
151 .\"O .BR fstat ()
152 .\"O is identical to
153 .\"O .BR stat (),
154 .\"O except that the file to be stat-ed is specified by the file descriptor
155 .\"O .IR fd .
156 .BR fstat ()
157
158 .BR stat ()
159 と同じだが、
160 状態を取得するファイルをファイル・ディスクリプタ
161 .I fd
162 で指定する。
163 .PP
164 .\"O All of these system calls return a
165 .\"O .I stat
166 .\"O structure, which contains the following fields:
167 これらのシステムコールはいずれも、結果を
168 .I stat
169 構造体に入れて返す。
170 .I stat
171 構造体には以下のフィールドが含まれている:
172 .PP
173 .in +4n
174 .nf
175 struct stat {
176 .\"O     dev_t     st_dev;     /* ID of device containing file */
177 .\"O     ino_t     st_ino;     /* inode number */
178 .\"O     mode_t    st_mode;    /* protection */
179 .\"O     nlink_t   st_nlink;   /* number of hard links */
180 .\"O     uid_t     st_uid;     /* user ID of owner */
181 .\"O     gid_t     st_gid;     /* group ID of owner */
182 .\"O     dev_t     st_rdev;    /* device ID (if special file) */
183 .\"O     off_t     st_size;    /* total size, in bytes */
184 .\"O     blksize_t st_blksize; /* blocksize for file system I/O */
185 .\"O     blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
186 .\"O     time_t    st_atime;   /* time of last access */
187 .\"O     time_t    st_mtime;   /* time of last modification */
188 .\"O     time_t    st_ctime;   /* time of last status change */
189     dev_t     st_dev;     /* ファイルがあるデバイスの ID */
190     ino_t     st_ino;     /* inode 番号 */
191     mode_t    st_mode;    /* アクセス保護 */
192     nlink_t   st_nlink;   /* ハードリンクの数 */
193     uid_t     st_uid;     /* 所有者のユーザ ID */
194     gid_t     st_gid;     /* 所有者のグループ ID */
195     dev_t     st_rdev;    /* デバイス ID (特殊ファイルの場合) */
196     off_t     st_size;    /* 全体のサイズ (バイト単位) */
197     blksize_t st_blksize; /* ファイルシステム I/O での
198                              ブロックサイズ */
199     blkcnt_t  st_blocks;  /* 割り当てられた 512B のブロック数 */
200     time_t    st_atime;   /* 最終アクセス時刻 */
201     time_t    st_mtime;   /* 最終修正時刻 */
202     time_t    st_ctime;   /* 最終状態変更時刻 */
203 };
204 .fi
205 .in
206 .PP
207 .\"O The
208 .\"O .I st_dev
209 .\"O field describes the device on which this file resides.
210 .\"O (The
211 .\"O .BR major (3)
212 .\"O and
213 .\"O .BR minor (3)
214 .\"O macros may be useful to decompose the device ID in this field.)
215 .I st_dev
216 フィールドは、このファイルが存在するデバイスを示す
217 (マクロ
218 .BR major (3),
219 .BR minor (3)
220 は、このフィールドのデバイス ID を分解するのに役立つだろう)。
221
222 .\"O The
223 .\"O .I st_rdev
224 .\"O field describes the device that this file (inode) represents.
225 .I st_rdev
226 フィールドは、このファイル (inode) が表すデバイスを示す。
227
228 .\"O The
229 .\"O .I st_size
230 .\"O field gives the size of the file (if it is a regular
231 .\"O file or a symbolic link) in bytes.
232 .\"O The size of a symlink is the length of the pathname
233 .\"O it contains, without a trailing null byte.
234 .I st_size
235 フィールドは、(通常のファイルかシンボリックリンクの場合に)
236 ファイルの大きさをバイト単位で示す。
237 シンボリックリンクの大きさは、シンボリックリンクに含まれている
238 パス名の長さ (最後の NULL バイトは含まない) である。
239
240 .\"O The
241 .\"O .I st_blocks
242 .\"O field indicates the number of blocks allocated to the file, 512-byte units.
243 .\"O (This may be smaller than
244 .\"O .IR st_size /512
245 .\"O when the file has holes.)
246 .I st_blocks
247 フィールドは、ファイルの大きさを 512 バイトのブロックサイズ単位で示す
248 フィールドは、ファイルに割り当てされたブロック数を 512 バイト単位で示す。
249 (ファイルに穴があるような場合、この値は
250 .IR st_size /512
251 より小さくなることもある)。
252
253 .\"O The
254 .\"O .I st_blksize
255 .\"O field gives the "preferred" blocksize for efficient file system I/O.
256 .\"O (Writing to a file in smaller chunks may cause
257 .\"O an inefficient read-modify-rewrite.)
258 .I st_blksize
259 フィールドは、効率的にファイル・システム I/O ができる「好ましい」
260 ブロックサイズを示す (もっと小さい単位でファイルに書き込みを行うと、
261 読み出し--修正--再書き込みといった非効率な動作になってしまうかもしれない)。
262 .PP
263 .\"O Not all of the Linux file systems implement all of the time fields.
264 .\"O Some file system types allow mounting in such a way that file
265 .\"O and/or directory accesses do not cause an update of the
266 .\"O .I st_atime
267 .\"O field.
268 .\"O (See
269 .\"O .IR noatime ,
270 .\"O .IR nodiratime ,
271 .\"O and
272 .\"O .I relatime
273 .\"O in
274 .\"O .BR mount (8),
275 .\"O and related information in
276 .\"O .BR mount (2).)
277 全ての Linux のファイル・システムが全ての時間フィールドを
278 実装しているわけではない。
279 ファイルやディレクトリのアクセスが
280 .I st_atime
281 フィールドを更新しないようなかたちでマウントできるファイルシステムもある。
282 .RB ( mount (8)
283
284 .IR noatime ,
285 .IR nodiratime ,
286 .I relatime
287
288 .BR mount (2)
289 の関連する情報を参照)。
290 .\"O In addition,
291 .\"O .I st_atime
292 .\"O is not updated if a file is opened with the
293 .\"O .BR O_NOATIME ;
294 .\"O see
295 .\"O .BR open (2).
296 また、ファイルが
297 .B O_NOATIME
298 付きでオープンされている場合には
299 .I st_atime
300 は更新されない。
301 .BR open (2)
302 参照。
303
304 .\"O The field
305 .\"O .I st_atime
306 .\"O is changed by file accesses, for example, by
307 .\"O .BR execve (2),
308 .\"O .BR mknod (2),
309 .\"O .BR pipe (2),
310 .\"O .BR utime (2)
311 .\"O and
312 .\"O .BR read (2)
313 .\"O (of more than zero bytes).
314 .\"O Other routines, like
315 .\"O .BR mmap (2),
316 .\"O may or may not update
317 .\"O .IR st_atime .
318 .I st_atime
319 フィールドはファイルアクセスがあった場合に変更される
320 (例えば、
321 .BR execve (2),
322 .BR mknod (2),
323 .BR pipe (2),
324 .BR utime (2)
325 を使用した場合や
326 .BR read (2)
327 で 1 バイト以上読み込んだ場合など)。
328 .BR mmap (2)
329 などの他のルーチンでは、
330 .I st_atime
331 は更新されることもあれば、そうでない場合もある。
332
333 .\"O The field
334 .\"O .I st_mtime
335 .\"O is changed by file modifications, for example, by
336 .\"O .BR mknod (2),
337 .\"O .BR truncate (2),
338 .\"O .BR utime (2)
339 .\"O and
340 .\"O .BR write (2)
341 .\"O (of more than zero bytes).
342 .I st_mtime
343 フィールドは、ファイルが修正された場合に変更される
344 (例えば、
345 .BR mknod (2),
346 .BR truncate (2),
347 .BR utime (2)
348 を使用した場合や
349 .BR write (2)
350 で 1 バイト以上書き込みをした場合など)。
351 .\"O Moreover,
352 .\"O .I st_mtime
353 .\"O of a directory is changed by the creation or deletion of files
354 .\"O in that directory.
355 さらに、ディレクトリの
356 .I st_mtime
357 は、そのディレクトリで
358 ファイルが作成されたり削除されたりすると変更される。
359 .\"O The
360 .\"O .I st_mtime
361 .\"O field is
362 .\"O .I not
363 .\"O changed for changes in owner, group, hard link count, or mode.
364 .I st_mtime
365 フィールドは
366 所有者やグループやハード・リンク数やモードの変更では変更
367 .I されない。
368
369 .\"O The field
370 .\"O .I st_ctime
371 .\"O is changed by writing or by setting inode information
372 .\"O (i.e., owner, group, link count, mode, etc.).
373 .I st_ctime
374 フィールドは書き込みや inode 情報
375 (所有者、グループ、リンク数、モードなど) の
376 設定によって変更される。
377 .PP
378 .\"O The following POSIX macros are defined to check the file type using the
379 .\"O .I st_mode
380 .\"O field:
381 以下の POSIX マクロは、
382 .I st_mode
383 フィールド
384 で使用されるファイル種別のチェックのために定義されている :
385 .RS 4
386 .TP 1.2i
387 .BR S_ISREG (m)
388 .\"O is it a regular file?
389 通常のファイルか?
390 .TP
391 .BR S_ISDIR (m)
392 .\"O directory?
393 ディレクトリか?
394 .TP
395 .BR S_ISCHR (m)
396 .\"O character device?
397 キャラクター・デバイスか?
398 .TP
399 .BR S_ISBLK (m)
400 .\"O block device?
401 ブロック・デバイスか?
402 .TP
403 .BR S_ISFIFO (m)
404 .\"O FIFO (named pipe)?
405 FIFO (名前付きパイプ) か?
406 .TP
407 .BR S_ISLNK (m)
408 .\"O symbolic link? (Not in POSIX.1-1996.)
409 シンボリック・リンクか? (POSIX.1-1996 にはない)
410 .TP
411 .BR S_ISSOCK (m)
412 .\"O socket? (Not in POSIX.1-1996.)
413 ソケットか? (POSIX.1-1996 にはない)
414 .RE
415 .PP
416 .\"O The following flags are defined for the
417 .\"O .I st_mode
418 .\"O field:
419 以下のフラグが
420 .I st_mode
421 フィールド用に定義されている:
422 .in +4n
423 .TS
424 lB l l.
425 .\"O S_IFMT     0170000 bit mask for the file type bit fields
426 .\"O S_IFSOCK   0140000 socket
427 .\"O S_IFLNK    0120000 symbolic link
428 .\"O S_IFREG    0100000 regular file
429 .\"O S_IFBLK    0060000 block device
430 .\"O S_IFDIR    0040000 directory
431 .\"O S_IFCHR    0020000 character device
432 .\"O S_IFIFO    0010000 FIFO
433 S_IFMT  0170000 ファイル種別を示すビット領域を表すビットマスク
434 S_IFSOCK        0140000 ソケット
435 S_IFLNK 0120000 シンボリック・リンク
436 S_IFREG 0100000 通常のファイル
437 S_IFBLK 0060000 ブロック・デバイス
438 S_IFDIR 0040000 ディレクトリ
439 S_IFCHR 0020000 キャラクター・デバイス
440 S_IFIFO 0010000 FIFO
441 .\"O S_ISUID    0004000 set-user-ID bit
442 .\"O S_ISGID    0002000 set-group-ID bit (see below)
443 .\"O S_ISVTX    0001000 sticky bit (see below)
444 S_ISUID 0004000 set-user-ID bit
445 S_ISGID 0002000 set-group-ID bit (下記参照)
446 S_ISVTX 0001000 スティッキー・ビット (下記参照)
447 .\"O S_IRWXU    00700   mask for file owner permissions
448 .\"O S_IRUSR    00400   owner has read permission
449 .\"O S_IWUSR    00200   owner has write permission
450 .\"O S_IXUSR    00100   owner has execute permission
451 S_IRWXU 00700   ファイル所有者のアクセス許可用のビットマスク
452 S_IRUSR 00400   所有者の読み込み許可
453 S_IWUSR 00200   所有者の書き込み許可
454 S_IXUSR 00100   所有者の実行許可
455 .\"O S_IRWXG    00070   mask for group permissions
456 .\"O S_IRGRP    00040   group has read permission
457 .\"O S_IWGRP    00020   group has write permission
458 .\"O S_IXGRP    00010   group has execute permission
459 S_IRWXG 00070   グループのアクセス許可用のビットマスク
460 S_IRGRP 00040   グループの読み込み許可
461 S_IWGRP 00020   グループの書き込み許可
462 S_IXGRP 00010   グループの実行許可
463 .\"O S_IRWXO    00007   mask for permissions for others (not in group)
464 .\"O S_IROTH    00004   others have read permission
465 .\"O S_IWOTH    00002   others have write permission
466 .\"O S_IXOTH    00001   others have execute permission
467 S_IRWXO 00007   他人 (others) のアクセス許可用のビットマスク
468 S_IROTH 00004   他人の読み込み許可
469 S_IWOTH 00002   他人の書き込み許可
470 S_IXOTH 00001   他人の実行許可
471 .TE
472 .in
473 .P
474 .\"O The set-group-ID bit
475 .\"O .RB ( S_ISGID )
476 .\"O has several special uses.
477 .\"O For a directory it indicates that BSD semantics is to be used
478 .\"O for that directory: files created there inherit their group ID from
479 .\"O the directory, not from the effective group ID of the creating process,
480 .\"O and directories created there will also get the
481 .\"O .B S_ISGID
482 .\"O bit set.
483 .\"O For a file that does not have the group execution bit
484 .\"O .RB ( S_IXGRP )
485 .\"O set,
486 .\"O the set-group-ID bit indicates mandatory file/record locking.
487 set-group-ID bit
488 .RB ( S_ISGID )
489 にはいくつかの特殊な使用法がある:
490 ディレクトリに設定した場合には、そのディレクトリが BSD 方式で使用される
491 ことを示す。つまり、そのディレクトリに作成されたファイルのグループID は
492 作成したプロセスの実効 (effective) グループID ではなく、ディレクトリの
493 グループID を継承する。また、そのディレクトリに作成されたディレクトリにも
494 .B S_ISGID
495 ビットが設定される。グループ実行ビット
496 .RB ( S_IXGRP )
497 が設定されていないファイルに設定された場合は、
498 set-group-ID ビットはファイル/レコードの
499 強制的な (mandatory) ロックを表す。
500 .P
501 .\"O The sticky bit (S_ISVTX) on a directory means that a file
502 .\"O in that directory can be renamed or deleted only by the owner
503 .\"O of the file, by the owner of the directory, and by a privileged
504 .\"O process.
505 ディレクトリにスティッキービット (S_ISVTX) が設定された場合は、
506 そのディレクトリのファイルの名前を変更したり、削除したりできるのは、
507 そのファイルの所有者か、そのディレクトリの所有者か、特権プロセス
508 だけとなる。
509 .\"O .SH "RETURN VALUE"
510 .SH 返り値
511 .\"O On success, zero is returned.
512 .\"O On error, \-1 is returned, and
513 .\"O .I errno
514 .\"O is set appropriately.
515 成功した場合は 0 を返す。エラーの場合は \-1 を返し、
516 .I errno
517 に適切な値が設定される。
518 .\"O .SH ERRORS
519 .SH エラー
520 .TP
521 .B EACCES
522 .\"O Search permission is denied for one of the directories
523 .\"O in the path prefix of
524 .\"O .IR path .
525 .\"O (See also
526 .\"O .BR path_resolution (7).)
527 .I path
528 が所属するディレクトリとその上位のディレクトリのいずれかに
529 対する検索許可がなかった
530 .RB ( path_resolution (7)
531 も参照のこと)。
532 .TP
533 .B EBADF
534 .\"O .I fd
535 .\"O is bad.
536 .I fd
537 が不正である。
538 .TP
539 .B EFAULT
540 .\"O Bad address.
541 アドレスが間違っている。
542 .TP
543 .B ELOOP
544 .\"O Too many symbolic links encountered while traversing the path.
545 パスを辿る際に解決すべきシンボリック・リンクが多過ぎた。
546 .TP
547 .B ENAMETOOLONG
548 .\"O .I path
549 .\"O is too long.
550 .I path
551 が長過ぎる。
552 .TP
553 .B ENOENT
554 .\"O A component of
555 .\"O .I path
556 .\"O does not exist, or
557 .\"O .I path
558 .\"O is an empty string.
559 .I path
560 の構成要素が存在しないか、
561 .I path
562 が空文字列である。
563 .TP
564 .B ENOMEM
565 .\"O Out of memory (i.e., kernel memory).
566 カーネルのメモリが足りない。
567 .TP
568 .B ENOTDIR
569 .\"O A component of the path prefix of
570 .\"O .I path
571 .\"O is not a directory.
572 .I path
573 の前半部分 (prefix) の構成要素がディレクトリではない。
574 .TP
575 .B EOVERFLOW
576 .\"O .RB ( stat ())
577 .\"O .I path
578 .\"O refers to a file whose size cannot be represented in the type
579 .\"O .IR off_t .
580 .\"O This can occur when an application compiled on a 32-bit platform without
581 .\"O .I -D_FILE_OFFSET_BITS=64
582 .\"O calls
583 .\"O .BR stat ()
584 .\"O on a file whose size exceeds
585 .\"O .I (1<<31)-1
586 .\"O bits.
587 .RB ( stat ())
588 .I path
589 が、ファイルサイズを
590 .I off_t
591 型で表現できないファイルを参照している。
592 このエラーが起こるのは、32 ビットプラットフォーム上で
593 .I -D_FILE_OFFSET_BITS=64
594 を指定せずにコンパイルされたアプリケーションが、ファイルサイズが
595 .I (1<31)-1
596 ビットを超えるファイルに対して
597 .BR stat ()
598 を呼び出した場合である。
599 .\"O .SH "CONFORMING TO"
600 .SH 準拠
601 .\"O These system calls conform to SVr4, 4.3BSD, POSIX.1-2001.
602 これらのシステムコールは SVr4, 4.3BSD, POSIX.1-2001 に準拠している。
603 .\"O .\" SVr4 documents additional
604 .\"O .\" .BR fstat ()
605 .\"O .\" error conditions EINTR, ENOLINK, and EOVERFLOW.  SVr4
606 .\"O .\" documents additional
607 .\"O .\" .BR stat ()
608 .\"O .\" and
609 .\"O .\" .BR lstat ()
610 .\"O .\" error conditions EINTR, EMULTIHOP, ENOLINK, and EOVERFLOW.
611 .BR stat ()
612
613 .BR fstat ()
614 コールは SVr4, SVID, POSIX, X/OPEN, 4.3BSD に準拠している。
615 .BR lstat ()
616 コールは 4.3BSD と SVr4 に準拠している。
617 .\" SVr4 には他に
618 .\" .BR fstat ()
619 .\" のエラーとして EINTR, ENOLINK, EOVERFLOW が記載されている。
620 .\" SVr4 には他に
621 .\" .BR stat ()
622 .\" と
623 .\" .BR lstat ()
624 .\" のエラーとして EINTR, EMULTIHOP, ENOLINK, EOVERFLOW が記載されている。
625
626 .\"O Use of the
627 .\"O .I st_blocks
628 .\"O and
629 .\"O .I st_blksize
630 .\"O fields may be less portable.
631 .\"O (They were introduced in BSD.
632 .\"O The interpretation differs between systems,
633 .\"O and possibly on a single system when NFS mounts are involved.)
634 .I st_blocks
635
636 .I st_blksize
637 フィールドの使用はあまり移植性がない。
638 (これらのフィールドは BSD によって導入された。
639 システムごとに解釈が異なっており、
640 NFS マウントの場合には同じシステムでも異なる可能性がある)
641 .LP
642 .\"O POSIX does not describe the
643 .\"O .BR S_IFMT ,
644 .\"O .BR S_IFSOCK ,
645 .\"O .BR S_IFLNK ,
646 .\"O .BR S_IFREG ,
647 .\"O .BR S_IFBLK ,
648 .\"O .BR S_IFDIR ,
649 .\"O .BR S_IFCHR ,
650 .\"O .BR S_IFIFO ,
651 .\"O .B S_ISVTX
652 .\"O bits, but instead demands the use of
653 .\"O the macros
654 .\"O .BR S_ISDIR (),
655 .\"O etc.
656 .\"O The
657 .\"O .BR S_ISLNK ()
658 .\"O and
659 .\"O .BR S_ISSOCK ()
660 .\"O macros are not in
661 .\"O POSIX.1-1996, but both are present in POSIX.1-2001;
662 .\"O the former is from SVID 4, the latter from SUSv2.
663 POSIX には
664 .BR S_IFMT ,
665 .BR S_IFSOCK ,
666 .BR S_IFLNK ,
667 .BR S_IFREG ,
668 .BR S_IFBLK ,
669 .BR S_IFDIR ,
670 .BR S_IFCHR ,
671 .BR S_IFIFO ,
672 .B S_ISVTX
673 ビットについての記述はない。かわりに
674 .BR S_ISDIR ()
675 のようなマクロを使用するように要求している。
676 マクロ
677 .BR S_ISLNK ()
678
679 .BR S_ISSOCK ()
680 は POSIX.1-1996 にはないが、
681 POSIX.1-2001 には両方とも存在する。
682 前者は SVID 4 に、後者は SUSv2 に由来している。
683 .LP
684 .\"O Unix V7 (and later systems) had S_IREAD, S_IWRITE, S_IEXEC, where POSIX
685 .\"O prescribes the synonyms S_IRUSR, S_IWUSR, S_IXUSR.
686 .\"O Unix V7 (and later systems) had
687 .\"O .BR S_IREAD ,
688 .\"O .BR S_IWRITE ,
689 .\"O .BR S_IEXEC ,
690 .\"O where POSIX
691 .\"O prescribes the synonyms
692 .\"O .BR S_IRUSR ,
693 .\"O .BR S_IWUSR ,
694 .\"O .BR S_IXUSR .
695 Unix V7 (とその後のシステム) は
696 .BR S_IREAD ,
697 .BR S_IWRITE ,
698 .B S_IEXEC
699 を持っており、
700 POSIX はその同義語として
701 .BR S_IRUSR ,
702 .BR S_IWUSR ,
703 .B S_IXUSR
704 を規定している。
705 .\"O .SS "Other Systems"
706 .SS 他のシステム
707 .\"O Values that have been (or are) in use on various systems:
708 各種システムで使用されていた(いる)値:
709 .TS
710 l l l l l.
711 .\"O hex        name    ls      octal   description
712 16進   名前  ls      8進数 説明
713 .\"O f000       S_IFMT          170000  mask for file type
714 .\"O 0000                       000000  SCO out-of-service inode, BSD unknown
715 .\"O                            type; SVID-v2 and XPG2 have both
716 .\"O                            0 and 0100000 for ordinary file
717 f000    S_IFMT          170000  ファイル種別フィールドのビットマスク
718 0000                    000000  SCO では 使用不能 inode;
719                                 BSD では未知のファイル種別;
720                                 SVID-v2 と XPG2 では 0 と 0100000 の
721                                 両方が普通のファイル
722 .\"O 1000       S_IFIFO p|      010000  FIFO (named pipe)
723 .\"O 2000       S_IFCHR c       020000  character special (V7)
724 .\"O 3000       S_IFMPC         030000  multiplexed character special (V7)
725 .\"O 4000       S_IFDIR d/      040000  directory (V7)
726 .\"O 5000       S_IFNAM         050000  XENIX named special file
727 .\"O                            with two subtypes, distinguished by
728 .\"O                            \fIst_rdev\fP values 1, 2
729 .\"O 0001       S_INSEM s       000001  XENIX semaphore subtype of IFNAM
730 .\"O 0002       S_INSHD m       000002  XENIX shared data subtype of IFNAM
731 1000    S_IFIFO p|      010000  FIFO (名前付きパイプ)
732 2000    S_IFCHR c       020000  キャラクタ特殊ファイル (V7)
733 3000    S_IFMPC         030000  多重化されたキャラクタ特殊ファイル (V7)
734 4000    S_IFDIR d/      040000  ディレクトリ (V7)
735 5000    S_IFNAM         050000  XENIX 二つの副型を持つ名前付きの
736                                 特殊ファイル
737                                 副型は \fIst_rdev\fP の値 1,2 で区別される:
738 0001    S_INSEM s       000001  XENIX IFNAMのセマフォー副型
739 0002    S_INSHD m       000002  XENIX IFNAMの共有データ副型
740 .\"O 6000       S_IFBLK b       060000  block special (V7)
741 .\"O 7000       S_IFMPB         070000  multiplexed block special (V7)
742 .\"O 8000       S_IFREG -       100000  regular (V7)
743 .\"O 9000       S_IFCMP         110000  VxFS compressed
744 .\"O 9000       S_IFNWK n       110000  network special (HP-UX)
745 .\"O a000       S_IFLNK l@      120000  symbolic link (BSD)
746 6000    S_IFBLK b       060000  ブロック特殊ファイル (V7)
747 7000    S_IFMPB         070000  多重化されたブロック特殊ファイル (V7)
748 8000    S_IFREG -       100000  通常ファイル (V7)
749 9000    S_IFCMP         110000  VxFS 圧縮ファイル
750 9000    S_IFNWK n       110000  ネットワーク特殊ファイル (HP-UX)
751 a000    S_IFLNK l@      120000  シンボリック・リンク (BSD)
752 .\"O b000       S_IFSHAD                130000  Solaris shadow inode for ACL
753 .\"O                            (not seen by userspace)
754 .\"O c000       S_IFSOCK        s=      140000  socket (BSD; also "S_IFSOC" on VxFS)
755 .\"O d000       S_IFDOOR        D>      150000  Solaris door
756 .\"O e000       S_IFWHT w%      160000  BSD whiteout (not used for inode)
757 b000    S_IFSHAD                130000  Solaris ACL のための隠された inode
758                                 (ユーザ空間からは見えない)
759 c000    S_IFSOCK        s=      140000  ソケット (BSD; VxFS の "S_IFSOC")
760 d000    S_IFDOOR        D>      150000  Solaris ドア・ファイル
761 e000    S_IFWHT w%      160000  BSD 空白ファイル (inode を使用しない)
762 .\"O 0200       S_ISVTX         001000  sticky bit: save swapped text even
763 .\"O                            after use (V7)
764 .\"O                            reserved (SVID-v2)
765 .\"O                            On nondirectories: don't cache this
766 .\"O                            file (SunOS)
767 .\"O                            On directories: restricted deletion
768 .\"O                            flag (SVID-v4.2)
769 .\"O 0400       S_ISGID         002000  set-group-ID on execution (V7)
770 .\"O                            for directories: use BSD semantics for
771 .\"O                            propagation of GID
772 .\"O 0400       S_ENFMT         002000  System V file locking enforcement (shared
773 .\"O                            with S_ISGID)
774 .\"O 0800       S_ISUID         004000  set-user-ID on execution (V7)
775 .\"O 0800       S_CDF           004000  directory is a context dependent
776 .\"O                            file (HP-UX)
777 0200    S_ISVTX         001000  `スティッキー・ビット':使用後も
778                                 スワップに残す (V7)
779                                 予約 (SVID-v2)
780                                 ディレクトリ以外: ファイルをキャッシュ
781                                 しない (SunOS)
782                                 ディレクトリ: 削除制限フラグ (SVID-v4.2)
783 0400    S_ISGID         002000  実行時の set-group-ID (V7)
784                                 ディレクトリに対しては GID の伝達に
785                                 BSD 方式を使用する
786 0400    S_ENFMT         002000  System V ファイル・ロックを強制する
787                                 (S_ISGID と共有)
788 0800    S_ISUID         004000  実行時の set-user-ID (V7)
789 0800    S_CDF           004000  ディレクトリが状況依存ファイル (HP-UX)
790 .TE
791
792 .\"O A sticky command appeared in Version 32V AT&T UNIX.
793 スティッキー コマンドは Version 32V AT&T UNIX で登場した。
794 .\"O .SH NOTES
795 .SH 注意
796 .\"O Since kernel 2.5.48, the
797 .\"O .I stat
798 .\"O structure supports nanosecond resolution for the three
799 .\"O file timestamp fields.
800 .\"O Glibc exposes the nanosecond component of each field using names either
801 .\"O of the form
802 .\"O .IR st_atim.tv_nsec ,
803 .\"O if the
804 .\"O .B _BSD_SOURCE
805 .\"O or
806 .\"O .B _SVID_SOURCE
807 .\"O feature test macro is defined,
808 .\"O or of the form
809 .\"O .IR st_atimensec ,
810 .\"O if neither of these macros is defined.
811 .\"O On file systems that do not support subsecond timestamps,
812 .\"O these nanosecond fields are returned with the value 0.
813 カーネル 2.5.48 以降では、
814 .I stat
815 構造体は 3つのファイルのタイムスタンプ関連のフィールドで
816 ナノ秒単位の精度に対応している。
817 glibc では、各フィールドのナノ秒の情報を
818 .I st_atim.tv_nsec
819
820 .I st_atimensec
821 といった形で参照できる。
822 機能検査マクロ
823 .B _BSD_SOURCE
824
825 .B _SVID_SOURCE
826 が定義されている場合には
827 .I st_atim.tv_nsec
828 の形式で、それ以外の場合には
829 .I st_atimensec
830 の形式となる。
831 秒より細かいタイムスタンプをサポートしていないファイルシステムでは、
832 これらのナノ秒のフィールドは 0 に設定される。
833 .\" As at kernel 2.6.25, XFS and JFS support nanosecond timestamps,
834 .\" but ext2, ext3, and Reiserfs do not.
835 .\" FIXME . SUSv4 specifies nanosecond timestamps.
836
837 .\"O On Linux,
838 .\"O .BR lstat ()
839 .\"O will generally not trigger automounter action, whereas
840 .\"O .BR stat ()
841 .\"O will.
842 Linux では、
843 .BR lstat ()
844 は一般には自動マウント動作 (automounter action) のきっかけとならないが、
845 .BR stat ()
846 はきっかけとなる。
847
848 .\"O For most files under the
849 .\"O .I /proc
850 .\"O directory,
851 .\"O .BR stat ()
852 .\"O does not return the file size in the
853 .\"O .I st_size
854 .\"O field; instead the field is returned with the value 0.
855 .I /proc
856 ディレクトリ以下にあるファイルのほとんどでは、
857 .BR stat ()
858 を呼び出した際に、
859 .I st_size
860 フィールドにファイルサイズが返されない。
861 代わりに
862 .I st_size
863 フィールドには 0 が返される。
864 .\"O .SS Underlying kernel interface
865 .SS 背後のカーネル・インタフェース
866 .\"O Over time, increases in the size of the
867 .\"O .I stat
868 .\"O structure have led to three successive versions of
869 .\"O .BR stat ():
870 時間の経過とともに、
871 .I stat
872 構造体のサイズが大きくなり、この影響で
873 .BR stat ()
874 には 3つのバージョンが存在する:
875 .\"O .IR sys_stat ()
876 .\"O (slot
877 .\"O .IR __NR_oldstat ),
878 .\"O .IR sys_newstat ()
879 .\"O (slot
880 .\"O .IR __NR_stat ),
881 .\"O and
882 .\"O .I sys_stat64()
883 .\"O (new in kernel 2.4; slot
884 .\"O .IR __NR_stat64 ).
885 .IR sys_stat ()
886 (スロットは
887 .IR __NR_oldstat )、
888 .IR sys_newstat ()
889 (スロットは
890 .IR __NR_stat )、
891 .IR sys_stat64 ()
892 (カーネル 2.4 で導入; スロットは
893 .IR __NR_stat64 ).
894 .\"O The glibc
895 .\"O .BR stat ()
896 .\"O wrapper function hides these details from applications,
897 .\"O invoking the most recent version of the system call provided by the kernel,
898 .\"O and repacking the returned information if required for old binaries.
899 glibc の
900 .BR stat ()
901 ラッパー関数はこれらの詳細をアプリケーションから隠蔽してくれる。
902 具体的には、カーネルが提供しているシステムコールのうち最新のバージョンを
903 起動し、古いバイナリの場合には必要に応じて返された情報を再構成 (repack) する。
904 .\"O Similar remarks apply for
905 .\"O .BR fstat ()
906 .\"O and
907 .\"O .BR lstat ().
908 .BR fstat ()
909
910 .BR lstat ()
911 についても同様である。
912 .\"
913 .\" A note from Andries Brouwer, July 2007
914 .\"
915 .\" > Is the story not rather more complicated for some calls like
916 .\" > stat(2)?
917 .\"
918 .\" Yes and no, mostly no. See /usr/include/sys/stat.h .
919 .\"
920 .\" The idea is here not so much that syscalls change, but that
921 .\" the definitions of struct stat and of the types dev_t and mode_t change.
922 .\" This means that libc (even if it does not call the kernel
923 .\" but only calls some internal function) must know what the
924 .\" format of dev_t or of struct stat is.
925 .\" The communication between the application and libc goes via
926 .\" the include file <sys/stat.h> that defines a _STAT_VER and
927 .\" _MKNOD_VER describing the layout of the data that user space
928 .\" uses. Each (almost each) occurrence of stat() is replaced by
929 .\" an occurrence of xstat() where the first parameter of xstat()
930 .\" is this version number _STAT_VER.
931 .\"
932 .\" Now, also the definitions used by the kernel change.
933 .\" But glibc copes with this in the standard way, and the
934 .\" struct stat as returned by the kernel is repacked into
935 .\" the struct stat as expected by the application.
936 .\" Thus, _STAT_VER and this setup cater for the application-libc
937 .\" interface, rather than the libc-kernel interface.
938 .\"
939 .\" (Note that the details depend on gcc being used as c compiler.)
940 .\"O .SH EXAMPLE
941 .SH 例
942 .\"O The following program calls
943 .\"O .BR stat ()
944 .\"O and displays selected fields in the returned
945 .\"O .I stat
946 .\"O structure.
947 以下のプログラムは
948 .BR stat ()
949 を呼び出し、返ってきた
950 .I stat
951 構造体のフィールドのいくつかを表示する。
952 .nf
953
954 #include <sys/types.h>
955 #include <sys/stat.h>
956 #include <time.h>
957 #include <stdio.h>
958 #include <stdlib.h>
959
960 int
961 main(int argc, char *argv[])
962 {
963     struct stat sb;
964
965     if (argc != 2) {
966         fprintf(stderr, "Usage: %s <pathname>\\n", argv[0]);
967         exit(EXIT_FAILURE);
968     }
969
970     if (stat(argv[1], &sb) == \-1) {
971         perror("stat");
972         exit(EXIT_FAILURE);
973     }
974
975     printf("File type:                ");
976
977     switch (sb.st_mode & S_IFMT) {
978     case S_IFBLK:  printf("block device\\n");            break;
979     case S_IFCHR:  printf("character device\\n");        break;
980     case S_IFDIR:  printf("directory\\n");               break;
981     case S_IFIFO:  printf("FIFO/pipe\\n");               break;
982     case S_IFLNK:  printf("symlink\\n");                 break;
983     case S_IFREG:  printf("regular file\\n");            break;
984     case S_IFSOCK: printf("socket\\n");                  break;
985     default:       printf("unknown?\\n");                break;
986     }
987
988     printf("I\-node number:            %ld\\n", (long) sb.st_ino);
989
990     printf("Mode:                     %lo (octal)\\n",
991             (unsigned long) sb.st_mode);
992
993     printf("Link count:               %ld\\n", (long) sb.st_nlink);
994     printf("Ownership:                UID=%ld   GID=%ld\\n",
995             (long) sb.st_uid, (long) sb.st_gid);
996
997     printf("Preferred I/O block size: %ld bytes\\n",
998             (long) sb.st_blksize);
999     printf("File size:                %lld bytes\\n",
1000             (long long) sb.st_size);
1001     printf("Blocks allocated:         %lld\\n",
1002             (long long) sb.st_blocks);
1003
1004     printf("Last status change:       %s", ctime(&sb.st_ctime));
1005     printf("Last file access:         %s", ctime(&sb.st_atime));
1006     printf("Last file modification:   %s", ctime(&sb.st_mtime));
1007
1008     exit(EXIT_SUCCESS);
1009 }
1010 .fi
1011 .\"O .SH "SEE ALSO"
1012 .SH 関連項目
1013 .BR access (2),
1014 .BR chmod (2),
1015 .BR chown (2),
1016 .BR fstatat (2),
1017 .BR readlink (2),
1018 .BR utime (2),
1019 .BR capabilities (7),
1020 .BR symlink (7)