umask

Section: System Calls (2)
Updated: 2026-02-08
Index JM Home Page roff page
 

名前

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

ライブラリ

標準 C ライブラリ (libc,~-lc)  

書式

#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) で説明されている。

The typical default value for the process umask is S_IWGRP | S_IWOTH (octal 022). In the usual case where the mode argument to open(2) is specified as:

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-2008.  

歴史

POSIX.1-2001, 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)


 

Index

名前
ライブラリ
書式
説明
返り値
標準規格
歴史
注意
関連項目

This document was created by man2html, using the manual pages.