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:
- Split the given path into components separated by
/
- The location of
/ is already known by the kernel.
- 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.
- Scan the directory
/folder looking for an item named "directory". Get inode number, read inode, find data.
- Scan the directory
/folder/directory looking for an item named "filename" and get the associated inode number.
- 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.