.\" Copyright (c) 1992 Drew Eckhardt (drew@cs.colorado.edu), March 28, 1992
.\" and Copyright (c) 1998 Andries Brouwer (aeb@cwi.nl)
-.\" and Copyright (c) 2007, 2008 Michael Kerrisk <mtk.manpages@gmail.com>
+.\" and Copyright (c) 2006, 2007, 2008, 2014 Michael Kerrisk <mtk.manpages@gmail.com>
.\"
.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
.\" Updated 2008-08-09, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>, LDP v3.05
.\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
.\"
-.TH CHOWN 2 2010\-11\-22 Linux "Linux Programmer's Manual"
+.TH CHOWN 2 2014\-02\-21 Linux "Linux Programmer's Manual"
.SH 名前
-chown, fchown, lchown \- ファイルの所有者を変更する
+chown, fchown, lchown, fchownat \- ファイルの所有者を変更する
.SH 書式
+.nf
\fB#include <unistd.h>\fP
.sp
-\fBint chown(const char *\fP\fIpath\fP\fB, uid_t \fP\fIowner\fP\fB, gid_t \fP\fIgroup\fP\fB);\fP
+\fBint chown(const char *\fP\fIpathname\fP\fB, uid_t \fP\fIowner\fP\fB, gid_t \fP\fIgroup\fP\fB);\fP
.br
\fBint fchown(int \fP\fIfd\fP\fB, uid_t \fP\fIowner\fP\fB, gid_t \fP\fIgroup\fP\fB);\fP
.br
-\fBint lchown(const char *\fP\fIpath\fP\fB, uid_t \fP\fIowner\fP\fB, gid_t \fP\fIgroup\fP\fB);\fP
+\fBint lchown(const char *\fP\fIpathname\fP\fB, uid_t \fP\fIowner\fP\fB, gid_t \fP\fIgroup\fP\fB);\fP
+.sp
+\fB#include <fcntl.h> \fP/* AT_* 定数の定義 */
+\fB#include <unistd.h>\fP
+.sp
+\fBint fchownat(int \fP\fIdirfd\fP\fB, const char *\fP\fIpathname\fP\fB,\fP
+\fB uid_t \fP\fIowner\fP\fB, gid_t \fP\fIgroup\fP\fB, int \fP\fIflags\fP\fB);\fP
+.fi
+.sp
.sp
.in -4n
glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照):
.br
|| /* glibc 2.12 以降: */ _POSIX_C_SOURCE\ >=\ 200809L
.RE
+.sp
+\fBfchownat\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
.ad
.PD
.SH 説明
-これらのシステムコールは、いずれもファイルの所有者 (owner) とグループを変更する。システムコール間の違いは、ファイルの指定の仕方だけである。
+これらのシステムコールは、いずれもファイルの所有者 (owner) とグループを変更する。システムコール \fBchown\fP(),
+\fBfchown\fP(), \fBlchown\fP() 間の違いは、ファイルの指定の仕方だけである。
.IP * 2
-\fBchown\fP() は \fIpath\fP で指定されたファイルの所有権を変更する。 \fIpath\fP
+\fBchown\fP() は \fIpathname\fP で指定されたファイルの所有権を変更する。 \fIpathname\fP
がシンボリックリンクの場合は、リンクの展開が行われる。
.IP *
\fBfchown\fP() はオープンされたファイルディスクリプタ \fIfd\fP により参照されるファイルの所有権を変更する。
における動作はカーネルのバージョンに依存する。 非グループ実行ファイル (\fBS_IXGRP\fP ビットが設定されていないファイル) の場合には
\fBS_ISGID\fP ビットは強制ロック (mandatory locking) を意味している。 そしてそれは \fBchown\fP()
ではクリアできない。
+.SS fchownat()
+The \fBfchownat\fP() system call operates in exactly the same way as
+\fBchown\fP(), except for the differences described here.
+
+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 \fBchown\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 \fBchown\fP()).
+
+If \fIpathname\fP is absolute, then \fIdirfd\fP is ignored.
+
+The \fIflags\fP argument is a bit mask created by ORing together 0 or more of
+the following values;
+.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). 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_SYMLINK_NOFOLLOW\fP
+If \fIpathname\fP is a symbolic link, do not dereference it: instead operate on
+the link itself, like \fBlchown\fP(). (By default, \fBfchownat\fP() dereferences
+symbolic links, like \fBchown\fP().)
+.PP
+See \fBopenat\fP(2) for an explanation of the need for \fBfchownat\fP().
.SH 返り値
成功した場合は 0 が返される。エラーの場合は \-1 が返され、 \fIerrno\fP が適切に設定される。
.SH エラー
-ファイルシステムによっては他のエラーが返される事がある。 \fBchmod\fP で一般的なエラーを以下に挙げる。
+Depending on the filesystem, errors other than those listed below can be
+returned.
+
+The more general errors for \fBchown\fP() are listed below.
.TP
\fBEACCES\fP
パス名の構成要素に検索許可がない (\fBpath_resolution\fP(7) も見よ)。
.TP
\fBEFAULT\fP
-\fIpath\fP がアクセスできるアドレス空間外を指している。
+\fIpathname\fP がアクセス可能なアドレス空間の外を指している。
.TP
\fBELOOP\fP
-\fIpath\fP を解決する際に遭遇したシンボリックリンクが多過ぎる。
+\fIpathname\fP を解決するときに、解決すべきシンボリックリンクが多すぎた。
.TP
\fBENAMETOOLONG\fP
-\fIpath\fP が長過ぎる。
+\fIpathname\fP が長過ぎる。
.TP
\fBENOENT\fP
ファイルが存在しない。
.TP
\fBEROFS\fP
上記を参照。
+.PP
+The same errors that occur for \fBchown\fP() can also occur for
+\fBfchownat\fP(). The following additional errors can occur for \fBfchownat\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 バージョン
+\fBfchownat\fP() was added to Linux in kernel 2.6.16; library support was
+added to glibc in version 2.4.
.SH 準拠
-4.4BSD, SVr4, POSIX.1\-2001.
+\fBchown\fP(), \fBfchown\fP(), \fBlchown\fP(): 4.4BSD, SVr4, POSIX.1\-2001,
+POSIX.1\-2008.
.\" chown():
.\" SVr4 documents EINVAL, EINTR, ENOLINK and EMULTIHOP returns, but no
.\" SVr4 documents additional EINVAL, EIO, EINTR, and ENOLINK
.\" error conditions.
4.4BSD 版ではスーパーユーザーのみが使用できる (つまり、普通のユーザーはファイルを手放すことはできない)。
+
+\fBfchownat\fP(): POSIX.1\-2008.
.SH 注意
元々の Linux の \fBchown\fP(), \fBfchown\fP(), \fBlchown\fP() システムコールは、
16 ビットのユーザ ID とグループ ID だけに対応していた。
以下のプログラムは、 二つ目のコマンドライン引き数で指定された名前のファイルの所有者を、 一つ目のコマンドライン引き数で指定された値に変更する。
新しい所有者は、数字のユーザ ID かユーザ名のいずれかで指定できる (ユーザ名で指定した場合には、 \fBgetpwnam\fP(3)
を使ってシステムのパスワードファイルの検索が行われ、 ユーザ ID への変換が行われる)。
+.SS "Program source"
.nf
-
#include <pwd.h>
#include <stdio.h>
#include <stdlib.h>
}
.fi
.SH 関連項目
-\fBchmod\fP(2), \fBfchownat\fP(2), \fBflock\fP(2), \fBpath_resolution\fP(7),
-\fBsymlink\fP(7)
+\fBchmod\fP(2), \fBflock\fP(2), \fBpath_resolution\fP(7), \fBsymlink\fP(7)
.SH この文書について
-この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.54 の一部
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.63 の一部
である。プロジェクトの説明とバグ報告に関する情報は
http://www.kernel.org/doc/man\-pages/ に書かれている。