OSDN Git Service

(split) LDP: Update draft and release for LDP 3.65
[linuxjm/LDP_man-pages.git] / draft / man2 / stat.2
index 782936a..b31f72d 100644 (file)
@@ -1,7 +1,7 @@
 .\" t
 .\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
 .\" Parts Copyright (c) 1995 Nicolai Langfeldt (janl@ifi.uio.no), 1/1/95
-.\" and Copyright (c) 2007 Michael Kerrisk <mtk.manpages@gmail.com>
+.\" and Copyright (c) 2006, 2007, 2014 Michael Kerrisk <mtk.manpages@gmail.com>
 .\"
 .\" %%%LICENSE_START(VERBATIM)
 .\" Permission is granted to make and distribute verbatim copies of this
 .\" Updated 2012-05-29, Akihiro MOTOKI <amotoki@gmail.com>
 .\" Updated 2013-03-26, Akihiro MOTOKI <amotoki@gmail.com>
 .\"
-.TH STAT 2 2012\-11\-11 Linux "Linux Programmer's Manual"
+.TH STAT 2 2014\-03\-19 Linux "Linux Programmer's Manual"
 .SH 名前
-stat, fstat, lstat \- ファイルの状態を取得する
+stat, fstat, lstat, fstatat \- ファイルの状態を取得する
 .SH 書式
+.nf
 \fB#include <sys/types.h>\fP
 .br
 \fB#include <sys/stat.h>\fP
 .br
 \fB#include <unistd.h>\fP
 .sp
-\fBint stat(const char *\fP\fIpath\fP\fB, struct stat *\fP\fIbuf\fP\fB);\fP
+\fBint stat(const char *\fP\fIpathname\fP\fB, struct stat *\fP\fIbuf\fP\fB);\fP
 .br
 \fBint fstat(int \fP\fIfd\fP\fB, struct stat *\fP\fIbuf\fP\fB);\fP
 .br
-\fBint lstat(const char *\fP\fIpath\fP\fB, struct stat *\fP\fIbuf\fP\fB);\fP
+\fBint lstat(const char *\fP\fIpathname\fP\fB, struct stat *\fP\fIbuf\fP\fB);\fP
+.sp
+\fB#include <fcntl.h>           \fP/* AT_* 定数の定義 */
+\fB#include <sys/stat.h>\fP
+.sp
+\fBint fstatat(int \fP\fIdirfd\fP\fB, const char *\fP\fIpathname\fP\fB, struct stat *\fP\fIbuf\fP\fB,\fP
+\fB            int \fP\fIflags\fP\fB);\fP
+.fi
 .sp
 .in -4n
 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7)  参照):
@@ -89,45 +97,73 @@ _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTEND
 .br
 || /* glibc 2.10 以降: */ _POSIX_C_SOURCE\ >=\ 200112L
 .RE
+.sp
+\fBfstatat\fP():
+.PD 0
+.ad l
+.RS 4
+.TP  4
+glibc 2.10 以降:
+_XOPEN_SOURCE\ >=\ 700 || _POSIX_C_SOURCE\ >=\ 200809L
+.TP 
+glibc 2.10 より前:
+_ATFILE_SOURCE
+.RE
 .PD
 .ad
 .SH 説明
 .PP
-これらの関数はファイルについての情報を返す。
-ファイルそのものに対するアクセス許可は必要としないが、
-\(em\fBstat\fP() と \fBlstat\fP()  の場合には \(em
-そのファイルへ至る \fIpath\fP を構成する全てのディレクトリに対する
-実行 (検索) 許可が必要である。
+これらの関数は、ファイルについての情報を \fIstat\fP が指すバッファに格納して返す。 ファイルそのものに対するアクセス許可は必要としないが、
+\(em\fBstat\fP(), \fBfstatat\fP(), \fBlstat\fP() の場合には \(emそのファイルへ至る \fIpathname\fP
+を構成する全てのディレクトリに対する実行 (検索) 許可が必要である。
 .PP
-\fBstat\fP()  は \fIpath\fP で指定されたファイルの状態を取得して \fIbuf\fP へ格納する。
+\fBstat\fP()  and \fBfstatat\fP()  retrieve information about the file pointed to
+by \fIpathname\fP; the differences for \fBfstatat\fP()  are described below.
 
-\fBlstat\fP()  は \fBstat\fP()  と同じであるが、 \fIpath\fP がシンボリックリンクの場合、リンクが参照しているファイルではなく、
\83ªã\83³ã\82¯è\87ªèº«ã\81®ç\8a¶æ\85\8bã\82\92å\8f\96å¾\97ã\81\99ã\82\8b点が異なる。
+\fBlstat\fP()  は \fBstat\fP()  と同じであるが、 \fIpathnames\fP
\81\8cã\82·ã\83³ã\83\9cã\83ªã\83\83ã\82¯ã\83ªã\83³ã\82¯ã\81®å ´å\90\88ã\80\81ã\83ªã\83³ã\82¯ã\81\8cå\8f\82ç\85§ã\81\97ã\81¦ã\81\84ã\82\8bã\83\95ã\82¡ã\82¤ã\83«ã\81§ã\81¯ã\81ªã\81\8fã\80\81 ã\83ªã\83³ã\82¯è\87ªèº«ã\81®ç\8a¶æ\85\8bã\82\92è¿\94ã\81\99点が異なる。
 
-\fBfstat\fP()  ã\81¯ \fBstat\fP()  ã\81¨å\90\8cã\81\98ã\81 ã\81\8cã\80\81 ç\8a¶æ\85\8bã\82\92å\8f\96å¾\97ã\81\99ã\82\8bã\83\95ã\82¡ã\82¤ã\83«ã\82\92ã\83\95ã\82¡ã\82¤ã\83«ã\83»ã\83\87ã\82£ã\82¹ã\82¯ã\83ªã\83\97ã\82¿ \fIfd\fP ã\81§æ\8c\87å®\9aã\81\99る。
+\fBfstat\fP()  ã\81¯ \fBstat\fP()  ã\81¨å\90\8cã\81\98ã\81 ã\81\8cã\80\81 ç\8a¶æ\85\8bã\82\92å\8f\96å¾\97ã\81\99ã\82\8bã\83\95ã\82¡ã\82¤ã\83«ã\82\92ã\83\95ã\82¡ã\82¤ã\83«ã\83\87ã\82£ã\82¹ã\82¯ã\83ªã\83\97ã\82¿ \fIfd\fP ã\81§æ\8c\87å®\9aã\81\99ã\82\8bç\82¹ã\81\8cç\95°ã\81ªる。
 .PP
 これらのシステムコールはいずれも、結果を \fIstat\fP 構造体に入れて返す。 \fIstat\fP 構造体には以下のフィールドが含まれている:
 .PP
 .in +4n
 .nf
 struct stat {
-    dev_t     st_dev;     /* ID of device containing file */
-    ino_t     st_ino;     /* inode number */
-    mode_t    st_mode;    /* protection */
-    nlink_t   st_nlink;   /* number of hard links */
-    uid_t     st_uid;     /* user ID of owner */
-    gid_t     st_gid;     /* group ID of owner */
-    dev_t     st_rdev;    /* device ID (if special file) */
-    off_t     st_size;    /* total size, in bytes */
-    blksize_t st_blksize; /* blocksize for filesystem I/O */
-    blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
-    time_t    st_atime;   /* time of last access */
-    time_t    st_mtime;   /* time of last modification */
-    time_t    st_ctime;   /* time of last status change */
+    dev_t     st_dev;     /* ファイルがあるデバイスの ID */
+    ino_t     st_ino;     /* inode 番号 */
+    mode_t    st_mode;    /* アクセス保護 */
+    nlink_t   st_nlink;   /* ハードリンクの数 */
+    uid_t     st_uid;     /* 所有者のユーザ ID */
+    gid_t     st_gid;     /* 所有者のグループ ID */
+    dev_t     st_rdev;    /* デバイス ID (特殊ファイルの場合) */
+    off_t     st_size;    /* 全体のサイズ (バイト単位) */
+    blksize_t st_blksize; /* ファイルシステム I/O での
+                             ブロックサイズ */
+    blkcnt_t  st_blocks;  /* 割り当てられた 512B のブロック数 */
+};
+
+    /* Since Linux 2.6, the kernel supports nanosecond
+       precision for the following timestamp fields.
+       For the details before Linux 2.6, see NOTES. */
+
+    struct timespec st_atim;  /* 最終アクセス時刻 */
+    struct timespec st_mtim;  /* 最終修正時刻 */
+    struct timespec st_ctim;  /* 最終状態変更時刻 */
+
+#define st_atime st_atim.tv_sec      /* Backward compatibility */
+#define st_mtime st_mtim.tv_sec
+#define st_ctime st_ctim.tv_sec
 };
 .fi
 .in
-.PP
+
+\fINote:\fP the order of fields in the \fIstat\fP structure varies somewhat across
+architectures.  In addition, the definition above does not show the padding
+bytes that may be present between some fields on various architectures.
+Consult the the glibc and kernel source code if you need to know the
+details.
+
 \fIst_dev\fP フィールドは、このファイルが存在するデバイスを示す (マクロ \fBmajor\fP(3), \fBminor\fP(3)
 は、このフィールドのデバイス ID を分解するのに役立つだろう)。
 
@@ -141,16 +177,13 @@ struct stat {
 \fIst_blocks\fP フィールドは、ファイルの大きさを 512 バイトのブロックサイズ単位で示す フィールドは、ファイルに割り当てされたブロック数を
 512 バイト単位で示す。 (ファイルに穴があるような場合、この値は \fIst_size\fP/512 より小さくなることもある)。
 
-The \fIst_blksize\fP field gives the "preferred" blocksize for efficient
-filesystem I/O.  (Writing to a file in smaller chunks may cause an
-inefficient read\-modify\-rewrite.)
+\fIst_blksize\fP フィールドは、効率的にファイルシステム I/O ができる「好ましい」 ブロックサイズを示す
+(もっと小さい単位でファイルに書き込みを行うと、 読み出し\-\-修正\-\-再書き込みといった非効率な動作になってしまうかもしれない)。
 .PP
-Not all of the Linux filesystems implement all of the time fields.  Some
-filesystem types allow mounting in such a way that file and/or directory
-accesses do not cause an update of the \fIst_atime\fP field.  (See \fInoatime\fP,
-\fInodiratime\fP, and \fIrelatime\fP in \fBmount\fP(8), and related information in
-\fBmount\fP(2).)  In addition, \fIst_atime\fP is not updated if a file is opened
-with the \fBO_NOATIME\fP; see \fBopen\fP(2).
+全ての Linux のファイルシステムが全ての時間フィールドを 実装しているわけではない。 ファイルやディレクトリのアクセスが \fIst_atime\fP
+フィールドを更新しないようなかたちでマウントできるファイルシステムもある。 (\fBmount\fP(8)  の \fInoatime\fP,
+\fInodiratime\fP, \fIrelatime\fP や \fBmount\fP(2)  の関連する情報を参照)。 また、ファイルが \fBO_NOATIME\fP
+付きでオープンされている場合には \fIst_atime\fP は更新されない。 \fBopen\fP(2)  参照。
 
 \fIst_atime\fP フィールドはファイルアクセスがあった場合に変更される (例えば、 \fBexecve\fP(2), \fBmknod\fP(2),
 \fBpipe\fP(2), \fButime\fP(2)  を使用した場合や \fBread\fP(2)  で 1 バイト以上読み込んだ場合など)。
@@ -211,7 +244,9 @@ S_IRWXG     00070   グループのアクセス許可用のビットマスク
 S_IRGRP        00040   グループの読み込み許可
 S_IWGRP        00020   グループの書き込み許可
 S_IXGRP        00010   グループの実行許可
-S_IRWXO        00007   他人 (others) のアクセス許可用のビットマスク
+S_IRWXO        00007   T{
+他人 (others) のアクセス許可用のビットマスク
+T}
 S_IROTH        00004   他人の読み込み許可
 S_IWOTH        00002   他人の書き込み許可
 S_IXOTH        00001   他人の実行許可
@@ -224,15 +259,60 @@ BSD 方式で使用される ことを示す。つまり、そのディレクト
 ビットが設定される。グループ実行ビット (\fBS_IXGRP\fP)  が設定されていないファイルに設定された場合は、 set\-group\-ID
 ビットはファイル/レコードの 強制的な (mandatory) ロックを表す。
 .P
+.\"
+.\"
 ディレクトリにスティッキービット (S_ISVTX) が設定された場合は、 そのディレクトリのファイルの名前を変更したり、削除したりできるのは、
 そのファイルの所有者か、そのディレクトリの所有者か、特権プロセス だけとなる。
+.SS fstatat()
+\fBfstatat\fP() システムコールは \fBstat\fP() と全く同様に動作するが、以下で説明する点が異なる。
+
+If the pathname given in \fIpathname\fP is relative, then it is interpreted
+relative to the directory referred to by the file descriptor \fIdirfd\fP
+(rather than relative to the current working directory of the calling
+process, as is done by \fBstat\fP()  for a relative pathname).
+
+If \fIpathname\fP is relative and \fIdirfd\fP is the special value \fBAT_FDCWD\fP,
+then \fIpathname\fP is interpreted relative to the current working directory of
+the calling process (like \fBstat\fP()).
+
+If \fIpathname\fP is absolute, then \fIdirfd\fP is ignored.
+
+この \fIflags\fP 引き数は下記のフラグの 0 個以上の論理和を取ったものである:
+.TP 
+\fBAT_EMPTY_PATH\fP (Linux 2.6.39 以降)
+.\" commit 65cfc6722361570bfe255698d9cd4dccaf47570d
+.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
+If \fIpathname\fP is an empty string, operate on the file referred to by
+\fIdirfd\fP (which may have been obtained using the \fBopen\fP(2)  \fBO_PATH\fP
+flag).  If \fIdirfd\fP is \fBAT_FDCWD\fP, the call operates on the current working
+directory.  In this case, \fIdirfd\fP can refer to any type of file, not just a
+directory.  This flag is Linux\-specific; define \fB_GNU_SOURCE\fP to obtain its
+definition.
+.TP 
+\fBAT_NO_AUTOMOUNT\fP (Linux 2.6.38 以降)
+.\" Before glibc 2.16, defining _ATFILE_SOURCE sufficed
+Don't automount the terminal ("basename") component of \fIpathname\fP if it is
+a directory that is an automount point.  This allows the caller to gather
+attributes of an automount point (rather than the location it would mount).
+This flag can be used in tools that scan directories to prevent
+mass\-automounting of a directory of automount points.  The
+\fBAT_NO_AUTOMOUNT\fP flag has no effect if the mount point has already been
+mounted over.  This flag is Linux\-specific; define \fB_GNU_SOURCE\fP to obtain
+its definition.
+.TP 
+\fBAT_SYMLINK_NOFOLLOW\fP
+If \fIpathname\fP is a symbolic link, do not dereference it: instead return
+information about the link itself, like \fBlstat\fP().  (By default,
+\fBfstatat\fP()  dereferences symbolic links, like \fBstat\fP().)
+.PP
+See \fBopenat\fP(2)  for an explanation of the need for \fBfstatat\fP().
 .SH 返り値
 成功した場合、0 が返される。 失敗した場合、 \-1 が返され、 \fIerrno\fP に適切な値がセットされる。
 .SH エラー
 .TP 
 \fBEACCES\fP
-\fIpath\fP が所属するディレクトリとその上位のディレクトリのいずれかに 対する検索許可がなかった (\fBpath_resolution\fP(7)
-も参照のこと)。
+\fIpathname\fP が所属するディレクトリとその上位のディレクトリのいずれかに 対する検索許可がなかった
+(\fBpath_resolution\fP(7)  も参照のこと)。
 .TP 
 \fBEBADF\fP
 \fIfd\fP が不正である。
@@ -244,24 +324,39 @@ BSD 方式で使用される ことを示す。つまり、そのディレクト
 パスを辿る際に解決すべきシンボリックリンクが多過ぎた。
 .TP 
 \fBENAMETOOLONG\fP
-\fIpath\fP が長過ぎる。
+\fIpathname\fP が長過ぎる。
 .TP 
 \fBENOENT\fP
-\fIpath\fP の構成要素が存在しないか、 \fIpath\fP が空文字列である。
+\fIpathname\fP の構成要素が存在しないか、 \fIpathname\fP が空文字列である。
 .TP 
 \fBENOMEM\fP
 カーネルのメモリが足りない。
 .TP 
 \fBENOTDIR\fP
-\fIpath\fP の前半部分 (prefix) の構成要素がディレクトリではない。
+\fIpathname\fP の前半部分 (prefix) の構成要素がディレクトリではない。
 .TP 
 \fBEOVERFLOW\fP
-\fIpath\fP または \fIfd\fP が、ファイルサイズ、inode 番号、ブロック数が
+\fIpathname\fP または \fIfd\fP が、ファイルサイズ、inode 番号、ブロック数が
 それぞれ \fIoff_t\fP 型、 \fIino_t\fP 型、 \fIblkcnt_t\fP 型で表現できないファイルを
 参照している。このエラーが起こるのは、例えば、32 ビットプラットフォーム上で
 \fI\-D_FILE_OFFSET_BITS=64\fP を指定せずにコンパイルされたアプリケーションが、
 ファイルサイズが \fI(1<<31)\-1\fP バイトを超えるファイルに対して
 \fBstat\fP() を呼び出した場合である。
+.PP
+The following additional errors can occur for \fBfstatat\fP():
+.TP 
+\fBEBADF\fP
+\fIdirfd\fP が有効なファイルディスクリプタでない。
+.TP 
+\fBEINVAL\fP
+\fIflags\fP に無効なフラグが指定された。
+.TP 
+\fBENOTDIR\fP
+\fIpathname\fP is relative and \fIdirfd\fP is a file descriptor referring to a
+file other than a directory.
+.SH バージョン
+\fBfstatat\fP()  はカーネル 2.6.16 で Linux に追加された。 ライブラリによるサポートはバージョン 2.4 で glibc
+に追加された。
 .SH 準拠
 .\" SVr4 documents additional
 .\" .BR fstat ()
@@ -271,9 +366,9 @@ BSD 方式で使用される ことを示す。つまり、そのディレクト
 .\" and
 .\" .BR lstat ()
 .\" error conditions EINTR, EMULTIHOP, ENOLINK, and EOVERFLOW.
-これらのシステムコールは SVr4, 4.3BSD, POSIX.1\-2001 に準拠している。 \fBstat\fP()  と \fBfstat\fP()
-コールは SVr4, SVID, POSIX, X/OPEN, 4.3BSD に準拠している。 \fBlstat\fP()  コールは 4.3BSD と
-SVr4 に準拠している。
+\fBstat\fP(), \fBfstat\fP(), \fBlstat\fP(): SVr4, 4.3BSD, POSIX.1\-2001, POSIX.1.2008.
+
+\fBfstatat\fP(): POSIX.1\-2008.
 
 POSIX.1\-2001 では、シンボリックリンクに対する \fBlstat\fP() で
 有効な情報を返すように求められていたのは、 \fIstat\fP 構造体の \fIst_size\fP
@@ -359,25 +454,29 @@ T}
 
 スティッキー コマンドは Version 32V AT&T UNIX で登場した。
 .SH 注意
-.\" As at kernel 2.6.25, XFS and JFS support nanosecond timestamps,
-.\" but ext2, ext3, and Reiserfs do not.
-Since kernel 2.5.48, the \fIstat\fP structure supports nanosecond resolution
-for the three file timestamp fields.  Glibc exposes the nanosecond component
-of each field using names of the form \fIst_atim.tv_nsec\fP if the
-\fB_BSD_SOURCE\fP or \fB_SVID_SOURCE\fP feature test macro is defined.  These
-fields are specified in POSIX.1\-2008, and, starting with version 2.12, glibc
-also exposes these field names if \fB_POSIX_C_SOURCE\fP is defined with the
-value 200809L or greater, or \fB_XOPEN_SOURCE\fP is defined with the value 700
-or greater.  If none of the aforementioned macros are defined, then the
-nanosecond values are exposed with names of the form \fIst_atimensec\fP.  On
-filesystems that do not support subsecond timestamps, the nanosecond fields
-are returned with the value 0.
-
 Linux では、 \fBlstat\fP() は一般には自動マウント動作 (automounter action) の
 きっかけとならないが、 \fBstat\fP() はきっかけとなる (\fBfstatat\fP(2) を参照)。
 
 \fI/proc\fP ディレクトリ以下にあるファイルのほとんどでは、 \fBstat\fP()  を呼び出した際に、 \fIst_size\fP
 フィールドにファイルサイズが返されない。 代わりに \fIst_size\fP フィールドには 0 が返される。
+.SS タイムスタンプフィールド
+Older kernels and older standards did not support nanosecond timestamp
+fields.  Instead, there were three timestamp fields\(em\fIst_atime\fP,
+\fIst_mtime\fP, and \fIst_ctime\fP\(emtyped as \fItime_t\fP that recorded timestamps
+with one\-second precision.
+
+カーネル 2.5.48 以降では、 \fIstat\fP 構造体は 3 つのファイルのタイムスタンプ関連のフィールドでナノ秒単位の精度に対応している。
+機能検査マクロ \fB_BSD_SOURCE\fP か \fB_SVID_SOURCE\fP が定義された場合に、各タイムスタンプのナノ秒の情報は
+\fIst_atim.tv_nsec\fP という形式の名前で参照できる。 ナノ秒のタイムスタンプは現在では標準化されており、 POSIX.1\-2008
+からである。 バージョン 2.12 以降の glibc では、 \fB_POSIX_C_SOURCE\fP が 200809L 以上の値で定義されるか、
+\fB_XOPEN_SOURCE\fP が 700 以上の値で定義された場合にも、 このナノ秒のタイムスタンプが公開される。
+上記のマクロのいずれも定義されていない場合、ナノ秒の値は \fIst_atimensec\fP という形式の名前で公開される。
+
+.\" commit ef7f38359ea8b3e9c7f2cae9a4d4935f55ca9e80
+Nanosecond timestamps are supported on XFS, JFS, Btrfs, and ext4 (since
+Linux 2.6.23).  Nanosecond timestamps are not supported in ext2, ext3, and
+Resierfs.  On filesystems that do not support subsecond timestamps, the
+nanosecond fields are returned with the value 0.
 .SS 背後のカーネル・インタフェース
 .\"
 .\" A note from Andries Brouwer, July 2007
@@ -413,6 +512,8 @@ Linux では、 \fBlstat\fP() は一般には自動マウント動作 (automount
 の \fBstat\fP()  ラッパー関数はこれらの詳細をアプリケーションから隠蔽してくれる。
 具体的には、カーネルが提供しているシステムコールのうち最新のバージョンを 起動し、古いバイナリの場合には必要に応じて返された情報を再構成
 (repack) する。 \fBfstat\fP()  と \fBlstat\fP()  についても同様である。
+
+glibc の \fBfstatat\fP() ラッパー関数が内部で利用するシステムコールは、実際には \fBfstatat64\fP() である。
 .SH 例
 以下のプログラムは \fBstat\fP()  を呼び出し、返ってきた \fIstat\fP 構造体のフィールドのいくつかを表示する。
 .nf
@@ -475,9 +576,9 @@ main(int argc, char *argv[])
 }
 .fi
 .SH 関連項目
-\fBaccess\fP(2), \fBchmod\fP(2), \fBchown\fP(2), \fBfstatat\fP(2), \fBreadlink\fP(2),
-\fButime\fP(2), \fBcapabilities\fP(7), \fBsymlink\fP(7)
+\fBls\fP(1), \fBstat\fP(1), \fBaccess\fP(2), \fBchmod\fP(2), \fBchown\fP(2),
+\fBreadlink\fP(2), \fButime\fP(2), \fBcapabilities\fP(7), \fBsymlink\fP(7)
 .SH この文書について
-この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.54 の一部
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.65 の一部
 である。プロジェクトの説明とバグ報告に関する情報は
 http://www.kernel.org/doc/man\-pages/ に書かれている。