IO File_System - seporaitis/xv6-public GitHub Wiki
File System
What is the distinction between file name and file itself?
The same underlying file, called and inode, can have multiple names called links.
The link
system call creates another file system name referring to
the same inode as an existing file. This fragment creates a new file
named both a
and b
:
open("a", O_CREATE|O_WRONLY);
link("a", "b")
(xv6-book.pdf, p. 15)
What happens to link inode and file contents when file gets deleted?
File b
links to file a
, a program executes unlink("a")
. What
happened with the inode and contents of file b
?
Only the filename a
is removed from filesystem, the content and the
inode are still accessible via filename b
.
When file's inode and the disk space holding its content are freed?
Only when the file's link count is zero and no file descriptors refer to it.
How to create a temporary file?
(temporary: removed when the file is closed or process exits)
fd = open("/tmp/xyz", O_CREATE|O_RDWR);
unlink("/tmp/xyz");
What prominent shell command is coded into the shell. Why?
Most shell commands are implemented as user-level programs, such as
mkdir
, ln
, rm
, etc., except for cd
.
If cd
were run as a regular command, then the shell would fork a
child process, the child process would run cd
, and cd
would change
the child's working directory. The parent's (i.e. the shell's)
working directory would not change.