Welcome to the Linux Foundation Forum!

Directory file

Options
Battogtokh
Battogtokh Posts: 23

I have just finished chapters covering about filesystem. But I am keep wondering where does the directory file is created and kept when creating filesystem using mkfs. I understand that files are accessed by referring file name and inode association in "directory file". I understood that Operating system kernel VFS abstraction layer is used for showing up all directory entries from "directory file" when we browse through the directory. I think, the directory file cannot be edited manually and that's why it is hidden in somewhere. I am keep wondering where does kernel keep the "directory file" for the filesystem. Does it store it in same filesystem or in different place? VFS need to look for the directory file for the user to when he/she browse through the directory right? Can you please explain me from where VFS abstraction layer finds the "directory file" which can show them list of file names?

Thank you very much.

Comments

  • luisviveropena
    luisviveropena Posts: 1,154
    edited January 2017
    Options

    Hi,

    Yes, it's hidden, so you won't find it in the filesystem.

    This started like this with ext2, from http://tldp.org/LDP/tlk/fs/filesystem.html

    9.2.5  Finding a File in the Virtual File System

    To find the VFS inode of a file in the Virtual File System, VFS must resolve the name a directory at a time, looking up the VFS inode representing each of the intermediate directories in the name. Each directory lookup involves calling the file system specific lookup whose address is held in the VFS inode representing the parent directory. This works because we always have the VFS inode of the root of each file system available and pointed at by the VFS superblock for that system. Each time an inode is looked up by the real file system it checks the directory cache for the directory. If there is no entry in the directory cache, the real file system gets the VFS inode either from the underlying file system or from the inode cache.

    Then with ex4, from https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout

    Hash Tree Directories

    A linear array of directory entries isn't great for performance, so a new feature was added to ext3 to provide a faster (but peculiar) balanced tree keyed off a hash of the directory entry name. If the EXT4_INDEX_FL (0x1000) flag is set in the inode, this directory uses a hashed btree (htree) to organize and find directory entries. For backwards read-only compatibility with ext2, this tree is actually hidden inside the directory file, masquerading as "empty" directory data blocks! It was stated previously that the end of the linear directory entry table was signified with an entry pointing to inode 0; this is (ab)used to fool the old linear-scan algorithm into thinking that the rest of the directory block is empty so that it moves on.

    [...]

     

    Regards,

    Luis.

  • Battogtokh
    Battogtokh Posts: 23
    edited January 2017
    Options

    I really appreciate the answer. Now i have understanding how VFS shows the directory tree when browsing.

  • luisviveropena
    luisviveropena Posts: 1,154
    edited January 2017
    Options

    It's a pleasure :)

    Regards,

    Luis.

Categories

Upcoming Training