1
$\begingroup$

I am recently studying The Operation System, I am confused about how symlink work even after watching some YouTube videos, hope there's someone can help me out with some questions. According to wiki, symlink is pointing to the name of the file but not the inode, if the computer wants to access /opt/be which is a symlink points to /usr/vscode/test.txt, should the procedure be

  1. Access root inode
  2. Access the index block pointed by root inode
  3. Access the inode of /opt
  4. Access the index block pointed by /opt inode
  5. Access the inode of /opt/be
  6. Access the index block pointed by /opt/be inode (the processor gets the filename i.e./usr/vscode/test.txt)
  7. Access root inode again
  8. Access index block pointed by root inode ...

I am wondering at step 7, should the process access the root inode again or should access the inode of the file directly?

$\endgroup$
1
  • $\begingroup$ how will it know the inode of the file directly? $\endgroup$
    – user253751
    Dec 1, 2022 at 14:36

1 Answer 1

1
$\begingroup$

A symbolic link is simply a special file which contains a path. There is nothing special or magic about this path. The path has to be looked up in exactly the same way as any other path.

For example, if the symbolic link contains the path foo/bar/../../../baz/./quux, then the OS has to look up that path.

should the process access the root inode again or should access the inode of the file directly?

How would it know the inode? How would it even know that the inode exists at all?

For example, the Gatling webserver uses symbolic links for a neat trick: in Gatling, you configure an HTTP Redirect by creating a symbolic link whose path is the URI you want to redirect to:

ln -s https://www.google.com/ search.html

There is absolutely no expectation that https://www.google.com/ is a resolvable path in your system – in fact, it is quite likely that it isn't. So, in this case, there is no inode for the linked path.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.