 |
One of the more important tasks the kernel is responsible for is the management
of the UNIX file system. It controls all accesses to it, including creation,
reading, and writing of files; managing directory information about a file;
and the actual placement of data on the disk. As a user, when you make
a directory, remove a file, etc., the commands you use (mkdir, rm) make
system calls to ask the kernel to do the work.
The UNIX file system is a hierarchical structured, file based system.
The hierarchy is often represented as a tree, with a root directory (or
trunk) which is referenced by '/', sub-directories (branches), and files
(leaves). Each file system has exactly one root directory containing sub-directories
and files, each sub-directory can branch off to many directories and/or
files with other sub-directories and files with each of those sub-directories.
In the UNIX file system, everything is a file, including directories,
terminals(TTY's), and even disk drives. Look in the /dev directory. This
is the UNIX device directory where TTYs and other files reside. Files in
/dev named tty"something" are where the system writes standard
output and
reads standard input. TTY stands for TeleTYpe, which in the days before
networking were dumb terminals directly connected to the machine.
For example, a directory is a special type of file. It contains a list
of two things about each of the files in the directory, the file's name,
and a unique number called an inode number (or inumber) which is a reference
to the inode. Another interesting example is a neat trick to copy the contents
of one disk to another. Assuming two floppy drives are represented by /dev/fd0
and /dev/fd1, the command cat /dev/fd0 > /dev/fd1 would
make the
second disk a clone of the first. This uses redirection (which is discussed
later) to copy the file /dev/fd0, which is actually a disk, to /dev/fd1,
which is also a disk.
File Name: The file name is simply a string of characters that
identifies a file
for a user, and has no restrictions on the name, other than it must be
unique within a given directory, and be no longer than the system's maximum
file name length (usually 256 characters). This means that you can use
any combination of alphanumeric characters, punctuation, control characters,
or even an '*' in a filename. However, it is usually not a good idea to
use anything other than alphanumeric characters and periods, since it becomes
difficult to reference a file that has
characters in its name.
Inode Number: The inode number is a special number that
identifies an inode, which
is a part of the file system where all the information about a file is
stored. This information includes things like the owner of the file, the
time the file was last modified, permissions associated with a file, the
type of file (regular file, directory, etc.), and where the file resides
on the physical disk.
One piece of information that is not stored in the inode is the filename.
That is stored as part of the directory information. This allows the UNIX
file system to support links, which is a single file with multiple names
and/or in multiple directories. Links are created with the ln(1) command,
which will do both hard links and symbolic links. A symbolic link is a
special file that contains the name of the file that it points to. When
a symbolic link is referenced, the system simply opens the file name that
the link points to. A hard link, however is indistinguishable from the
original file, it exists in the same manner (and is exactly the same) as
the original file. It is not two files, it is one inode with two names.
Any changes to permissions, time, date, owner, and data contained in the
file will appear in both places. As a user, you will find that symbolic
links come in handy when you want to use a file without actually copying
it into a directory. For example, if someone has an executable in his or
her public directory, you can make a link to it in your home directory
instead of copying the executable (which might be quite large) and save
yourself some disk space. Hard links are not so common, and are usually
used only for administration. They do not work across devices, so since
you, as a user, cannot control how your disk space is physically configured,
it is a good idea to stay away from using them.
At the beginning of each directory file, are two entries: '.'
and '..'
. The first entry is for the directory itself, the second is for the parent
of the directory (with the exception of the root directory, where '..'
has the same meaning as '.' ). This is so the system has a point of reference.
When you cd into a directory, UNIX only knows that you are in a directory,
not which one, or where, it needs '.' to know where you are, and '..' to
resolve it's relative position in the file system.
|