2

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.

migrated from cs.stackexchange.com Jun 7 '14 at 8:51

This question came from our site for students, researchers and practitioners of computer science.

  • 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 '14 at 23:12
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 to known system FS root due to chroot, jail, LXC and analogs) in case of an absolute path, or from current process directory, or from specified directory (in calls like openat), both in case of relative path. Specified path is split into sequence of path components, 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.
  2. "Open file" object is created, referencing this vnode, and attached to 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