.\" Updated 2012-05-29, Akihiro MOTOKI <amotoki@gmail.com>
.\" Updated 2013-03-26, Akihiro MOTOKI <amotoki@gmail.com>
.\"
-.TH STAT 2 2014\-03\-19 Linux "Linux Programmer's Manual"
+.TH STAT 2 2014\-05\-10 Linux "Linux Programmer's Manual"
.SH 名前
stat, fstat, lstat, fstatat \- ファイルの状態を取得する
.SH 書式
.sp
\fBlstat\fP():
.RS 4
-_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
+/* glibc 2.19 and earlier */ _BSD_SOURCE ||
+.br
+/* Since glibc 2.20 */_DEFAULT_SOURCE ||
+.br
+_XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
.br
|| /* glibc 2.10 以降: */ _POSIX_C_SOURCE\ >=\ 200112L
.RE
\(em\fBstat\fP(), \fBfstatat\fP(), \fBlstat\fP() の場合には \(emそのファイルへ至る \fIpathname\fP
を構成する全てのディレクトリに対する実行 (検索) 許可が必要である。
.PP
-\fBstat\fP() and \fBfstatat\fP() retrieve information about the file pointed to
-by \fIpathname\fP; the differences for \fBfstatat\fP() are described below.
+\fBstat\fP() と \fBfstatat\fP() は \fIpathname\fP が指すファイルに関する情報を取得する。 \fBfstatat\fP()
+の違いについては後で説明する。
\fBlstat\fP() は \fBstat\fP() と同じであるが、 \fIpathnames\fP
がシンボリックリンクの場合、リンクが参照しているファイルではなく、 リンク自身の状態を返す点が異なる。
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. */
+ /* Linux 2.6 以降では、カーネルは以下のタイムスタンプ
+ フィールドでナノ秒の精度をサポートしている。
+ Linux 2.6 より前のバージョンでの詳細は
+ 下記の「注意」を参照。 */
struct timespec st_atim; /* 最終アクセス時刻 */
struct timespec st_mtim; /* 最終修正時刻 */
struct timespec st_ctim; /* 最終状態変更時刻 */
-#define st_atime st_atim.tv_sec /* Backward compatibility */
+#define st_atime st_atim.tv_sec /* 後方互換性 */
#define st_mtime st_mtim.tv_sec
#define st_ctime st_ctim.tv_sec
};
.fi
.in
-\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.
+\fI注意:\fP \fIstat\fP 構造体のフィールドの順序はアーキテクチャにより様々である。
+また、上記の定義では、フィールド間に存在することがあるパディングバイトは書かれていない。このパディングバイトはアーキテクチャによっても異なる。詳細を知る必要がある場合は
+glibc とカーネルのソースを調べてほしい。
\fIst_dev\fP フィールドは、このファイルが存在するデバイスを示す (マクロ \fBmajor\fP(3), \fBminor\fP(3)
は、このフィールドのデバイス ID を分解するのに役立つだろう)。
\fIst_size\fP フィールドは、(通常のファイルかシンボリックリンクの場合に)
ファイルの大きさをバイト単位で示す。 シンボリックリンクの大きさは、
-シンボリックリンクに含まれている パス名の長さ (終端の NULL バイトは含まない)
+シンボリックリンクに含まれている パス名の長さ (終端のヌルバイトは含まない)
である。
\fIst_blocks\fP フィールドは、ファイルの大きさを 512 バイトのブロックサイズ単位で示す フィールドは、ファイルに割り当てされたブロック数を
\fIst_ctime\fP フィールドは書き込みや inode 情報 (所有者、グループ、リンク数、モードなど) の 設定によって変更される。
.PP
-以下の POSIX マクロは、 \fIst_mode\fP フィールド で使用されるファイル種別のチェックのために定義されている :
+The following mask values are defined for the file type component of the
+\fIst_mode\fP field:
+.in +4n
+.TS
+lB l l.
+S_IFMT 0170000 ファイル種別を示すビット領域を表すビットマスク
+
+S_IFSOCK 0140000 ソケット
+S_IFLNK 0120000 シンボリックリンク
+S_IFREG 0100000 通常のファイル
+S_IFBLK 0060000 ブロック・デバイス
+S_IFDIR 0040000 ディレクトリ
+S_IFCHR 0020000 キャラクター・デバイス
+S_IFIFO 0010000 FIFO
+.TE
+.in
+.PP
+Thus, to test for a regular file (for example), one could write:
+
+.nf
+.in +4n
+stat(pathname, &sb);
+if ((sb.st_mode & S_IFMT) == S_IFREG) {
+ /* Handle regular file */
+}
+.in
+.fi
+.PP
+Because tests of the above form are common, additional macros are defined by
+POSIX to allow the test of the file type in \fIst_mode\fP to be written more
+concisely:
.RS 4
.TP 1.2i
\fBS_ISREG\fP(m)
ソケットか? (POSIX.1\-1996 にはない)
.RE
.PP
-以下のフラグが \fIst_mode\fP フィールド用に定義されている:
+The preceding code snippet could thus be rewritten as:
+
+.nf
+.in +4n
+stat(pathname, &sb);
+if (S_ISREG(sb.st_mode)) {
+ /* Handle regular file */
+}
+.in
+.fi
+.PP
+The definitions of most of the above file type test macros are provided if
+any of the following feature test macros are defined: \fB_BSD_SOURCE\fP (in
+glibc 2.19 and earlier), \fB_SVID_SOURCE\fP (in glibc 2.19 and earlier), or
+\fB_DEFAULT_SOURCE\fP (in glibc 2.20 and later). In addition, definitions of
+all of the above macros except \fBS_IFSOCK\fP and \fBS_ISSOCK\fP() are provided
+if \fB_XOPEN_SOURCE\fP is defined. The definition of \fBS_IFSOCK\fP can also be
+exposed by defining \fB_XOPEN_SOURCE\fP with a value of 500 or greater.
+
+The definition of \fBS_ISSOCK\fP() is exposed if any of the following feature
+test macros is defined: \fB_BSD_SOURCE\fP (in glibc 2.19 and earlier),
+\fB_DEFAULT_SOURCE\fP (in glibc 2.20 and later), \fB_XOPEN_SOURCE\fP with a value
+of 500 or greater, or \fB_POSIX_C_SOURCE\fP with a value of 200112L or greater.
+.PP
+The following mask values are defined for the file permissions component of
+the \fIst_mode\fP field:
.in +4n
.TS
lB l l.
-S_IFMT 0170000 ファイル種別を示すビット領域を表すビットマスク
-S_IFSOCK 0140000 ソケット
-S_IFLNK 0120000 シンボリックリンク
-S_IFREG 0100000 通常のファイル
-S_IFBLK 0060000 ブロック・デバイス
-S_IFDIR 0040000 ディレクトリ
-S_IFCHR 0020000 キャラクター・デバイス
-S_IFIFO 0010000 FIFO
S_ISUID 0004000 set\-user\-ID bit
S_ISGID 0002000 set\-group\-ID bit (下記参照)
S_ISVTX 0001000 スティッキー・ビット (下記参照)
-S_IRWXU 00700 ファイル所有者のアクセス許可用のビットマスク
-S_IRUSR 00400 所有者の読み込み許可
-S_IWUSR 00200 所有者の書き込み許可
-S_IXUSR 00100 所有者の実行許可
-S_IRWXG 00070 グループのアクセス許可用のビットマスク
-S_IRGRP 00040 グループの読み込み許可
-S_IWGRP 00020 グループの書き込み許可
-S_IXGRP 00010 グループの実行許可
-S_IRWXO 00007 T{
+
+S_IRWXU 00700 mask for file owner permissions
+S_IRUSR 00400 owner has read permission
+S_IWUSR 00200 owner has write permission
+S_IXUSR 00100 owner has execute permission
+
+S_IRWXG 00070 mask for group permissions
+S_IRGRP 00040 group has read permission
+S_IWGRP 00020 group has write permission
+S_IXGRP 00010 group has execute permission
+
+S_IRWXO 00007 T{
他人 (others) のアクセス許可用のビットマスク
T}
-S_IROTH 00004 他人の読み込み許可
-S_IWOTH 00002 他人の書き込み許可
-S_IXOTH 00001 他人の実行許可
+S_IROTH 00004 others have read permission
+S_IWOTH 00002 others have write permission
+S_IXOTH 00001 others have execute permission
.TE
.in
.P
-set\-group\-ID bit (\fBS_ISGID\fP) にはいくつかの特殊な使用法がある: ディレクトリに設定した場合には、そのディレクトリが
-BSD 方式で使用される ことを示す。つまり、そのディレクトリに作成されたファイルのグループID は 作成したプロセスの実効 (effective)
-グループID ではなく、ディレクトリの グループID を継承する。また、そのディレクトリに作成されたディレクトリにも \fBS_ISGID\fP
-ビットが設定される。グループ実行ビット (\fBS_IXGRP\fP) が設定されていないファイルに設定された場合は、 set\-group\-ID
-ビットはファイル/レコードの 強制的な (mandatory) ロックを表す。
+The set\-group\-ID bit (\fBS_ISGID\fP) has several special uses. For a
+directory, it indicates that BSD semantics is to be used for that directory:
+files created there inherit their group ID from the directory, not from the
+effective group ID of the creating process, and directories created there
+will also get the \fBS_ISGID\fP bit set. For a file that does not have the
+group execution bit (\fBS_IXGRP\fP) set, the set\-group\-ID bit indicates
+mandatory file/record locking.
.P
.\"
.\"
.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).
+指定された \fIpathname\fP が相対パスの場合、 ファイルディスクリプタ \fIdirfd\fP が参照するディレクトリに対する相対パスと解釈される
+(\fBstat\fP() に相対パスを渡した場合のように、呼び出したプロセスのカレントワーキングディレクトリに対する相対パスではない)。
-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()).
+\fIpathname\fP が相対パスで、 \fIdirfd\fP が特別な値 \fBAT_FDCWD\fP の場合、 (\fBstat\fP(2) と同様に)
+\fIpathname\fP は呼び出したプロセスのカレントワーキングディレクトリに対する相対パスと解釈される。
-If \fIpathname\fP is absolute, then \fIdirfd\fP is ignored.
+\fIpathname\fP で指定されたパス名が絶対パスの場合、 \fIdirfd\fP は無視される。
この \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.
+\fIpathname\fP が空文字列の場合、 \fIdirfd\fP が参照するファイルに対して操作を行う (\fIdirfd\fP は \fBopen\fP(2) の
+\fBO_PATH\fP フラグを使って取得できる)。 \fBdirfd\fP が \fBAT_FDCWD\fP
+の場合、呼び出しはカレントワーキングディレクトリに対して操作を行う。 この場合、 \fIdirfd\fP
+は、ディレクトリだけでなく、任意のタイプのファイルを参照することができる。 このフラグは Linux 固有であり、その定義を得るには
+\fB_GNU_SOURCE\fP を定義すること。
.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.
+\fIpathname\fP がオートマウントポイントとなっているディレクトリの場合、 \fIpathname\fP の最終 ("basename")
+要素のオートマウントを行わない。 これにより (マウントされるはずの場所ではなく) オートマウントポイントの属性を取得することができる。
+このフラグを使うと、 ディレクトリをスキャンするツールがオートマウントポイントのディレクトリを大量にオートマウントしてしまうのを防ぐことができる。
+マウントポイントがすでにマウントされている場合 \fBAT_NO_AUTOMOUNT\fP フラグは何の効果もない。 このフラグは Linux
+固有であり、その定義を得るには \fB_GNU_SOURCE\fP を定義すること。
.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().)
+(\fBlstat\fP() 同様) \fIpathname\fP がシンボリックリンクの場合リンクの展開を行わず、 リンク自身の情報を返す (デフォルトでは、
+\fBfstatat\fP() は、 \fBstat\fP() と同様に、シンボリックリンクの展開を行う)。
.PP
-See \fBopenat\fP(2) for an explanation of the need for \fBfstatat\fP().
+\fBfstatat\fP() の必要性についての説明については \fBopenat\fP(2) を参照。
.SH 返り値
成功した場合、0 が返される。 失敗した場合、 \-1 が返され、 \fIerrno\fP に適切な値がセットされる。
.SH エラー
ファイルサイズが \fI(1<<31)\-1\fP バイトを超えるファイルに対して
\fBstat\fP() を呼び出した場合である。
.PP
-The following additional errors can occur for \fBfstatat\fP():
+\fBfstatat\fP() では以下のエラーも発生することがある。
.TP
\fBEBADF\fP
\fIdirfd\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.
+\fIpathname\fP が相対パスで、 \fIdirfd\fP がディレクトリ以外のファイルを参照しているファイルディスクリプタである。
.SH バージョン
\fBfstatat\fP() はカーネル 2.6.16 で Linux に追加された。 ライブラリによるサポートはバージョン 2.4 で glibc
に追加された。
\fBfstatat\fP(): POSIX.1\-2008.
-According to POSIX.1\-2001, \fBlstat\fP() on a symbolic link need return valid
-information only in the \fIst_size\fP field and the file\-type component of the
-\fIst_mode\fP field of the \fIstat\fP structure. POSIX.1\-2008 tightens the
-specification, requiring \fBlstat\fP() to return valid information in all
-fields except the permission bits in \fIst_mode\fP.
+POSIX.1\-2001 では、シンボリックリンクに対する \fBlstat\fP() で
+有効な情報を返すように求められていたのは、 \fIstat\fP 構造体の \fIst_size\fP
+と \fIst_mode\fP のファイル種別要素だけであった。
+POSIX.1\-2008 では規定が厳しくなり、 \fBlstat\fP() は \fIst_mode\fP の
+アクセス許可ビット以外の全てのフィールドに有効な情報を返すことが
+求められるようになっている。
\fIst_blocks\fP と \fIst_blksize\fP フィールドの使用はあまり移植性がない
(これらのフィールドは BSD によって導入された。 システムごとに解釈が
POSIX.1\-2001 には両方とも存在する。 前者は SVID 4 に、後者は SUSv2 に
由来している。
.LP
-UNIX V7 (とその後のシステム) は \fBS_IREAD\fP, \fBS_IWRITE\fP, \fBS_IEXEC\fP を持っており、
+UNIX\ V7 (とその後のシステム) は \fBS_IREAD\fP, \fBS_IWRITE\fP, \fBS_IEXEC\fP を持っており、
POSIX はその同義語として \fBS_IRUSR\fP, \fBS_IWUSR\fP, \fBS_IXUSR\fP を規定している。
.SS 他のシステム
各種システムで使用されていた(いる)値:
\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.
+古いカーネルや古い標準では、ナノ秒精度のタイムスタンプフィールドはサポートされていなかった。 代わりに 3 つの \fItime_t\fP
+型のタイムスタンプフィールド \fIst_atime\fP, \fIst_mtime\fP, and \fIst_ctime\fP があった。これらのフィールドには 1
+秒単位のタイムスタンプが記録されていた。
カーネル 2.5.48 以降では、 \fIstat\fP 構造体は 3 つのファイルのタイムスタンプ関連のフィールドでナノ秒単位の精度に対応している。
機能検査マクロ \fB_BSD_SOURCE\fP か \fB_SVID_SOURCE\fP が定義された場合に、各タイムスタンプのナノ秒の情報は
上記のマクロのいずれも定義されていない場合、ナノ秒の値は \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.
+ナノ秒のタイムスタンプは XFS, JFS, Btrfs, ext4 でサポートされている (Linux 2.6.23 以降)。
+ナノ秒のタイムスタンプは ext2, ext3, Reiserfs ではサポートされていない。
+サブ秒のタイムスタンプをサポートしていないファイルシステムでは、 ナノ秒のフィールドには値 0 が入る。
.SS 背後のカーネル・インタフェース
.\"
.\" A note from Andries Brouwer, July 2007
\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.65 の一部
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.67 の一部
である。プロジェクトの説明とバグ報告に関する情報は
http://www.kernel.org/doc/man\-pages/ に書かれている。