Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

The index nodes contain meta data and points to where the actual data is. But how does the system know where in the directory tree the file or folder is, and how does it translate the filename into an i-node?

An explanation from the file systems point-of-view of the process that happens when I request the file /folder/directory/filename would be much appreciated.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

A directory is technically just a file containing file names, their inode numbers, and attributes. In BSD and Plan9, you can even read it like a file. (Although on modern filesystems the on-disk format is some kind of a binary tree, not a sequential list.)

The basic process (for Unix-like paths) is:

  1. Split the given path into components separated by /
  2. The location of / is already known by the kernel.
  3. Scan the directory / looking for an item named "folder". Get the associated inode number.
    • If /folder is not a directory (or a symlink pointing to a directory), return ENOTDIR.
  4. Scan the directory /folder looking for an item named "directory". Get inode number, read inode, find data.
  5. Scan the directory /folder/directory looking for an item named "filename" and get the associated inode number.
  6. Read the inode and get the file's metadata, permission bits, data location, etc.

Note: /, /folder, and /folder/directory can be mount-points for completely separate filesystems. A common configuration is to have one partition for / and another for /home. (This also applies to non-Unix systems, such as Windows NT.) The process above should list lookups in the kernel's mount table.

share|improve this answer

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.