CS 279 - Week 4 Lecture 2 - 9-13-12
Subsidiary file systems
-----------------------
* reference: section 2.7.4
* UNIX permits parts of the directory hierarchy to reside
on separate storage devices, in separate disk
partitions, etc.
* these parts of "the UNIX file system" are called
"file systems"
* why? to permit more storage, to allow for
handling temporary storage devices, to permit
network file systems, etc.;
* UNIX associates such a file system with a MOUNT POINT
* mount point: a directory in a [primary] file system
that corresponds to the root directory of some other
[secondary] file system
* the mount command is given the pathname to the
mount point
[in the primary file system],
and the location of the secondary file system
to be mounted
at that mount point;
result: the root of the secondary file system
now corresponds to the mount point in the primary
file system;
* and once a file system has been mounted,
you can refer to any file or directory within it
by using
a path the passes through the mount point;
* NOW -- once it is mounted, do you really need to know
that it is a mounted secondary file system, as opposed
to just another directory subtree starting from that
directory?
* turns out that, sometimes you do;
* there are some restrictions on some kinds of
connections across
file system boundaries (we'll discuss one example of
this related
to links below)
* and, not unexpectedly, when a file system is unmounted,
you lose access to its files until it is remounted...
Links
------
* pp. 41-42 of course text
* hard links and symbolic/soft links
* according to text, if someone JUST says "link",
a hard link is assumed;
* hard link:
* A [hard] link to a file is a directory entry for that
file, consisting of a filename that names the file
within the directory and an i-node number
* i-node number: a unique identifier for a file
within a file system
* ls with the -i option shows the i-node numbers for
the files:
ls -i
ls -li
* ln command (without the -s option) creates a hard
link to an existing file
ln existing-file-name hard-link-name
(although, once made, you can mv or delete that
existing file without affecting the new hard link
-- interesting and true!)
* a file is not deleted until ALL hard links to it
are removed;
(beware -- emacs creates a NEW copy of a file with
a new i-node number! BUT vi does not...)
* can only (hard) link to a file in the same file
system;
* symbolic link (soft link)
* specifies a PATHNAME
* If that pathname designates an actual file, then the
symbolic link refers to that file.
* If it designates another symbolic link, then
that link is followed in turn.
* A symbolic link can specify a pathname for
which NO file exists; in that case a reference
to the link is treated like a reference to any
other nonexistent file.
* a symbolic link can link to a directory or to a special
file as well as to a regular file;
...it is also allowed to files in different file systems
* use ln command with the -s option to create a symbolic link
ln -s existing-file-name soft-link-name
* (compare a hard link to a symbolic link using
ls -li
...interesting differences!)
* do you see the difference between hard and symbolic links?
* for a new hard link, what is stored is the link
filename and an
inode number; it just so happens that another filename
also
happens to include the same inode number.
* for a new soft/symbolic link, what is stored is the link
filename and the pathname to the linked-to file;
it is clear,
then, WHICH is the original/target;
How files are stored
---------------------
* reference: Section 2.7.7
* p. 42:
* "The file system stores the essential information about
a file in
an i-node (information node):
* where the file's actual contents are stored
* how long the file is
* how many LINKS there are to it [<-- hard links, then,
NOT symbolic]
* when it was created
and so on"
* an i-node is identified uniquely [within a file
system] by an
i-number/i-node number
* The actual data in a file is stored in a sequence of BLOCKS.
* typical for a modern system: 4096 bytes
* if a file is longer than 1 block?
file system stores its contents in scattered data
blocks,
and uses a smaller set of blocks to keep track of
where the
data blocks are;
* ^ the blocks in this smaller set contain pointers to the
data blocks;
they are called INDIRECT blocks because they provide
access
to the data indirectly
* For VERY LARGE files, there may be a SECOND level of
indirect blocks that point to the first-level blocks
or even, in
some cases, a THIRD level --
The UNIX utilities that show the number of blocks in
a file
count INDIRECT blocks, as WELL as the blocks containing
the ACTUAL data of the file...