================ Start Lecture #18
================
Lab 2 due date extended until 10 April and may be done on acf5
as well as omicron
Inodes
- Used by unix
- Directory entry points to inode (index-node)
- Inode points to first few data blocks
- Inode points to an indirect block, which points to disk blocks
- Inode points to a double indirect, which points an indirect ...
- For some implementations there are triple indirect as well
- The inode is in memory for open files so many references just take
one I/O
- Big files take two (indirect + data)
- Huge files take three
4.3.2; Implementing Directories
Maps file (or subdirectory) names to the files (or subdirectories)
themselves.
Trivial Filesystem (CP/M)
- Only one directory in the system
- Directory entry contains pointers to disk blocks.
- If need more blocks, get another directory entry.
MS-DOS (FAT)
- Subdirectories supported
- Directory entry contains metatdata such as date and size
as well as pointer to first block.
Unix
- Entry contains name and pointer to inode.
- Metadata is in inode
- Early unix had limit of 14 character names.
- Name field now is varying length.
- To go down a level in directory takes two steps: get inode, get
file (or subdirectory).
- Do on board steps for /allan/gottlieb/courses/os/class-notes.html
Homework: 11
4.3.3: Shared files (links)
- Sharing is Tanenbaum's terminology.
- More descriptive would ``multinamed files''.
- If a file exists, one can create another name for it (quite
possibly in another directory)
- Often called creating a (or another) link to the file.
- Unix has two flavor, hard links and symbolic
links or symlinks.
- Dos/windows has symlinks, but I don't believe it has hard links.
Start with an empty filesystem (i.e. just root) and then execute
cd /
mkdir /A; mkdir /B
touch /A/X; touch /B/Y
We have the situation shown on the right.
Note that names are on edges not nodes.
When there are no multinamed files, it doesn't much matter.
Now execute
ln /B/Y /A/New
This gives the new diagram to the right.
At this point there are two equally valid name for the right hand
yellow file, B/Y and A/New. The fact that B/Y was created first is
NOT detectable.
- Both point to the same inode
- Only one owner (the one who created the file initially)
- One date, one set of permissions, one ...
Assume Bob created /B and /B/Y and Alice created /A, /A/X, and /A/New
Later Bob tires of /B/Y and removes it by executing
rm /B/Y
The file /A/New is still fine (see third diagram on the right).
But it is owned by Bob, who can't find it! If the system enforces
quotas bob will likely be charged (as the owner) but he can neither
find nor delete the file (since bob cannot unlink, i.e. remove, files
from /A)
Since hard links are only permitted to files (not directories) the
resulting filesystem is a dag (directed acyclic graph). That is there
are no directed cycles. We will now proceed to give away this useful
property by studying symlinks, which can point to directories.
Symlinks
- Asymmetric multinamed files.
- When a symlink is created another file is created, one
that points to the original file.
Again start with an empty filesystem and this time execute
cd /
mkdir /A; mkdir /B
touch /A/X; touch /B/Y
ln -s /B/Y /A/New
We now have an additional file /A/New, which is a symlink to /B/Y.
- The file /A/New has the name /B/Y as its data
(not metadata).
- The system notices that A/New is a diamond (symlink) so reading
/A/New will return the contents of /B/Y (assuming the reader has read
permission for /B/Y).
- If /B/Y is removed /A/New becomes invalid.
- If a new /B/Y is created, A/New is once again valid.
- Removing /A/New has no effect of /B/Y.
- If a user has write permission for /B/Y, then writing /A/New is possible
and writes /B/Y.
The bottom line is that, with a hard link, a new name is created
that has equal status to the original name. This can cause some
surprised (e.g., you create a link but Id own it).
With a symbolic link a new file is created (owned by the
creator naturally) that points to the original file.
Question: Consider the hard link setup above. If Bob removes /B/Y
and then creates another /B/Y, what happens to /A/X?
Answer: Nothing. /A/X is still a file with the same contents as the
original /B/Y.
Question: What about with a symlink?
Answer: /A/X becomes invalid and then valid again, this time pointing
to the new /B/Y.
(It can't point to the old /B/Y as that is completely gone.)