Go to the previous, next section.

The Filing System

The filing system provides a means of storing data on block devices. Files are organised in a tree-like structure through the use of directories. There is no limit on the number of files or directories that a directory can contain.

Concepts

This section explains some of the terms used by the filing system and a bit about how the filing system actually works.

A file is an object in a filing system, files don't intrinsically have names, instead they are differentiated by i-numbers, each i-number representing a separate file. Each file has a number of attributes associated with it, these include its type and permission bits, the time at which it was last modified and the data (a sequence of characters) stored in the file.

A directory is a file containing a list of name to i-number mappings, each mapping is called a directory entry and specifies one file stored in the directory. When a named file is referenced the current directory is scanned to find the i-number of the file. Each directory has two special entries, `.' pointing to the directory itself and `..' pointing at the directory's parent directory.

It is possible for a file's i-number to be stored in more than one directory entry, this allows a file to have more than one name, each directory entry is sometimes called a hard link to the file. Hard links have their drawbacks (hard to manage, can't cross device boundaries), so the filing system provides another type of link: symbolic links. A symbolic link binds much less tightly than a hard link, only the name of the file being linked to (i.e. a directory entry pointing to that file) is stored with the link, not the i-number.

File Names

Each file (or directory) can be located through the use of a file name. Each file name tells the system how to locate the file it specifies by listing the directories that have to be traversed from the current directory and then the name of the actual file separated by `/' characters.

Other meta characters include `:' to denote a device name (for example, the file name `hda1:foo' denotes the file `foo' on the device `hda1') or the root directory of the current device (for example `:foo', the file `foo' in the root of the current device). Finally, a `/' character at the start of a file name refers to the system's global root directory.

The following table contains several example file names together with a description of how the filing system uses them to locate the file or directory that they specify.

`foo'
`./foo'
The file named `foo' in the current directory.

`foo/bar'
The file named `bar' in the directory called `bar' in the current directory.

`../foo'
The file called `foo' in the parent of the current directory.

`/foo'
The file named `foo' in the system's root directory.

`hda:'
The root directory of the device called `hda' (the first IDE hard disk).

`hda:foo'
The file called `foo' in the root directory of the device called `hda'.

`:foo'
The file named `foo' in the root directory of the device which the current directory is stored on.

Devices

A device is a contiguous set of disk blocks that the filing system may store data on. Before the filing system is any use a device must be initialised and added to the list of devices that the filing system may access. Once this has been done the device can be accessed and files and directories may be created on it.

One of the most common entities to initialise as a filing system device is a hard disk partition; when the system is initialised the hard disk device driver scans the disks partition table and creates a logical partition for each partition it finds. For more details about hard disks see section The Hard Disk Device Driver.

When referring to a device in the filing system, its name should have a colon (`:') appended to it. For example to refer to the first primary partition of the first IDE disk, use the device name `hda1:'. The name of the device is still `hda1', the colon simply tells the filing system that a device is being referred to, not a file or a directory.

To create a new empty file system on a device the mkfs command should be used.

Command: mkfs type partition-name [reserved-blocks]

Creates a new filing system on the partition called partition-name. The parameter type defines which type of device the partition exists on, currently the only possible values are -hd to denote a hard disk partition and -fd to specify a floppy disk.

If reserved-blocks is defined, it specifies the number of blocks which will be left unused, directly after the boot block.

An initialised device may be added to the list of devices available for access by using the mount command.

Command: mount type partition-name

Adds the partition partition-name on the device of type type (currently, this may only be -hd or -fd) to the filing system.

To allow the system to boot from a hard disk partition, any partition which has its system type set to 48 will be automatically mounted when the system is initialised.

Command: umount device-name

Remove the device called device-name (no colon should be given) from the filing system.

Command: devinfo

Lists all the devices currently mounted in the filing system, and some information about each device.

Shell Commands

The filing system defines a number of shell commands, allowing the user to manipulate the contents of the individual devices.

Command: cp source-file dest-file

Copies the file called source-file to the file called dest-file.

Command: type files...

Prints each of the files named in the list files to the tty.

Command: ls [directory]

Lists the contents of the directory called directory, or if this parameter is undefined the current directory.

Command: cd directory

Changes the current directory of the shell to the directory called directory.

Command: ln [options] source dest

Makes a link from the directory entry called dest to the object called source. Currently the only option is the -s flag, if given the link is a symbolic link, otherwise a hard link is created.

Command: mkdir directory

Creates a new directory called directory. Note that the parent of directory must already exist.

Command: rm files...

Deletes each of the files named by files. This command can not be used to delete directories, use rmdir instead.

Command: rmdir directory

Removes the directory called directory. Note that only empty directories may be deleted (i.e. those whose only entries are `.' and `..'). An error is signalled if directory is not empty.

Command: mv source-file dest-file

Renames the file called source-file as dest-file. This command is not able to move files across devices.

Command: bufstats

Prints some statistics about the use of the buffer cache, basically how many cache hits have occurred against the number of actual buffer accesses.

Go to the previous, next section.