Basic Unix File System Structure

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 imediately 
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
    which 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.

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 indentifies a group that can be granted special access by the 
owner.

File type.
A file can be one of several filetypes.  The following is a partial list.
-  regular file -  a file of data.  
d  directory file - a file that contains filenames and their associated inode
   numbers.
l  symbolic link file - a file that contains the path information needed to
   access a file.  Note that there is nothing to garentee that this information
   is valid.
c  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.
b  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. 
p  pipe (fifo) - when connecting the output of a command to the input of 
   another, the system may need to buffer the data.  

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 thes 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.

Access times.
  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 indentifies 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.  Howver, the size field in the inode is only 
  four bytes which set the file size at a 4 Gig limit.

Other
  NOTE: the one thing that is NOT in the inode table is the name of the file
  used by the user.