「拡張属性」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
タグ: 新規リダイレクト
 
(英語版から)
タグ: リダイレクト解消
1行目: 1行目:
  +
[[en:Extended attributes]]
#REDIRECT[[ファイルのパーミッションと属性#拡張属性]]
 
  +
  +
From {{man|7|xattr}}: "Extended attributes are name:value pairs associated
  +
permanently with files and directories". There are four extended attribute
  +
classes: security, system, trusted and user.
  +
  +
{{Warning|By default, extended attributes are not preserved by [[cp]], [[rsync]], and other similar programs, see [[#Preserving extended attributes]].}}
  +
  +
Extended attributes are also used to set [[Capabilities]].
  +
  +
=== ユーザ拡張属性 ===
  +
  +
User extended attributes can be used to store arbitrary information about a
  +
file. To create one:
  +
  +
$ setfattr -n user.checksum -v "3baf9ebce4c664ca8d9e5f6314fb47fb" foo.txt
  +
  +
Use getfattr to display extended attributes:
  +
  +
{{hc|$ getfattr -d foo.txt|2=
  +
# file: foo.txt
  +
user.checksum="3baf9ebce4c664ca8d9e5f6314fb47fb"
  +
}}
  +
  +
Finally, to remove an extended attribute:
  +
$ setfattr -x user.checksum foo.txt
  +
  +
some other user xattrs include:
  +
* {{ic|user.mime_type}}: helps programs know mimetype and set it with less guesswork.
  +
* {{ic|user.charset}}: used by the Apache httpd module [http://0pointer.de/lennart/projects/mod_mime_xattr mod_mime_xattr].
  +
* {{ic|user.creator}}: The name of the application that created the file.
  +
  +
XDG also proposes a set of standardized xattrs to be used by programs:
  +
* {{ic|user.xdg.comment}}: supported by Dolphin and other file managers.
  +
* {{ic|user.xdg.origin.url}}: for files downloaded from a url.
  +
* {{ic|user.xdg.robots.index}}: "true" if a file is included in indexing, "false" otherwise
  +
* {{ic|user.xdg.robots.backup}}: "true" if a file is included in backup, "false" otherwise
  +
* {{ic|user.xdg.language}}
  +
* {{ic|user.xdg.creator}}
  +
* {{ic|user.xdg.publisher}}
  +
* {{ic|user.xdg.origin.email.subject}}
  +
* {{ic|user.xdg.origin.email.from}}
  +
* {{ic|user.xdg.origin.email.message-id}}
  +
  +
=== 拡張属性を保持する ===
  +
  +
{| class="wikitable"
  +
! Command || Required flag
  +
|-
  +
| {{ic|cp}} || {{ic|1=--preserve=mode,ownership,timestamps,xattr}}
  +
|-
  +
| {{ic|mv}} || {{Y|preserves by default<sup>1}}
  +
|-
  +
| {{ic|tar}} || {{ic|--xattrs}} for creation and {{ic|1=--xattrs-include='*'}} for extraction
  +
|-
  +
| {{ic|bsdtar}} || {{ic|-p}} for extraction
  +
|-
  +
| [[rsync]] || {{ic|-X, --xattrs}}
  +
|-
  +
| {{pkg|cpio}} || {{No}}
  +
|-
  +
| {{pkg|gzip}} || {{No}}
  +
|-
  +
| {{pkg|pax}} || {{No}}
  +
|}
  +
  +
# mv silently discards extended attributes when the target file system does not support them.
  +
  +
To preserve extended attributes with [[text editor]]s you need to configure them
  +
to truncate files on saving instead of using {{man|2|rename}}. [https://unix.stackexchange.com/questions/45407]
  +
  +
== サポート ==
  +
  +
=== ファイルシステム ===
  +
  +
All major Linux file systems including ext, btrfs, zfs, xfs, and more support
  +
xattrs. The kernel allows to have xattrs names of up to 255 bytes and values of
  +
up to 64 KiB, but ext and btrfs might impose smaller limits, requiring xattrs to
  +
be within a "filesystem block".
  +
  +
[[NTFS]] uses Alternative Data Streams to store user. The mount option
  +
{{ic|user_xattr}} or {{ic|1=streams_interface=xattr}} should be used by default. However it
  +
might not be supported if mount option {{ic|1=streams_interface=windows}} is used.
  +
{{pkg|ntfs-3g}} supports mapping ADS to extended attributes in FUSE.
  +
  +
NFS does not currently support xattrs.
  +
  +
=== ファイルマネージャ ===
  +
  +
Legend:
  +
# Preserved: whether xattrs are preserved when copied or moved.
  +
# Tags: whether tags xattrs are supported.
  +
  +
{| class="wikitable"
  +
! File manager
  +
! Preserved
  +
! Tags
  +
|-
  +
| [[dolphin]]
  +
| {{No}}
  +
|
  +
|-
  +
| [[thunar]]
  +
| {{Yes}}
  +
|
  +
|-
  +
| {{pkg|caja}}
  +
|
  +
| {{Yes}}<sup>1
  +
|-
  +
| [[nautilus]]
  +
|
  +
|
  +
|}
  +
  +
# caja: supported by caja-xattr-tags and caja.eiciel extensions.
  +
  +
=== プログラム ===
  +
  +
{| class="wikitable"
  +
! Application
  +
! Supported xattrs
  +
! Supported since
  +
! Notes
  +
|-
  +
| {{pkg|baloo}}
  +
| {{ic|user.xdg.tags}}
  +
|
  +
|
  +
|-
  +
| [[Chromium]]
  +
| {{ic|user.xdg.origin}},{{ic|user.xdg.referrer}}
  +
|
  +
|
  +
|-
  +
| [[CURL]]
  +
|
  +
|
  +
|
  +
|-
  +
| [[Dropbox]]
  +
| {{ic|user.com.dropbox.attributes}}
  +
|
  +
|
  +
|-
  +
| [[emacs|emacs-vm]]
  +
| {{No}}
  +
|
  +
| Resets mbox xattrs.
  +
|-
  +
| [[Gwenview]]
  +
| {{ic|user.xdg.tags}}
  +
|
  +
|
  +
|-
  +
| {{pkg|recoll}}
  +
| {{ic|user.xdg.tags}}
  +
|
  +
|
  +
|-
  +
| {{AUR|tmsu}}
  +
| {{No|1=https://github.com/oniony/TMSU/issues/10}}
  +
|
  +
|
  +
|-
  +
| {{AUR|tagspaces}}
  +
| {{No|1=https://trello.com/c/iapsXZZe/64-option-to-store-tags-in-file-using-extended-attributes-xattr}}
  +
|
  +
|
  +
|-
  +
| [[Wget]]
  +
|
  +
|
  +
|
  +
|}
  +
  +
== 参照 ==
  +
  +
* [https://www.freedesktop.org/wiki/CommonExtendedAttributes XDG guidelines for extended attributes]
  +
* [[wikipedia:Extended file attributes#Linux]]
  +
* [https://www.lesbonscomptes.com/pages/extattrs.html Extended attributes: the good, the not so good, the bad.]

2023年8月12日 (土) 10:13時点における版


From xattr(7): "Extended attributes are name:value pairs associated permanently with files and directories". There are four extended attribute classes: security, system, trusted and user.

警告: By default, extended attributes are not preserved by cp, rsync, and other similar programs, see #Preserving extended attributes.

Extended attributes are also used to set Capabilities.

ユーザ拡張属性

User extended attributes can be used to store arbitrary information about a file. To create one:

$ setfattr -n user.checksum -v "3baf9ebce4c664ca8d9e5f6314fb47fb" foo.txt

Use getfattr to display extended attributes:

$ getfattr -d foo.txt
# file: foo.txt
user.checksum="3baf9ebce4c664ca8d9e5f6314fb47fb"

Finally, to remove an extended attribute:

$ setfattr -x user.checksum foo.txt

some other user xattrs include:

  • user.mime_type: helps programs know mimetype and set it with less guesswork.
  • user.charset: used by the Apache httpd module mod_mime_xattr.
  • user.creator: The name of the application that created the file.

XDG also proposes a set of standardized xattrs to be used by programs:

  • user.xdg.comment: supported by Dolphin and other file managers.
  • user.xdg.origin.url: for files downloaded from a url.
  • user.xdg.robots.index: "true" if a file is included in indexing, "false" otherwise
  • user.xdg.robots.backup: "true" if a file is included in backup, "false" otherwise
  • user.xdg.language
  • user.xdg.creator
  • user.xdg.publisher
  • user.xdg.origin.email.subject
  • user.xdg.origin.email.from
  • user.xdg.origin.email.message-id

拡張属性を保持する

Command Required flag
cp --preserve=mode,ownership,timestamps,xattr
mv preserves by default1
tar --xattrs for creation and --xattrs-include='*' for extraction
bsdtar -p for extraction
rsync -X, --xattrs
cpio No
gzip No
pax No
  1. mv silently discards extended attributes when the target file system does not support them.

To preserve extended attributes with text editors you need to configure them to truncate files on saving instead of using rename(2). [1]

サポート

ファイルシステム

All major Linux file systems including ext, btrfs, zfs, xfs, and more support xattrs. The kernel allows to have xattrs names of up to 255 bytes and values of up to 64 KiB, but ext and btrfs might impose smaller limits, requiring xattrs to be within a "filesystem block".

NTFS uses Alternative Data Streams to store user. The mount option user_xattr or streams_interface=xattr should be used by default. However it might not be supported if mount option streams_interface=windows is used. ntfs-3g supports mapping ADS to extended attributes in FUSE.

NFS does not currently support xattrs.

ファイルマネージャ

Legend:

  1. Preserved: whether xattrs are preserved when copied or moved.
  2. Tags: whether tags xattrs are supported.
File manager Preserved Tags
dolphin No
thunar Yes
caja Yes1
nautilus
  1. caja: supported by caja-xattr-tags and caja.eiciel extensions.

プログラム

Application Supported xattrs Supported since Notes
baloo user.xdg.tags
Chromium user.xdg.origin,user.xdg.referrer
CURL
Dropbox user.com.dropbox.attributes
emacs-vm No Resets mbox xattrs.
Gwenview user.xdg.tags
recoll user.xdg.tags
tmsuAUR No
tagspacesAUR No
Wget

参照