Email or username:

Password:

Forgot your password?
Lennart Poettering

Quiz: How many inode types are there on Linux?

You might think the answer to this is 7, i.e. regular files, directories, symlinks, block device nodes, char device nodes, fifos, and sockets. But you are actually are wrong: there's an 8th one. There's the concept of an anonymous inode on Linux which has the file type of zero. You can easily acquire fds to inodes of this type via eventfd(). If you call fstat() on such fds, then (.st_mode & S_IFMT) == 0 will hold. 🤯

6 comments
Lennart Poettering

And I am pretty sure there's a lot of software you might be able to break given that they do not expect this case on the most basic of fs concepts.

Also note that these anonymous inodes are not actually as anonymous as one might think: because open fds appear in /proc/self/fd/ as magic symlinks you can easily get am fs path when you call stat() on will return you a zero inode type.

Double 🤯🤯

Lennart Poettering

And note that they don't want you to know about the 8th, secret inode type! It's not mentioned in the inode(7) man page after all. But now I spilled the beans anyway!

Psst! 🤫

Jyrki :jyrki:🐾:heart_nb:

@pid_eins what’s the purpose of these inodes? do they have a practical use?

Lennart Poettering

@nilsding yes, a multitude of apis of the kernel expose these anonymous inodes these days. Eventfd, signalfd, epoll, inotify, and so on. Basically a good chunk of the kernel apis that give you an fd as a reference to some api object do this. Tremendously useful hence, and very common. But not particularly visible outside of programs since generally not visible in the fs except for /proc/self/fd/.

Jyrki :jyrki:🐾:heart_nb:

@pid_eins oooh, that makes sense actually. Never really questioned the origin of these fds before x)

Go Up