4

bash's man page (and help cd) mentions that cd supports a -@ parameter ("on systems that support it") to "present a file with extended attributes as a directory containing the file attributes"

Is there an example of using this? (Ideally with a commonly present file, or with a setup to create an example (I'm not familiar enough with xattr currnelt))

Where is it supported? Everywhere supporting xattrs, or is there more kernel support needed? (i.e. Can I use it with an xattr-supporting version of OS X, Solaris, FreeBSD, Linux, etc)

My guess is that if a file, /path/f has xattrs I can do cd -@ /path/f and ls would then show xattrs as (emulated) "files" in the emulated "directory" /path/f? (For this, I assume that the kernel need some kind of support for this simulation, since things like ls live outside bash, which means that bash can't be doing the emulation)

3
  • Related: Examples of options to bash cd, eg: cd -Pe@ $directory. Commented Feb 27, 2019 at 8:21
  • I tried setfattr on WSL and get setfattr: test: Operation not supported, so I'm assuming I need to try a real Linux to see if I can create an xattr on a file for my own testing... (A random XFS and ext4 filesystem gets the same result with the default mount options) (I know OS X makes extended use of xattrs, so it might be testable there) Commented Feb 27, 2019 at 8:29
  • @StephenKitt Useful, but no info on -@ beyond the man page or help output there either... Commented Feb 27, 2019 at 8:31

1 Answer 1

6

I think -@ is only supported on Solaris (and systems based on Solaris, such as Illumos). On Solaris, extended attributes can be considered as files in an orthogonal name space; in theory, any file (in the general sense, including directories etc.) can have extended attributes, which themselves can have extended attributes, etc. In order to explore this forest of attributes, there are APIs which allow them to be handled as a tree of files, and this is what cd -@ uses (and -@ on other commands). See fsattr(5) for details. This can be limited depending on the supporting file system; for example UFS doesn’t allow directories to be used as attributes, and doesn’t allow attributes to have attributes themselves.

On Solaris, the way this appears to the user is as you suggest:

~$ touch test
~$ cd -@ test
/proc/1604/fd/6$ ls
SUNWattr_ro  SUNWattr_rw
/proc/1604/fd/6$ touch attribute

This creates an “attribute” extended attribute file attached to the “test” file. cd -@ attribute works too, inside the attribute tree, and one can continue down the rabbit hole.

A similar extended attribute API was floated recently (January 2019) for Linux, notably as part of a discussion on fs-verity.

1
  • 1
    Ah, I didin't realise that extended attributes differ that significantly between *nixes... (Other than to a "not enabled" or "not supported" level) Commented Feb 27, 2019 at 8:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .