xattr/扩展属性对于 /tmp 中的文件不可设置,而在同一安装上的 $home 中工作正常

THX*_*THX 2 linux file-attributes tmpfs xattr

我正在 Linux/Fedora 下使用扩展文件属性,目前我遇到了一些困难,因为我无法添加/更改文件的属性,而在/tmp我家里它工作正常 - 虽然两个路径都在同一个挂载点上,即,

/dev/mapper/fedora-root on / type ext4 (rw,relatime,seclabel,data=ordered)
Run Code Online (Sandbox Code Playgroud)

例如,我可以成功添加和检索主目录中文件的属性,例如

> setfattr -n user.test.md5 -v 58d8e4cd0e60facf386838cbe8b11767 ~/foo.bar
> getfattr -n user.test.md5 ~/foo.bar 
  # file: foo.bar
  user.test.md5="58d8e4cd0e60facf386838cbe8b11767"
Run Code Online (Sandbox Code Playgroud)

但是,对于 中的同一文件,同样会失败/tmp

> cp ~/foo.bar /tmp/foo.bar
> setfattr -n user.test.md5 -v 58d8e4cd0e60facf386838cbe8b11767 /tmp/foo.bar 
  setfattr: /tmp/foo.bar: Operation not supported
Run Code Online (Sandbox Code Playgroud)

我假设,对扩展属性的支持仅取决于使用 xattr 支持“正确”安装的文件系统。但是,它似乎也依赖于目录(??),我想知道,是什么阻止我在 /tmp 中设置扩展属性以及如何更改它?(这似乎与 SELinux 无关——至少我在审核日志中没有找到任何内容。)

小智 5

CONFIG_TMPFS_XATTR如果在内核配置中启用,tmpfs可以支持扩展属性。从版本 5.9.3 开始,这仅支持trusted.*security.*命名空间,因此您的setfattr -n user.test.md5命令仍然会失败。