Handout 18
Unix File Systems*
Preliminaries
File Attributes
-rw-r--r--+ 1 pheattch other 72 Feb 3 14:38 x.c
00000000011111111112222222222333333333344444444445
12345678901234567890123456789012345678901234567890
Position 1 - can represent:
d the entry is a directory;
l the entry is a symbolic link - a file that contains the path information needed to access a file. Note
that there is nothing to guarantee that this information is valid.
b the entry is a block special file - a file that is accessed a set number of bytes ( block ) at a time.
The video screen on you pc is usually accessed as a block special file device.
c the entry is a character special file - a file that is to accessed one character at a time. The keyboard
of your terminal would be accessed as a character file.
p the entry is a fifo (or "named pipe") special file;
- the entry is an ordinary file;
| the entry is a FIFO - when connecting the output of a command to the input of another, the system may
need to buffer the data.
Position 2-10 - Interpreted as three sets of three bits each. The first set refers to the owner's permissions;
the next to permissions of others in the user-group of the file; and the last to all others.
Position 11 - The plus sign indicates that there is an ACL (access control list, see below) associated
with the file.
Position 13 - indicates the number of links to the file. Is incremented by the ln command as well as
if it is a directory. (the original file is considered a link)
Position 15-22 - File owner.
Position 24-28 - File group.
Position 30-31 - File contains 72 bytes.
Position 33-43 - The last time that file's contents were modified owner.
Position 45-47 - File name.
linking
hard: ln existing_name new_name
soft: ln -s existing_name new_name
Hard links
- With a hard link, two filenames (i.e., two directory entries) point to the same inode and the same set of data
blocks.
- All UNIX versions support hard links.
- They have two important limitations: a hard link can't cross a filesystem (i.e., both filenames must be in
the same filesystem), and you can't create a hard link to a directory (i.e., a directory can only have one name).
- They have two important advantages: the link and the original file are absolutely and always identical, and
the extra link takes no disk space (except an occasional extra disk block in the directory file).
Symbolic links (also called soft links or symlinks):
- With a symbolic link, there really are two different files. One file contains the actual data; the other file
just contains the name of the first file and serves as a "pointer."
- The system knows that whenever it opens a link, it should read the contents of the link, and then access the
file that really holds the data you want.
- Symbolic links are infinitely more flexible than hard links.
They can cross filesystems, or even computer systems (if you are using NFS or RFS).
You can make a symbolic link to a directory.
A symbolic link has its own inode and takes a small amount of disk space to store.
What are Access Control Lists?
Unix allows you to grant or deny access to users by putting users on a directory's access control list. Every directory
has its own ACL that defines who can access the directory and its files. Groups are lists of users; some groups
are created by the system, but users can also create their own groups.
If we issue the command:
setfacl -s user:bozo:rw-,user::rwx,group::---,mask:rw-,other:--- x.c
setfacl modifies the Access Control List (ACL) for a file or files. The -s option will set the
ACL to the entries specified on the command line. The command above:
- gives the user bozo rw permission
- gives the owner rwx permission
- gives the owning group no permissions
- gives all others no permissions
- The mask entry indicates the file group mask permissions. These are the maximum permissions allowed to any
user entries except the file owner, and to any group entries, including the owning group. These permissions restrict
the permissions specified in other entries.
Unix Filesystem Overview
The structure of a simple Unix file system can generally be seperated into four parts, the boot block, the super
block, the inode list and the data blocks.
The boot block is located at the beginning of the file system and can be accessed with the minimal code
incorporated in the computer's rom bios. The boot block of the bootable partition contains the code needed to further
initialize the operating system.
The super block describes the state of a file system - how large it is, how many files in can store, What
parts of the storage area are already in use and what parts are available, etc.
The inode list (table) is a list of inodes that are used to track and maintain information about each file
created on the filesystem. All access to a file is based on the data in the inode list. The inode list is found
immediately after the super block, and the first usable inode is reserved for accessing the root directory of the
filesystem.
The data blocks are where the data of a file is stored. These blocks follow the inode table and occupy most
of the storage device's space.

SuperBlock
The super block contains the following information
- the size of the file system.
- This is the storage size of the device or current partition on the device.
- the list of storage blocks
- The storage space is divided up into a series of standard size blocks.
- When data is moved to or from the filesystem, it is moved in block units.
- the number of free blocks.
- the location of all free blocks.
- the index of the next free block in the free block list.
- the size of the inode list.
- The inode list is initialized to track the maximum number of files that cannot be more than the maximum number
of strorage blocks.
- the number of free inodes in the file system.
- the index of the next free inode in the free inode list.
Inodes
The inode list is a static list. Once the filesystem is created, the size of the list cannot change. The initial
size of the inode list is determined by the Administrator and the size of the storage device.
An inode for a file contains the following information.
- Inode number
- File owner id. (UID) This is the numeric id used in the password file to uniquely identify a user on the system.
- Group id. (GID) This identifies a group that can be granted special access by the owner.
- File type - directory, regular file, link, etc.
- File access permissions. There are three sets of permissions.
- User access - access by the person owns the file, usually the creator.
- Group access - access by the member of a specified group.
- Other access - the rest of the world who are not the owner or recognized group.
- And these sets consist of three types of access.
- read access - to be able to inspect the data stored in the file.
- write access - to be able to modify the data stored in the file.
- execute access - to be able to request that the system attempt to execute (run) the file as a command.
- File access time - when the file data last read.
- Some actions that will change this value.
- Displaying the contents of the file with cat or less.
- Copying the file to a new location.
- Editing the file with vi or pico, even if you don't save any changes.
- Some actions that will NOT change this value.
- Moving the file to another name or directory in the current filesystem partition.
- Using redirection to append data to an existing file.
- File modification time - when the file data last changed.
- Creating a new file initializes this value.
- Editing a file and saving it will update this value.
- Overwriting the file with new data will update this value.
- Appending data to an existing file will update.
- inode modification time - when was information in the inode last changed.
- Creating additional hard links to the file will change inode info.
- Changes in the size of the file will change the inode info
- Changes in the file access timestamp do NOT qualify as change in inode info.
- Number of links - how many directory entries reference the same inode.
- Size of file - size of file in bytes.
- Table of disk addresses - - where data is stored on the storage device.
- Although uses treat the data in a file as a logical stream of bytes, the kernal saves the data in disk blocks
scattered all over the storage device. The inode identifies the blocks storing the file's data and the order in
which to retrieve it. There is room for 13 addresses or pointers, the first 10 point directly to the blocks containing
the file. If a storage block can hold 512 bytes of data, the first 10 pointers can point directly to 5K of storage.
- If additional storage is required for the file, the 11th file pointer will be used as an indirect pointer.
It will point to a disk storage block that will be converted into a table of additional block pointers. If a block
contains 512 bytes and a pointer uses 4 bytes, this would create a table of 128 additional storage block pointers.
This will add 128 pointers * 4K per block that can access/store a 500K file.
- If additional storage is required for the file, the 12th file pointer will be used as a double indirect pointer.
It will point to a disk storage block that will be converted into a table of additional block pointers. The blocks
these pointers point to will also be converted to tables of pointers (as needed). This will allow up to 128 * 128
additional storage block pointers that can keep track of a 6.7 Megabyte file.
- If additional storage is required for the file, the 13th file pointer will be used as a triple indirect pointer
(a pointer to a table of pointers that point to tables of pointers that point to other tables of pointers that
point to the blocks containing the file). The total block pointers would be 128 * 128 * 128 or up to 2097152 pointers
that could theoretically keep track of an 8 Gigabyte file. However, the size field in the inode is only four bytes
which set the file size at a 4 Gig limit.


NFS
The Network File System (NFS) is a protocol suite that allows the file system to logically include directories
and files in a file system while they physically reside on disks attached to remote hosts. The NFS is implemented
using a set of remote procedure calls that transparently request and receive files across the network.
Disk space commands
df reports the free disk space or inodes on file systems, e.g. to report the disk space.
du reports the number of disk blocks used by directory or file.
Where Stuff Is
The actual locations and names of certain system configuration files will differ under different implementations
of Unix. Here are
some examples:
/dev - Where special I/O files are kept
/bin - Executable system utilities, like sh, cp, rm
/etc - System configuration files and databases
/lib - Operating system and programming libraries
/tmp - System scratch files (all users can write here)
/lost+found - Where the file system checker puts detached files
/usr/bin - Additional user commands
/usr/include - Standard system header files
/usr/lib - More programming and system call libraries
/usr/local - Typically a place where local utilities go
/usr/man - The manual pages are kept here
Some Special Files
/dev/null - the bit bucket
/dev/pts/number - telnet session file identifier
* figure from here