Provided by: manpages-ja-dev_0.5.0.0.20221215+dfsg-1_all bug

名前

       umask - ファイルモード作成マスクを設定する

書式

       #include <sys/types.h>
       #include <sys/stat.h>

       mode_t umask(mode_t mask);

説明

       umask()  は、呼び出し元プロセスのファイルモード作成マスク (umask) を mask & 0777 に設定し (umask のファイ
       ル許可に対応するビットのみを使用する)、 変更前のマスク値を返す。

       umask  は、  open(2), mkdir(2)  やファイル作成を行うその他のシステムコールで、 新しく作成されるファイルや
       ディレクトリの許可 (permission) を  修正するために使用される。  具体的には  umask  に設定されている許可が
       open(2)  や mkdir(2)  の mode 引数から取り消される。

       Alternatively,  if the parent directory has a default ACL (see acl(5)), the umask is ignored, the default
       ACL is inherited, the permission bits are set based on the inherited ACL, and permission bits  absent  in
       the  mode  argument  are  turned off.  For example, the following default ACL is equivalent to a umask of
       022:

           u::rwx,g::r-x,o::r-x

       Combining the effect of this default ACL with a mode argument of 0666  (rw-rw-rw-),  the  resulting  file
       permissions would be 0644 (rw-r--r--).

       mask に指定するのに使用すべき定数については inode(7) で説明されている。

       プロセスの umask のよくあるデフォルト値は S_IWGRP | S_IWOTH (8進で 022) である。 新しいファイルを作成する
       際に open(2)  の mode 引数に

            S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH

       を指定するというよくあるケースでは、作成されたファイルは

            S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH

       (because 0666 & ~022 = 0644; i.e., rw-r--r--).

返り値

       このシステムコールは必ず成功し、以前の umask 値を返す。

準拠

        POSIX.1-2001, POSIX.1-2008, SVr4, 4.3BSD.

注意

       fork(2)  で作成された子プロセスは、親プロセスの umask を継承する。 execve(2)  によって umask は変更されな
       い。

       It  is  impossible  to  use  umask()  to fetch a process's umask without at the same time changing it.  A
       second call to umask()  would then be needed to restore the umask.  The nonatomicity of these  two  steps
       provides the potential for races in multithreaded programs.

       Since  Linux  4.7,  the  umask  of  any  process can be viewed via the Umask field of /proc/[pid]/status.
       Inspecting this field in /proc/self/status allows a process to retrieve its umask  without  at  the  same
       time changing it.

       umask  の設定は、そのプロセスが生成する POSIX IPC オブジェクト (mq_open(3), sem_open(3), shm_open(3))  や
       FIFO (mkfifo(3))、 UNIX ドメインソケット (unix(7)) に設定される許可にも影響を与える。 一方、umask  は、そ
       のプロセスが (msgget(2), semget(2), shmget(2)  を使って) 生成する System V IPC オブジェクトに設定される許
       可には 影響を与えない。

関連項目

       chmod(2), mkdir(2), open(2), stat(2), acl(5)

この文書について

       この  man ページは Linux man-pages プロジェクトのリリース 5.10 の一部である。プロジェクトの説明とバグ報告
       に関する情報は https://www.kernel.org/doc/man-pages/ に書かれている。

Linux                                               2020-08-13                                          UMASK(2)