57

Where are filenames stored on a filesystem?

It's not in inode or with the actual file content since we have hard link that two filenames can point to the same inode.

4
  • 4
    Strictly speaking, that depends entirely on which filesystem you are talking about. Not all of them have inodes (or even directories). Feb 28, 2014 at 14:26
  • NTFS or FAT12/16/32 and many other filesystems don't have any inode
    – phuclv
    Feb 28, 2014 at 15:10
  • Many files have more than a name in more than one directories. All files of type directory have at least 2 names, one of them being . in themselves. Mar 31, 2014 at 20:58
  • @LưuVĩnhPhúc, ntfs does.. it just calls it an MFT record, but it's pretty much an inode.
    – psusi
    Apr 1, 2014 at 1:10

3 Answers 3

73

I wasn't finding a suitable duplicate so here's an answer to your question.

File names & directories

excerpt

File names and directory implications:

  • inodes do not contain file names, only other file metadata.
  • Unix directories are lists of association structures, each of which contains one filename and one inode number.
  • The file system driver must search a directory looking for a particular filename and then convert the filename to the correct corresponding inode number.

Source: Wikipedia page on Inode

So the name of the file is stored within the directories' information structure. For example:

                         ss of fs

Directory's structure

excerpt

In the EXT2 file system, directories are special files that are used to create and hold access paths to the files in the file system. Figure 9.3 shows the layout of a directory entry in memory.

A directory file is a list of directory entries, each one containing the following information:

  • inode - The inode for this directory entry. This is an index into the array of inodes held in the Inode Table of the Block Group. In figure 9.3, the directory entry for the file called file has a reference to inode number i1,
  • name length - The length of this directory entry in bytes,
  • name - The name of this directory entry.

The first two entries for every directory are always the standard . and .. entries meaning "this directory" and "the parent directory" respectively.

Here's the Figure 9.3 references above:

                 ss #2

Source: The Linux Documentation Project: Filesystem

References

9

The file name is stored in the respective directory ("directory file"). This entry points to an inode.

2
  • 1
    I can't see how symlink targets could end-up in directory entries. The symlink target may be found in the symlink's inode, but not in (any of) the directory entry that symlink is linked to, that would not make sense. Mar 31, 2014 at 20:57
  • 1
    @StéphaneChazelas, the symlink itself simply contains another name that should be opened instead. The name lookup starts again on the new name, which ( if it exists at all ) is a directory entry somewhere.
    – psusi
    Jun 3, 2015 at 1:50
5

Filenames are stored in the directory data structures, which have the filename (a string) and the corresponding inode number.

directory is responsible for mapping filename --> inode.

and inode is responsible for mapping data area location --> sector on disk.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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