How is a root directory used for resolution of absolute pathnames?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












APUE says




Each process also has a root directory that is used for resolution of absolute pathnames.
This root directory can be changed with the chroot function.




I thought only relative pathnames need resolution. So I was wondering



  • what does resolution of absolute pathnames mean?


  • how does chroot use a root directory for resolution of absolute pathnames?
    Thanks.







share|improve this question


























    up vote
    0
    down vote

    favorite












    APUE says




    Each process also has a root directory that is used for resolution of absolute pathnames.
    This root directory can be changed with the chroot function.




    I thought only relative pathnames need resolution. So I was wondering



    • what does resolution of absolute pathnames mean?


    • how does chroot use a root directory for resolution of absolute pathnames?
      Thanks.







    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      APUE says




      Each process also has a root directory that is used for resolution of absolute pathnames.
      This root directory can be changed with the chroot function.




      I thought only relative pathnames need resolution. So I was wondering



      • what does resolution of absolute pathnames mean?


      • how does chroot use a root directory for resolution of absolute pathnames?
        Thanks.







      share|improve this question














      APUE says




      Each process also has a root directory that is used for resolution of absolute pathnames.
      This root directory can be changed with the chroot function.




      I thought only relative pathnames need resolution. So I was wondering



      • what does resolution of absolute pathnames mean?


      • how does chroot use a root directory for resolution of absolute pathnames?
        Thanks.









      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 11 at 17:59

























      asked Apr 11 at 15:37









      Tim

      22.6k63224401




      22.6k63224401




















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote



          accepted










          All pathnames need resolution. 
          Obviously, processes pass pathnames to the kernel
          as arguments to system calls like:




          • creat or open,


          • link or rename,


          • unlink or rmdir,


          • chmod or chown,


          • chdir or chroot,


          • execve,

          etc. 
          Consider a pathname that looks something like




          …  a  /  b  /  c




          The way the kernel interprets this is:




          Starting (somewhere in the filesystem),

          Look for a directory called a1.

              If not found, return an error.

              If found, then search that directory for a subdirectory called b.

                  If not found, return an error.

                  If found, then search that directory for directory entry called c2.

                      If not found, return an error3.

                      If found, return that inode.




          Notice the obfuscation at the beginning of the pathname,
          and in the first line of the algorithm. 
          It’s simple: if the pathname begins with a slash
          (i.e., it’s an “absolute pathname”, e.g., /a/b/c),
          the search begins at the process’s root directory,
          and if the pathname begins with anything else
          (i.e., it’s a relative pathname, e.g., a/b/c),
          the search begins at the process’s current working directory.




          You may ask “How is this achieved?” 
          Well, of course,
          the kernel maintains a lot of information about each process, including



          • PID, PPID, and various process group identifiers,

          • real, effective, and saved UID and GID, and supplementary GID list,

          • open files,

          • signal dispositions,

          and more. 
          I left out many things because they’re irrelevant to this question. 
          I left out environment variables because they’re not maintained by the kernel;
          they’re maintained by user-space programs. 
          All the kernel does is support a mechanism
          for passing environment variables from one program to another through execve.



          Two things I left out of the above list for dramatic purposes are:



          • process’s root directory, and

          • current working directory

          These are pointers to inodes. 
          I expect everybody who has gotten this far
          understands how the process’s current working directory is set —
          the process calls chdir, passing it a pathname as an argument;
          the kernel interprets the pathname (resolves it to an inode)
          following the procedure described above,
          and, upon success, sets the current directory pointer to point to that inode.



          The process’s root directory is set the same way,
          except with the chroot system call.



          (Note that, in either case, if the pathname argument begins with /,
          the pathname resolution starts at the process’s root directory
          in effect when the system call is invoked. )



          Some examples:



          • If your current directory is /home/tim
            (and your process root directory is the filesystem root), then

            • if you access /etc/services, you will get /etc/services,

            • if you access .bashrc, you will get /home/tim/.bashrc.


          • If you do chroot /filesystem/tim
            (assuming that there is a directory by that name, and you have access to it,
            and you have the necessary privilege to chroot), then

            • if you access /etc/services, you will get /filesystem/tim/etc/services,

            • if you access /, you will get /filesystem/tim, so

            • if you chroot /, nothing will change;

            • if you chroot /filesystem/john,
              it will try to chroot to /filesystem/tim/filesystem/john.


          Since the root directory and the current directory
          are stored as pointers to inodes, the system doesn’t need to “locate” them.

          __________
          1 i.e., look for a directory entry that points to an inode whose mode indicates that it is a directory, i.e., (i_mode & IFMT) == IFDIR.


          2 for the last segment of the pathname,
          it doesn’t care what type of file it is;
          it could be a directory, a plain file, a named pipe,
          a symbolic link, a device, … whatever.
          3 if the last segment of the pathname is not found,
          but the system call is creat(file, mode)
          or (equivalently) open(file, O_CREAT, mode),
          or anything else than can create a directory entry,

          the operation will not fail.




          share|improve this answer




















          • I know that this question already has an accepted answer.  But some of the information content of that answer lies in the comments (rather than in the body of the answer), and, IMO, even the aggregate answer (including the comments) is unclear and borderline incomplete.  That’s why I’m adding this answer.
            – G-Man
            Apr 12 at 20:02

















          up vote
          2
          down vote













          When the kernel resolves e.g. /usr/share/man/man1/cat.1.gz to an inode, it will have to start from the root /, and work its way down to cat.1.gz. In the case of a relative pathname, it needs only look up the file in the current directory.



          Maybe you were thinking of how to get the absolute path to the current working directory? To determine the path, you will have to work your way from the current directory, through all the intermediate directories up to the root. (But note that the kernel does not do this when given a relative path to a file, e.g. as a parameter to the open syscall.)






          share|improve this answer






















          • Thanks. My questions is that given an absolute pathname, what does it mean by resolution of the absolute pathname, and how a root directory is used for the resolution?
            – Tim
            Apr 11 at 17:27











          • Resolving a pathname means locating a file or directory in a filesystem, based on its name. If the path is absolute (begins with a slash), it means the kernel will have to first locate the root directory, and in that directory locate the next component (usr in my example) by seaching the root directory. The process is repeated for all path components, and the result is the inode of the wanted file or directory (cat.1.1gz in the example). If the path is not absolute (i.e. it does not begin with a slash), then the search is similar, but instead starts from the current directory.
            – Johan Myréen
            Apr 11 at 17:56










          • How does chroot use root directory for resolution of absolute pathnames?
            – Tim
            Apr 11 at 17:59










          • chroot changes the root directory of the process, i.e. the directory seen as /. When you change the root e.g. with chroot("/var/vmroots/vm1"), then what was /var/vmroots/vm1/usr can now be found using the path /usr. What is outside the new root is now inaccessible to the chrooted process. Chroot affects path resolution only in that resolution now begins at the new root.
            – Johan Myréen
            Apr 11 at 18:17










          • How does chroot achieve that? Does chroot create a symlink named / linking to /var/vmroots/vm1? If yes, does the symlink override the original /?
            – Tim
            Apr 11 at 18:20











          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f437057%2fhow-is-a-root-directory-used-for-resolution-of-absolute-pathnames%23new-answer', 'question_page');

          );

          Post as a guest






























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          2
          down vote



          accepted










          All pathnames need resolution. 
          Obviously, processes pass pathnames to the kernel
          as arguments to system calls like:




          • creat or open,


          • link or rename,


          • unlink or rmdir,


          • chmod or chown,


          • chdir or chroot,


          • execve,

          etc. 
          Consider a pathname that looks something like




          …  a  /  b  /  c




          The way the kernel interprets this is:




          Starting (somewhere in the filesystem),

          Look for a directory called a1.

              If not found, return an error.

              If found, then search that directory for a subdirectory called b.

                  If not found, return an error.

                  If found, then search that directory for directory entry called c2.

                      If not found, return an error3.

                      If found, return that inode.




          Notice the obfuscation at the beginning of the pathname,
          and in the first line of the algorithm. 
          It’s simple: if the pathname begins with a slash
          (i.e., it’s an “absolute pathname”, e.g., /a/b/c),
          the search begins at the process’s root directory,
          and if the pathname begins with anything else
          (i.e., it’s a relative pathname, e.g., a/b/c),
          the search begins at the process’s current working directory.




          You may ask “How is this achieved?” 
          Well, of course,
          the kernel maintains a lot of information about each process, including



          • PID, PPID, and various process group identifiers,

          • real, effective, and saved UID and GID, and supplementary GID list,

          • open files,

          • signal dispositions,

          and more. 
          I left out many things because they’re irrelevant to this question. 
          I left out environment variables because they’re not maintained by the kernel;
          they’re maintained by user-space programs. 
          All the kernel does is support a mechanism
          for passing environment variables from one program to another through execve.



          Two things I left out of the above list for dramatic purposes are:



          • process’s root directory, and

          • current working directory

          These are pointers to inodes. 
          I expect everybody who has gotten this far
          understands how the process’s current working directory is set —
          the process calls chdir, passing it a pathname as an argument;
          the kernel interprets the pathname (resolves it to an inode)
          following the procedure described above,
          and, upon success, sets the current directory pointer to point to that inode.



          The process’s root directory is set the same way,
          except with the chroot system call.



          (Note that, in either case, if the pathname argument begins with /,
          the pathname resolution starts at the process’s root directory
          in effect when the system call is invoked. )



          Some examples:



          • If your current directory is /home/tim
            (and your process root directory is the filesystem root), then

            • if you access /etc/services, you will get /etc/services,

            • if you access .bashrc, you will get /home/tim/.bashrc.


          • If you do chroot /filesystem/tim
            (assuming that there is a directory by that name, and you have access to it,
            and you have the necessary privilege to chroot), then

            • if you access /etc/services, you will get /filesystem/tim/etc/services,

            • if you access /, you will get /filesystem/tim, so

            • if you chroot /, nothing will change;

            • if you chroot /filesystem/john,
              it will try to chroot to /filesystem/tim/filesystem/john.


          Since the root directory and the current directory
          are stored as pointers to inodes, the system doesn’t need to “locate” them.

          __________
          1 i.e., look for a directory entry that points to an inode whose mode indicates that it is a directory, i.e., (i_mode & IFMT) == IFDIR.


          2 for the last segment of the pathname,
          it doesn’t care what type of file it is;
          it could be a directory, a plain file, a named pipe,
          a symbolic link, a device, … whatever.
          3 if the last segment of the pathname is not found,
          but the system call is creat(file, mode)
          or (equivalently) open(file, O_CREAT, mode),
          or anything else than can create a directory entry,

          the operation will not fail.




          share|improve this answer




















          • I know that this question already has an accepted answer.  But some of the information content of that answer lies in the comments (rather than in the body of the answer), and, IMO, even the aggregate answer (including the comments) is unclear and borderline incomplete.  That’s why I’m adding this answer.
            – G-Man
            Apr 12 at 20:02














          up vote
          2
          down vote



          accepted










          All pathnames need resolution. 
          Obviously, processes pass pathnames to the kernel
          as arguments to system calls like:




          • creat or open,


          • link or rename,


          • unlink or rmdir,


          • chmod or chown,


          • chdir or chroot,


          • execve,

          etc. 
          Consider a pathname that looks something like




          …  a  /  b  /  c




          The way the kernel interprets this is:




          Starting (somewhere in the filesystem),

          Look for a directory called a1.

              If not found, return an error.

              If found, then search that directory for a subdirectory called b.

                  If not found, return an error.

                  If found, then search that directory for directory entry called c2.

                      If not found, return an error3.

                      If found, return that inode.




          Notice the obfuscation at the beginning of the pathname,
          and in the first line of the algorithm. 
          It’s simple: if the pathname begins with a slash
          (i.e., it’s an “absolute pathname”, e.g., /a/b/c),
          the search begins at the process’s root directory,
          and if the pathname begins with anything else
          (i.e., it’s a relative pathname, e.g., a/b/c),
          the search begins at the process’s current working directory.




          You may ask “How is this achieved?” 
          Well, of course,
          the kernel maintains a lot of information about each process, including



          • PID, PPID, and various process group identifiers,

          • real, effective, and saved UID and GID, and supplementary GID list,

          • open files,

          • signal dispositions,

          and more. 
          I left out many things because they’re irrelevant to this question. 
          I left out environment variables because they’re not maintained by the kernel;
          they’re maintained by user-space programs. 
          All the kernel does is support a mechanism
          for passing environment variables from one program to another through execve.



          Two things I left out of the above list for dramatic purposes are:



          • process’s root directory, and

          • current working directory

          These are pointers to inodes. 
          I expect everybody who has gotten this far
          understands how the process’s current working directory is set —
          the process calls chdir, passing it a pathname as an argument;
          the kernel interprets the pathname (resolves it to an inode)
          following the procedure described above,
          and, upon success, sets the current directory pointer to point to that inode.



          The process’s root directory is set the same way,
          except with the chroot system call.



          (Note that, in either case, if the pathname argument begins with /,
          the pathname resolution starts at the process’s root directory
          in effect when the system call is invoked. )



          Some examples:



          • If your current directory is /home/tim
            (and your process root directory is the filesystem root), then

            • if you access /etc/services, you will get /etc/services,

            • if you access .bashrc, you will get /home/tim/.bashrc.


          • If you do chroot /filesystem/tim
            (assuming that there is a directory by that name, and you have access to it,
            and you have the necessary privilege to chroot), then

            • if you access /etc/services, you will get /filesystem/tim/etc/services,

            • if you access /, you will get /filesystem/tim, so

            • if you chroot /, nothing will change;

            • if you chroot /filesystem/john,
              it will try to chroot to /filesystem/tim/filesystem/john.


          Since the root directory and the current directory
          are stored as pointers to inodes, the system doesn’t need to “locate” them.

          __________
          1 i.e., look for a directory entry that points to an inode whose mode indicates that it is a directory, i.e., (i_mode & IFMT) == IFDIR.


          2 for the last segment of the pathname,
          it doesn’t care what type of file it is;
          it could be a directory, a plain file, a named pipe,
          a symbolic link, a device, … whatever.
          3 if the last segment of the pathname is not found,
          but the system call is creat(file, mode)
          or (equivalently) open(file, O_CREAT, mode),
          or anything else than can create a directory entry,

          the operation will not fail.




          share|improve this answer




















          • I know that this question already has an accepted answer.  But some of the information content of that answer lies in the comments (rather than in the body of the answer), and, IMO, even the aggregate answer (including the comments) is unclear and borderline incomplete.  That’s why I’m adding this answer.
            – G-Man
            Apr 12 at 20:02












          up vote
          2
          down vote



          accepted







          up vote
          2
          down vote



          accepted






          All pathnames need resolution. 
          Obviously, processes pass pathnames to the kernel
          as arguments to system calls like:




          • creat or open,


          • link or rename,


          • unlink or rmdir,


          • chmod or chown,


          • chdir or chroot,


          • execve,

          etc. 
          Consider a pathname that looks something like




          …  a  /  b  /  c




          The way the kernel interprets this is:




          Starting (somewhere in the filesystem),

          Look for a directory called a1.

              If not found, return an error.

              If found, then search that directory for a subdirectory called b.

                  If not found, return an error.

                  If found, then search that directory for directory entry called c2.

                      If not found, return an error3.

                      If found, return that inode.




          Notice the obfuscation at the beginning of the pathname,
          and in the first line of the algorithm. 
          It’s simple: if the pathname begins with a slash
          (i.e., it’s an “absolute pathname”, e.g., /a/b/c),
          the search begins at the process’s root directory,
          and if the pathname begins with anything else
          (i.e., it’s a relative pathname, e.g., a/b/c),
          the search begins at the process’s current working directory.




          You may ask “How is this achieved?” 
          Well, of course,
          the kernel maintains a lot of information about each process, including



          • PID, PPID, and various process group identifiers,

          • real, effective, and saved UID and GID, and supplementary GID list,

          • open files,

          • signal dispositions,

          and more. 
          I left out many things because they’re irrelevant to this question. 
          I left out environment variables because they’re not maintained by the kernel;
          they’re maintained by user-space programs. 
          All the kernel does is support a mechanism
          for passing environment variables from one program to another through execve.



          Two things I left out of the above list for dramatic purposes are:



          • process’s root directory, and

          • current working directory

          These are pointers to inodes. 
          I expect everybody who has gotten this far
          understands how the process’s current working directory is set —
          the process calls chdir, passing it a pathname as an argument;
          the kernel interprets the pathname (resolves it to an inode)
          following the procedure described above,
          and, upon success, sets the current directory pointer to point to that inode.



          The process’s root directory is set the same way,
          except with the chroot system call.



          (Note that, in either case, if the pathname argument begins with /,
          the pathname resolution starts at the process’s root directory
          in effect when the system call is invoked. )



          Some examples:



          • If your current directory is /home/tim
            (and your process root directory is the filesystem root), then

            • if you access /etc/services, you will get /etc/services,

            • if you access .bashrc, you will get /home/tim/.bashrc.


          • If you do chroot /filesystem/tim
            (assuming that there is a directory by that name, and you have access to it,
            and you have the necessary privilege to chroot), then

            • if you access /etc/services, you will get /filesystem/tim/etc/services,

            • if you access /, you will get /filesystem/tim, so

            • if you chroot /, nothing will change;

            • if you chroot /filesystem/john,
              it will try to chroot to /filesystem/tim/filesystem/john.


          Since the root directory and the current directory
          are stored as pointers to inodes, the system doesn’t need to “locate” them.

          __________
          1 i.e., look for a directory entry that points to an inode whose mode indicates that it is a directory, i.e., (i_mode & IFMT) == IFDIR.


          2 for the last segment of the pathname,
          it doesn’t care what type of file it is;
          it could be a directory, a plain file, a named pipe,
          a symbolic link, a device, … whatever.
          3 if the last segment of the pathname is not found,
          but the system call is creat(file, mode)
          or (equivalently) open(file, O_CREAT, mode),
          or anything else than can create a directory entry,

          the operation will not fail.




          share|improve this answer












          All pathnames need resolution. 
          Obviously, processes pass pathnames to the kernel
          as arguments to system calls like:




          • creat or open,


          • link or rename,


          • unlink or rmdir,


          • chmod or chown,


          • chdir or chroot,


          • execve,

          etc. 
          Consider a pathname that looks something like




          …  a  /  b  /  c




          The way the kernel interprets this is:




          Starting (somewhere in the filesystem),

          Look for a directory called a1.

              If not found, return an error.

              If found, then search that directory for a subdirectory called b.

                  If not found, return an error.

                  If found, then search that directory for directory entry called c2.

                      If not found, return an error3.

                      If found, return that inode.




          Notice the obfuscation at the beginning of the pathname,
          and in the first line of the algorithm. 
          It’s simple: if the pathname begins with a slash
          (i.e., it’s an “absolute pathname”, e.g., /a/b/c),
          the search begins at the process’s root directory,
          and if the pathname begins with anything else
          (i.e., it’s a relative pathname, e.g., a/b/c),
          the search begins at the process’s current working directory.




          You may ask “How is this achieved?” 
          Well, of course,
          the kernel maintains a lot of information about each process, including



          • PID, PPID, and various process group identifiers,

          • real, effective, and saved UID and GID, and supplementary GID list,

          • open files,

          • signal dispositions,

          and more. 
          I left out many things because they’re irrelevant to this question. 
          I left out environment variables because they’re not maintained by the kernel;
          they’re maintained by user-space programs. 
          All the kernel does is support a mechanism
          for passing environment variables from one program to another through execve.



          Two things I left out of the above list for dramatic purposes are:



          • process’s root directory, and

          • current working directory

          These are pointers to inodes. 
          I expect everybody who has gotten this far
          understands how the process’s current working directory is set —
          the process calls chdir, passing it a pathname as an argument;
          the kernel interprets the pathname (resolves it to an inode)
          following the procedure described above,
          and, upon success, sets the current directory pointer to point to that inode.



          The process’s root directory is set the same way,
          except with the chroot system call.



          (Note that, in either case, if the pathname argument begins with /,
          the pathname resolution starts at the process’s root directory
          in effect when the system call is invoked. )



          Some examples:



          • If your current directory is /home/tim
            (and your process root directory is the filesystem root), then

            • if you access /etc/services, you will get /etc/services,

            • if you access .bashrc, you will get /home/tim/.bashrc.


          • If you do chroot /filesystem/tim
            (assuming that there is a directory by that name, and you have access to it,
            and you have the necessary privilege to chroot), then

            • if you access /etc/services, you will get /filesystem/tim/etc/services,

            • if you access /, you will get /filesystem/tim, so

            • if you chroot /, nothing will change;

            • if you chroot /filesystem/john,
              it will try to chroot to /filesystem/tim/filesystem/john.


          Since the root directory and the current directory
          are stored as pointers to inodes, the system doesn’t need to “locate” them.

          __________
          1 i.e., look for a directory entry that points to an inode whose mode indicates that it is a directory, i.e., (i_mode & IFMT) == IFDIR.


          2 for the last segment of the pathname,
          it doesn’t care what type of file it is;
          it could be a directory, a plain file, a named pipe,
          a symbolic link, a device, … whatever.
          3 if the last segment of the pathname is not found,
          but the system call is creat(file, mode)
          or (equivalently) open(file, O_CREAT, mode),
          or anything else than can create a directory entry,

          the operation will not fail.





          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Apr 12 at 19:59









          G-Man

          11.5k82656




          11.5k82656











          • I know that this question already has an accepted answer.  But some of the information content of that answer lies in the comments (rather than in the body of the answer), and, IMO, even the aggregate answer (including the comments) is unclear and borderline incomplete.  That’s why I’m adding this answer.
            – G-Man
            Apr 12 at 20:02
















          • I know that this question already has an accepted answer.  But some of the information content of that answer lies in the comments (rather than in the body of the answer), and, IMO, even the aggregate answer (including the comments) is unclear and borderline incomplete.  That’s why I’m adding this answer.
            – G-Man
            Apr 12 at 20:02















          I know that this question already has an accepted answer.  But some of the information content of that answer lies in the comments (rather than in the body of the answer), and, IMO, even the aggregate answer (including the comments) is unclear and borderline incomplete.  That’s why I’m adding this answer.
          – G-Man
          Apr 12 at 20:02




          I know that this question already has an accepted answer.  But some of the information content of that answer lies in the comments (rather than in the body of the answer), and, IMO, even the aggregate answer (including the comments) is unclear and borderline incomplete.  That’s why I’m adding this answer.
          – G-Man
          Apr 12 at 20:02












          up vote
          2
          down vote













          When the kernel resolves e.g. /usr/share/man/man1/cat.1.gz to an inode, it will have to start from the root /, and work its way down to cat.1.gz. In the case of a relative pathname, it needs only look up the file in the current directory.



          Maybe you were thinking of how to get the absolute path to the current working directory? To determine the path, you will have to work your way from the current directory, through all the intermediate directories up to the root. (But note that the kernel does not do this when given a relative path to a file, e.g. as a parameter to the open syscall.)






          share|improve this answer






















          • Thanks. My questions is that given an absolute pathname, what does it mean by resolution of the absolute pathname, and how a root directory is used for the resolution?
            – Tim
            Apr 11 at 17:27











          • Resolving a pathname means locating a file or directory in a filesystem, based on its name. If the path is absolute (begins with a slash), it means the kernel will have to first locate the root directory, and in that directory locate the next component (usr in my example) by seaching the root directory. The process is repeated for all path components, and the result is the inode of the wanted file or directory (cat.1.1gz in the example). If the path is not absolute (i.e. it does not begin with a slash), then the search is similar, but instead starts from the current directory.
            – Johan Myréen
            Apr 11 at 17:56










          • How does chroot use root directory for resolution of absolute pathnames?
            – Tim
            Apr 11 at 17:59










          • chroot changes the root directory of the process, i.e. the directory seen as /. When you change the root e.g. with chroot("/var/vmroots/vm1"), then what was /var/vmroots/vm1/usr can now be found using the path /usr. What is outside the new root is now inaccessible to the chrooted process. Chroot affects path resolution only in that resolution now begins at the new root.
            – Johan Myréen
            Apr 11 at 18:17










          • How does chroot achieve that? Does chroot create a symlink named / linking to /var/vmroots/vm1? If yes, does the symlink override the original /?
            – Tim
            Apr 11 at 18:20















          up vote
          2
          down vote













          When the kernel resolves e.g. /usr/share/man/man1/cat.1.gz to an inode, it will have to start from the root /, and work its way down to cat.1.gz. In the case of a relative pathname, it needs only look up the file in the current directory.



          Maybe you were thinking of how to get the absolute path to the current working directory? To determine the path, you will have to work your way from the current directory, through all the intermediate directories up to the root. (But note that the kernel does not do this when given a relative path to a file, e.g. as a parameter to the open syscall.)






          share|improve this answer






















          • Thanks. My questions is that given an absolute pathname, what does it mean by resolution of the absolute pathname, and how a root directory is used for the resolution?
            – Tim
            Apr 11 at 17:27











          • Resolving a pathname means locating a file or directory in a filesystem, based on its name. If the path is absolute (begins with a slash), it means the kernel will have to first locate the root directory, and in that directory locate the next component (usr in my example) by seaching the root directory. The process is repeated for all path components, and the result is the inode of the wanted file or directory (cat.1.1gz in the example). If the path is not absolute (i.e. it does not begin with a slash), then the search is similar, but instead starts from the current directory.
            – Johan Myréen
            Apr 11 at 17:56










          • How does chroot use root directory for resolution of absolute pathnames?
            – Tim
            Apr 11 at 17:59










          • chroot changes the root directory of the process, i.e. the directory seen as /. When you change the root e.g. with chroot("/var/vmroots/vm1"), then what was /var/vmroots/vm1/usr can now be found using the path /usr. What is outside the new root is now inaccessible to the chrooted process. Chroot affects path resolution only in that resolution now begins at the new root.
            – Johan Myréen
            Apr 11 at 18:17










          • How does chroot achieve that? Does chroot create a symlink named / linking to /var/vmroots/vm1? If yes, does the symlink override the original /?
            – Tim
            Apr 11 at 18:20













          up vote
          2
          down vote










          up vote
          2
          down vote









          When the kernel resolves e.g. /usr/share/man/man1/cat.1.gz to an inode, it will have to start from the root /, and work its way down to cat.1.gz. In the case of a relative pathname, it needs only look up the file in the current directory.



          Maybe you were thinking of how to get the absolute path to the current working directory? To determine the path, you will have to work your way from the current directory, through all the intermediate directories up to the root. (But note that the kernel does not do this when given a relative path to a file, e.g. as a parameter to the open syscall.)






          share|improve this answer














          When the kernel resolves e.g. /usr/share/man/man1/cat.1.gz to an inode, it will have to start from the root /, and work its way down to cat.1.gz. In the case of a relative pathname, it needs only look up the file in the current directory.



          Maybe you were thinking of how to get the absolute path to the current working directory? To determine the path, you will have to work your way from the current directory, through all the intermediate directories up to the root. (But note that the kernel does not do this when given a relative path to a file, e.g. as a parameter to the open syscall.)







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Apr 11 at 16:41

























          answered Apr 11 at 16:33









          Johan Myréen

          6,76711221




          6,76711221











          • Thanks. My questions is that given an absolute pathname, what does it mean by resolution of the absolute pathname, and how a root directory is used for the resolution?
            – Tim
            Apr 11 at 17:27











          • Resolving a pathname means locating a file or directory in a filesystem, based on its name. If the path is absolute (begins with a slash), it means the kernel will have to first locate the root directory, and in that directory locate the next component (usr in my example) by seaching the root directory. The process is repeated for all path components, and the result is the inode of the wanted file or directory (cat.1.1gz in the example). If the path is not absolute (i.e. it does not begin with a slash), then the search is similar, but instead starts from the current directory.
            – Johan Myréen
            Apr 11 at 17:56










          • How does chroot use root directory for resolution of absolute pathnames?
            – Tim
            Apr 11 at 17:59










          • chroot changes the root directory of the process, i.e. the directory seen as /. When you change the root e.g. with chroot("/var/vmroots/vm1"), then what was /var/vmroots/vm1/usr can now be found using the path /usr. What is outside the new root is now inaccessible to the chrooted process. Chroot affects path resolution only in that resolution now begins at the new root.
            – Johan Myréen
            Apr 11 at 18:17










          • How does chroot achieve that? Does chroot create a symlink named / linking to /var/vmroots/vm1? If yes, does the symlink override the original /?
            – Tim
            Apr 11 at 18:20

















          • Thanks. My questions is that given an absolute pathname, what does it mean by resolution of the absolute pathname, and how a root directory is used for the resolution?
            – Tim
            Apr 11 at 17:27











          • Resolving a pathname means locating a file or directory in a filesystem, based on its name. If the path is absolute (begins with a slash), it means the kernel will have to first locate the root directory, and in that directory locate the next component (usr in my example) by seaching the root directory. The process is repeated for all path components, and the result is the inode of the wanted file or directory (cat.1.1gz in the example). If the path is not absolute (i.e. it does not begin with a slash), then the search is similar, but instead starts from the current directory.
            – Johan Myréen
            Apr 11 at 17:56










          • How does chroot use root directory for resolution of absolute pathnames?
            – Tim
            Apr 11 at 17:59










          • chroot changes the root directory of the process, i.e. the directory seen as /. When you change the root e.g. with chroot("/var/vmroots/vm1"), then what was /var/vmroots/vm1/usr can now be found using the path /usr. What is outside the new root is now inaccessible to the chrooted process. Chroot affects path resolution only in that resolution now begins at the new root.
            – Johan Myréen
            Apr 11 at 18:17










          • How does chroot achieve that? Does chroot create a symlink named / linking to /var/vmroots/vm1? If yes, does the symlink override the original /?
            – Tim
            Apr 11 at 18:20
















          Thanks. My questions is that given an absolute pathname, what does it mean by resolution of the absolute pathname, and how a root directory is used for the resolution?
          – Tim
          Apr 11 at 17:27





          Thanks. My questions is that given an absolute pathname, what does it mean by resolution of the absolute pathname, and how a root directory is used for the resolution?
          – Tim
          Apr 11 at 17:27













          Resolving a pathname means locating a file or directory in a filesystem, based on its name. If the path is absolute (begins with a slash), it means the kernel will have to first locate the root directory, and in that directory locate the next component (usr in my example) by seaching the root directory. The process is repeated for all path components, and the result is the inode of the wanted file or directory (cat.1.1gz in the example). If the path is not absolute (i.e. it does not begin with a slash), then the search is similar, but instead starts from the current directory.
          – Johan Myréen
          Apr 11 at 17:56




          Resolving a pathname means locating a file or directory in a filesystem, based on its name. If the path is absolute (begins with a slash), it means the kernel will have to first locate the root directory, and in that directory locate the next component (usr in my example) by seaching the root directory. The process is repeated for all path components, and the result is the inode of the wanted file or directory (cat.1.1gz in the example). If the path is not absolute (i.e. it does not begin with a slash), then the search is similar, but instead starts from the current directory.
          – Johan Myréen
          Apr 11 at 17:56












          How does chroot use root directory for resolution of absolute pathnames?
          – Tim
          Apr 11 at 17:59




          How does chroot use root directory for resolution of absolute pathnames?
          – Tim
          Apr 11 at 17:59












          chroot changes the root directory of the process, i.e. the directory seen as /. When you change the root e.g. with chroot("/var/vmroots/vm1"), then what was /var/vmroots/vm1/usr can now be found using the path /usr. What is outside the new root is now inaccessible to the chrooted process. Chroot affects path resolution only in that resolution now begins at the new root.
          – Johan Myréen
          Apr 11 at 18:17




          chroot changes the root directory of the process, i.e. the directory seen as /. When you change the root e.g. with chroot("/var/vmroots/vm1"), then what was /var/vmroots/vm1/usr can now be found using the path /usr. What is outside the new root is now inaccessible to the chrooted process. Chroot affects path resolution only in that resolution now begins at the new root.
          – Johan Myréen
          Apr 11 at 18:17












          How does chroot achieve that? Does chroot create a symlink named / linking to /var/vmroots/vm1? If yes, does the symlink override the original /?
          – Tim
          Apr 11 at 18:20





          How does chroot achieve that? Does chroot create a symlink named / linking to /var/vmroots/vm1? If yes, does the symlink override the original /?
          – Tim
          Apr 11 at 18:20













           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f437057%2fhow-is-a-root-directory-used-for-resolution-of-absolute-pathnames%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          Peggy Mitchell

          Palaiologos

          The Forum (Inglewood, California)