Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Where is filename 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.

share|improve this question
4  
Strictly speaking, that depends entirely on which filesystem you are talking about. Not all of them have inodes (or even directories). –  Michael Borgwardt Feb 28 at 14:26
    
NTFS or FAT12/16/32 and many other filesystems don't have any inode –  Lưu Vĩnh Phúc Feb 28 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. –  Stéphane Chazelas Mar 31 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 at 1:10

2 Answers 2

up vote 27 down vote accepted

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

share|improve this answer

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

share|improve this answer
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. –  Stéphane Chazelas Mar 31 at 20:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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