std::experimental::filesystem:: perms
|
ヘッダーで定義
<experimental/filesystem>
|
||
|
enum
class
perms
;
|
(filesystem TS) | |
この型はファイルアクセス権限を表します。
perms
は
BitmaskType
の要件を満たします
(これはビット単位演算子
operator
&
、
operator
|
、
operator
^
、
operator~
、
operator
&
=
、
operator
|
=
、および
operator
^
=
がこの型に対して定義されていることを意味します)。
アクセス権限モデル POSIX permission bits および個々のファイル権限( status によって報告される)は、以下のビットの組み合わせです:
目次 |
メンバー定数
| メンバー定数 | 値(8進数) | POSIX 相当値 | 意味 |
|---|---|---|---|
none
|
0 | パーミッションビットが設定されていない | |
owner_read
|
0400 | S_IRUSR | ファイル所有者に読み取り権限がある |
owner_write
|
0200 | S_IWUSR | ファイル所有者に書き込み権限がある |
owner_exec
|
0100 | S_IXUSR | ファイル所有者に実行/検索権限がある |
owner_all
|
0700 | S_IRWXU |
ファイル所有者に読み取り、書き込み、実行/検索権限がある
以下と同等: owner_read | owner_write | owner_exec |
group_read
|
040 | S_IRGRP | ファイルのユーザーグループに読み取り権限がある |
group_write
|
020 | S_IWGRP | ファイルのユーザーグループに書き込み権限がある |
group_exec
|
010 | S_IXGRP | ファイルのユーザーグループに実行/検索権限がある |
group_all
|
070 | S_IRWXG |
ファイルのユーザーグループに読み取り、書き込み、実行/検索権限がある
以下と同等: group_read | group_write | group_exec |
others_read
|
04 | S_IROTH | 他のユーザーに読み取り権限がある |
others_write
|
02 | S_IWOTH | 他のユーザーに書き込み権限がある |
others_exec
|
01 | S_IXOTH | 他のユーザーに実行/検索権限がある |
others_all
|
07 | S_IRWXO |
他のユーザーに読み取り、書き込み、実行/検索権限がある
以下と同等: others_read | others_write | others_exec |
all
|
0777 |
すべてのユーザーに読み取り、書き込み、実行/検索権限がある
以下と同等: owner_all | group_all | others_all |
|
set_uid
|
04000 | S_ISUID | 実行時にユーザーIDをファイル所有者のユーザーIDに設定する |
set_gid
|
02000 | S_ISGID | 実行時にグループIDをファイルのユーザーグループIDに設定する |
sticky_bit
|
01000 | S_ISVTX | 実装定義の意味を持つが、POSIX XSIではディレクトリに設定された場合、他のユーザーに書き込み権限があってもファイル所有者のみがファイルを削除できることを規定する( / tmp で使用される) |
mask
|
07777 |
すべての有効なパーミッションビット
以下と同等: all | set_uid | set_gid | sticky_bit |
さらに、この型で定義されている以下の定数は、権限を表すものではありません:
| メンバー定数 | 値 (16進数) | 意味 |
|---|---|---|
unknown
|
0xFFFF | 不明なパーミッション(例: file_status がパーミッションなしで作成された場合) |
add_perms
|
0x10000 | permissions にパーミッションビットを追加するがクリアしないように指示する制御ビット |
remove_perms
|
0x20000 | permissions にパーミッションビットをクリアするが追加しないように指示する制御ビット |
resolve_symlinks
|
0x40000 | permissions にシンボリックリンクを解決するように指示する制御ビット |
注記
権限は必ずしもビットとして実装されるわけではありませんが、概念的にはそのように扱われます。
一部のパーミッションビットは一部のシステムで無視される可能性があり、また一部のビットを変更すると自動的に他のビットが変更される場合があります(例:所有者/グループ/全ユーザーの区別がないプラットフォームでは、3つの書き込みビットのいずれかを設定すると、3つすべてが設定されます)。
例
#include <bitset> #include <experimental/filesystem> #include <fstream> #include <iostream> namespace fs = std::experimental::filesystem; void demo_perms(fs::perms p) { std::cout << ((p & fs::perms::owner_read) != fs::perms::none ? "r" : "-") << ((p & fs::perms::owner_write) != fs::perms::none ? "w" : "-") << ((p & fs::perms::owner_exec) != fs::perms::none ? "x" : "-") << ((p & fs::perms::group_read) != fs::perms::none ? "r" : "-") << ((p & fs::perms::group_write) != fs::perms::none ? "w" : "-") << ((p & fs::perms::group_exec) != fs::perms::none ? "x" : "-") << ((p & fs::perms::others_read) != fs::perms::none ? "r" : "-") << ((p & fs::perms::others_write) != fs::perms::none ? "w" : "-") << ((p & fs::perms::others_exec) != fs::perms::none ? "x" : "-") << '\n'; } int main() { std::ofstream("test.txt"); // ファイル作成 std::cout << "作成されたファイルのパーミッション: "; demo_perms(fs::status("test.txt").permissions()); fs::permissions("test.txt", fs::perms::add_perms | fs::perms::owner_all | fs::perms::group_all); std::cout << "o+rwx と g+rwx を追加後: "; demo_perms(fs::status("test.txt").permissions()); fs::remove("test.txt"); }
出力例:
作成されたファイルのパーミッション: rw-r--r-- o+rwx と g+rwx を追加後: rwxrwxr--
関連項目
|
ファイル属性を決定する
シンボリックリンクのターゲットをチェックしてファイル属性を決定する (function) |
|
|
ファイルアクセス権限を変更する
(function) |