Linux – How to detect special hidden files in Linux (e.g. .reiser_priv)

filesystemslinux

I've recently found out that there are special hidden directories found on Linux that are not displayed with ls -a command. Namely the one I encountered is .reiserfs_priv directory located in the root of a reiserfs filesystem. I can call ls -ld .reiserfs_priv on it and cd into the directory (as root), but it is not shown with ls -a command (find ./ -name *reiser* doesn't find it as well).

Questions:

  • How do I actually detect this kind of directories?
  • Can I create them myself?
  • What kind of mechanism do they use to stay stealth and why ls -a doesn't see them?
  • Can it be files as well?
  • Where these type of directories are generally used?

Best Answer

You cannot detect or create such files in general. They only exist because a filesystem is reporting inconsistent data.

In the absence of modifications to the filesystem, there are redundancies between various ways of obtaining information about the files on that filesystem. For example, permissions permitting:

  • If a file name is reported by readdir then calling lstat on that name will succeed.
  • If lstat does not report the file to be a symbolic link, then calling stat and open will also succeed.
  • If stat succeeds then open succeeds`.
  • If open succeeds then so do stat and lstat.
  • If stat reports a file to be a directory then cd succeeds and vice versa.

And so on. When a Reiserfs filesystem omits the .reiserfs_priv entry from directory listings and yet reports it as a directory via system calls that access it directly, the filesystem is reporting inconsistent information.

This information isn't wrong, just inconsistent. It's only violating conventions, not rules. The same behavior could be observed if there was a very fast goblin who created that directory just before you ran cd or ls .reiserfs_priv, and removed it just before you ran find.

It is somewhat bad form for a filesystem to report inconsistent data, because that confuses some applications and users, so it should only be done for a very good reason. In the case of Reiserfs, the reason is to make some information rather hidden, and in particular not traversed by file searches and indexing. This is useful because the content of .reiserfs_priv is not “real” files, it's used to store extended file attributes, which are accessed by calling the *xattr system call family. In fact, I don't know why it's exposed at all — maybe only for debugging purposes.

Another example of not reporting files that exist is filesystems that allow the same data to be returned in different ways. For example, ciopfs presents a case-insensitive view of a filesystem; if you have a file called Foo then a directory listing will only list Foo but accessing foo, FOO, etc. will succeed.

Related Question