What's the internal process of opening a file?

To open a file, the system converts the pathname to inode and from the inode search the corresponding driver disk portion to look for the content of the file? Is that it? I only have a vague sense of the process of opening a file, but I want more detail.

  • 3
    What research have you done? Have you read a standard OS textbook? It'll typically have a chapter on filesystems. Have you read Wikipedia, e.g., en.wikipedia.org/wiki/Filesystem? We expect you to do a significant amount of resaerch before asking, to help you frame a more precise question and to articulate what more clearly you're stuck on.
    – D.W.
    Jun 6, 2014 at 23:12

1 Answer 1


Generally you should read a book like this one to get answers for most such details inside kernel. But, in general, yes, the process is that:

  1. Filesystem is traversed using the specified path, from the process' root (it can differ from a known system FS root due to chroot, jail, LXC and analogs) in case of an absolute path, or from the current process directory, or from a specified directory (in calls like openat), both in case of relative path. The specified path is split into sequence of path components (separated by '/'), which are processed in sequence. Directory contents and mountpoint crossings are analyzed during this process (named "path lookup", "namei lookup"), and each path component result in temporary reference to a vnode (sfile in old Unixes, inode in Linux) object. As the result, if this succeeds, final file's vnode is found (created, if needed) and held up (usually, reference counting is used to keep it alive in kernel RAM).
  2. An "open file" object is created, referencing this vnode, and attached to the process' file descriptor, allocated for this request.

Details of directory search for this are very specific for particular VFS. It can be of any kind including memory-only ones (tmpfs), disk-based ones (ext4, etc.), but the common concept of hierarchy of directories is kept in effect.

Your Answer

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