From the article Anatomy of the Linux file system by M. Tim Jones, I read that Linux views all the file systems from the perspective of a common set of objects and these objects are superblock, inode, dentry and file. Even though the rest of the paragraph explains the above, I was not that comfortable with that explanation.

Could somebody explain to me these terms?

up vote 119 down vote accepted

First and foremost, and I realize that it was not one of the terms from your question, you must understand metadata. Succinctly, and stolen from Wikipedia, metadata is data about data. That is to say that metadata contains information about a piece of data. For example, if I own a car then I have a set of information about the car but which is not part of the car itself. Information such as the registration number, make, model, year of manufacture, insurance information, and so on. All of that information is collectively referred to as the metadata. In Linux and UNIX file systems metadata exists at multiple levels of organization as you will see.

The superblock is essentially file system metadata and defines the file system type, size, status, and information about other metadata structures (metadata of metadata). The superblock is very critical to the file system and therefore is stored in multiple redundant copies for each file system. The superblock is a very "high level" metadata structure for the file system. For example, if the superblock of a partition, /var, becomes corrupt then the file system in question (/var) cannot be mounted by the operating system. Commonly in this event, you need to run fsck which will automatically select an alternate, backup copy of the superblock and attempt to recover the file system. The backup copies themselves are stored in block groups spread through the file system with the first stored at a 1 block offset from the start of the partition. This is important in the event that a manual recovery is necessary. You may view information about superblock backups with the command dumpe2fs /dev/foo | grep -i superblock which is useful in the event of a manual recovery attempt. Let us suppose that the dumpe2fs command outputs the line Backup superblock at 163840, Group descriptors at 163841-163841. We can use this information, and additional knowledge about the file system structure, to attempt to use this superblock backup: /sbin/fsck.ext3 -b 163840 -B 1024 /dev/foo. Please note that I have assumed a block size of 1024 bytes for this example.

An inode exists in, or on, a file system and represents metadata about a file. For clarity, all objects in a Linux or UNIX system are files; actual files, directories, devices, and so on. Please note that, among the metadata contained in an inode, there is no file name as humans think of it, this will be important later. An inode contains essentially information about ownership (user, group), access mode (read, write, execute permissions) and file type.

A dentry is the glue that holds inodes and files together by relating inode numbers to file names. Dentries also play a role in directory caching which, ideally, keeps the most frequently used files on-hand for faster access. File system traversal is another aspect of the dentry as it maintains a relationship between directories and their files.

A file, in addition to being what humans typically think of when presented with the word, is really just a block of logically related arbitrary data. Comparatively very dull considering all of the work done (above) to keep track of them.

I fully realize that a few sentences do not provide a full explanation of any of these concepts so please feel free to ask for additional details when and where necessary.

  • "The superblock is very critical to the file system and therefore is stored in multiple redundant copies for each file system". Could you please explain this a bit more in detail? Why is that multiple redundant copies are there? – Sen Nov 30 '10 at 10:50
  • @Sen - Certainly. My explanation became too long for a convenient comments so I have included additional information in the response above. – Tok Nov 30 '10 at 11:32
  • @Tok : Will it dump like this (as shown in the answer) :Backup superblock at 163840, Group descriptors at 163841-163841 or is it this way : Backup superblock at 163840, Group descriptors at 163841-163842? Was that a typo error? :-) – Sen Nov 30 '10 at 13:44
  • @TOK : Backup superblock at 163840, Group descriptors at 163841-163842, What info does the Group Descriptors convey? – Sen Nov 30 '10 at 13:46
  • @Sen - theoretically the group descriptors could span multiple blocks, but for most desktop systems you will see them take only a single block and be referenced as $((BackupBlock+1))-$((BackupBlock+1)) – Tok Nov 30 '10 at 13:47

File

A file just means a bunch of bytes arranged in a certain order. It's what normal people call the contents of a file. When Linux opens a file, it also creates a file object, which holds data about where the file is stored and what processes are using it. The file object (but not the file data itself) is thrown away when the file is closed.

Inode

An inode (short for "index node") is a bunch of attributes about a file that Linux stores. There is one inode for each file (though with some filesystems, Linux has to create its own inodes because the information is spread around the filesystem). The inode stores information like who owns the file, how big the file is, and who is allowed to open the file. Each inode also contains a number unique to the filesystem partition; it's like a serial number for the file described by that inode.

Dentry

A dentry (short for "directory entry") is what the Linux kernel uses to keep track of the hierarchy of files in directories. Each dentry maps an inode number to a file name and a parent directory.

Superblock

The superblock is a unique data structure in a filesystem (though multiple copies exist to guard against corruption). The superblock holds metadata about the filesystem, like which inode is the top-level directory and the type of filesystem used.

superblock, the index node (or inode), the directory entry (or dentry), and finally, the file object are part of virtual file system (VFS) or virtual filesystem switch. The purpose of a VFS is to allow client applications to access different types of concrete file systems in a uniform way.

Relationships of major objects in the VFS

enter image description here


An Inode is a data structure on a Unix / Linux file system. An inode stores meta data about a regular file, directory, or other file system object. Inode acts as a interface between files and data. An inode can refer to a file or a directory or a symbolic link to another object. It contains a unique number (the i-number), the file's attributes, including name, date, size and read/write permissions, and a pointer to the file's location. It is the counterpart to the FAT table in the DOS/Windows world.

Programs, services, texts, images, and so forth, are all files. Input and output devices, and generally all devices, are considered to be files, according to the system.

The superblock is the container for high-level metadata about a file system. The superblock is a structure that exists on disk (actually, multiple places on disk for redundancy) and also in memory. It provides the basis for dealing with the on-disk file system, as it defines the file system's managing parameters (for example, total number of blocks, free blocks, root index node).

Dentry is interface between files and Inodes. Dentries also play a role in directory caching which, ideally, keeps the most frequently used files on-hand for faster access.

Source

Note that these terms aren't Linux specific but file system specific. Most filesystems used by current Unix and Unix like systems are either derived or inspired by the original Unix filesystem which defined the superblock and inode idioms. Linux can also mount several filesystems with which there is no notion of superblock and/or inode, the most common being FAT. Another one, ZFS, doesn't use superblocks but überblocks.

  • Hope you get to read this comment after so long. I read that VFS has inodes and superblocks that are unrelated to the inodes and superblocks of say EXT2. So, just not to misunderstand what you said, by virtue of every Linux having a VFS, they all should be using inodes and superblock, right? – CuriousKimchi Dec 29 '16 at 4:50
  • 1
    @CuriousKimchi Despite the fact they have the same name here, you shouldn't confuse information stored on disk (superblock/inodes) and structures used by the kernel to access a file system and its files. Every file system has some metadata on disk that describe the file system characteristics, this metadata is used to populate Linux VFS superblock structure. Similarly, files have an in kernel inode structure under VFS. When the underlying file systems lacks the notion of inode, this structure contains a fake inode number created on the fly by the OS. – jlliagre Dec 29 '16 at 7:35

In simplicity, dentry and inode are the same thing, an abstraction of file or directory. The differences between dentry and inode are that dentry is used to facilitate directory-specific operations, inode is just a collection of metadata about file or directory. Superblock is the abstraction of filesystem.

struct file, in linux kernle, is misnamed as lots of others(e.g. struct address_space) and is not a abstraction of a real "file"(e.g. /etc/passwd). It stands for a opened "file" or directory. struct file is created by sys_open in kernel, so a process can have a lot of struct file.

Why do we need dentry? It is used to speed up the translating from path name(e.g. /etc/passwd) to inode. Linux kernel use inode to manipulate "file" or directory, not their name.

protected by slm Dec 29 '13 at 3:25

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.