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

Clash 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
chrootuse a root directory for resolution of absolute pathnames?
Thanks.
filenames chroot
add a comment |Â
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
chrootuse a root directory for resolution of absolute pathnames?
Thanks.
filenames chroot
add a comment |Â
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
chrootuse a root directory for resolution of absolute pathnames?
Thanks.
filenames chroot
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
chrootuse a root directory for resolution of absolute pathnames?
Thanks.
filenames chroot
edited Apr 11 at 17:59
asked Apr 11 at 15:37
Tim
22.6k63224401
22.6k63224401
add a comment |Â
add a comment |Â
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:
creatoropen,linkorrename,unlinkorrmdir,chmodorchown,chdirorchroot,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 calleda1.
âÂÂâÂÂâÂÂâÂÂIf not found, return an error.
âÂÂâÂÂâÂÂâÂÂIf found, then search that directory for a subdirectory calledb.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂIf not found, return an error.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂIf found, then search that directory for directory entry calledc2.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ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 access
- 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 tochroot), 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 tochrootto/filesystem/tim/filesystem/john.
- if you access
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.
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
add a comment |Â
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.)
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 (usrin 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.1gzin 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 doeschrootuse root directory for resolution of absolute pathnames?
â Tim
Apr 11 at 17:59
chrootchanges the root directory of the process, i.e. the directory seen as/. When you change the root e.g. withchroot("/var/vmroots/vm1"), then what was/var/vmroots/vm1/usrcan 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 doeschrootachieve that? Doeschrootcreate a symlink named/linking to/var/vmroots/vm1? If yes, does the symlink override the original/?
â Tim
Apr 11 at 18:20
 |Â
show 1 more comment
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:
creatoropen,linkorrename,unlinkorrmdir,chmodorchown,chdirorchroot,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 calleda1.
âÂÂâÂÂâÂÂâÂÂIf not found, return an error.
âÂÂâÂÂâÂÂâÂÂIf found, then search that directory for a subdirectory calledb.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂIf not found, return an error.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂIf found, then search that directory for directory entry calledc2.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ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 access
- 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 tochroot), 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 tochrootto/filesystem/tim/filesystem/john.
- if you access
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.
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
add a comment |Â
up vote
2
down vote
accepted
All pathnames need resolution.ÃÂ
Obviously, processes pass pathnames to the kernel
as arguments to system calls like:
creatoropen,linkorrename,unlinkorrmdir,chmodorchown,chdirorchroot,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 calleda1.
âÂÂâÂÂâÂÂâÂÂIf not found, return an error.
âÂÂâÂÂâÂÂâÂÂIf found, then search that directory for a subdirectory calledb.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂIf not found, return an error.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂIf found, then search that directory for directory entry calledc2.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ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 access
- 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 tochroot), 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 tochrootto/filesystem/tim/filesystem/john.
- if you access
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.
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
add a comment |Â
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:
creatoropen,linkorrename,unlinkorrmdir,chmodorchown,chdirorchroot,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 calleda1.
âÂÂâÂÂâÂÂâÂÂIf not found, return an error.
âÂÂâÂÂâÂÂâÂÂIf found, then search that directory for a subdirectory calledb.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂIf not found, return an error.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂIf found, then search that directory for directory entry calledc2.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ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 access
- 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 tochroot), 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 tochrootto/filesystem/tim/filesystem/john.
- if you access
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.
All pathnames need resolution.ÃÂ
Obviously, processes pass pathnames to the kernel
as arguments to system calls like:
creatoropen,linkorrename,unlinkorrmdir,chmodorchown,chdirorchroot,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 calleda1.
âÂÂâÂÂâÂÂâÂÂIf not found, return an error.
âÂÂâÂÂâÂÂâÂÂIf found, then search that directory for a subdirectory calledb.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂIf not found, return an error.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂIf found, then search that directory for directory entry calledc2.
âÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂâÂÂ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 access
- 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 tochroot), 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 tochrootto/filesystem/tim/filesystem/john.
- if you access
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.
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
add a comment |Â
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
add a comment |Â
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.)
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 (usrin 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.1gzin 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 doeschrootuse root directory for resolution of absolute pathnames?
â Tim
Apr 11 at 17:59
chrootchanges the root directory of the process, i.e. the directory seen as/. When you change the root e.g. withchroot("/var/vmroots/vm1"), then what was/var/vmroots/vm1/usrcan 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 doeschrootachieve that? Doeschrootcreate a symlink named/linking to/var/vmroots/vm1? If yes, does the symlink override the original/?
â Tim
Apr 11 at 18:20
 |Â
show 1 more comment
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.)
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 (usrin 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.1gzin 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 doeschrootuse root directory for resolution of absolute pathnames?
â Tim
Apr 11 at 17:59
chrootchanges the root directory of the process, i.e. the directory seen as/. When you change the root e.g. withchroot("/var/vmroots/vm1"), then what was/var/vmroots/vm1/usrcan 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 doeschrootachieve that? Doeschrootcreate a symlink named/linking to/var/vmroots/vm1? If yes, does the symlink override the original/?
â Tim
Apr 11 at 18:20
 |Â
show 1 more comment
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.)
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.)
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 (usrin 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.1gzin 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 doeschrootuse root directory for resolution of absolute pathnames?
â Tim
Apr 11 at 17:59
chrootchanges the root directory of the process, i.e. the directory seen as/. When you change the root e.g. withchroot("/var/vmroots/vm1"), then what was/var/vmroots/vm1/usrcan 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 doeschrootachieve that? Doeschrootcreate a symlink named/linking to/var/vmroots/vm1? If yes, does the symlink override the original/?
â Tim
Apr 11 at 18:20
 |Â
show 1 more comment
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 (usrin 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.1gzin 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 doeschrootuse root directory for resolution of absolute pathnames?
â Tim
Apr 11 at 17:59
chrootchanges the root directory of the process, i.e. the directory seen as/. When you change the root e.g. withchroot("/var/vmroots/vm1"), then what was/var/vmroots/vm1/usrcan 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 doeschrootachieve that? Doeschrootcreate 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
 |Â
show 1 more comment
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password