FILESYSTEM(F) UNIX System V
Name
filesystem - format of filesystem types
Syntax
#include <sys/fs/??filsys.h>
#include <sys/types.h>
#include <sys/param.h>
Description
Every filesystem storage volume (for example, a hard disk)
has a common format for certain vital information. Every
such volume is divided into a certain number of 1024-byte
blocks. There are four fileystem types available:
S51K (UNIX fileystem)
XENIX
AFS (ACER Fast Filesystem)
DOS
The DOS filesystem is a 512-byte filesystem. (The DOS
filesystem structure is shown in
/usr/include/fs/dosfilsys.h. This page does not discuss the
format of the DOS filesystem in detail. Consult a DOS
reference for more information.)
Block 0 is unused and is available to contain a bootstrap
program or other information.
Block 1 is the super-block. The format of the S51K, AFS,
and XENIX filesystem super-blocks are described in two files
in the directory /usr/include/fs: s5filsys.h (S51K and AFS),
xxfilsys.h (XENIX). The XENIX filesystem boot block is
1024-bytes; the S51K and UNIX boot blocks are 512-byte
blocks. In these include files, s_isize is the address of
the first data block after the i-list. The i-list starts
just after the super-block in block 2; thus the i-list is
s_isize-2 blocks long. s_fsize is the first block not
potentially available for allocation to a file. These
numbers are used by the system to check for bad block
numbers. If an ``impossible'' block number is allocated
from the free list or is freed, a diagnostic is written on
the console. Moreover, the free array is cleared so as to
prevent further allocation from a presumably corrupted free
list.
The free list for S51K and XENIX volumes (but not AFS) is
maintained as follows: The s_free array contains, in
s_free[1], ..., s_free[s_nfree-1], up to NICFREE-1 numbers
of free blocks. s_free[0] is the block number of the head
of a chain of blocks constituting the free list. The first
short in each free-chain block is the number (up to NICFREE)
of free-block numbers listed in the next NICFREE longs of
this chain member. The first of these NICFREE blocks is the
link to the next member of the chain. To allocate a block:
decrement s_nfree, and the new block is s_free[s_nfree]. If
the new block number is 0, there are no blocks left, so give
an error. If s_nfree becomes 0, read in the block named by
the new block number, replace s_nfree by its first word, and
copy the block numbers in the next NICFREE longs into the
s_free array. To free a block, check if s_nfree is NICFREE;
if so, copy s_nfree and the s_free array into it, write it
out, and set s_nfree to 0. In any event set s_free[s_nfree]
to the freed block's number and increment s_nfree.
In the AFS filesystem, the free list is maintained
differently, The AFS freelist is organized as a bitmap, one
bit per (1K) block in the filesystem. This organization
makes it easy to find contiguous stretches of free blocks.
s_tfree is the total free blocks available in the
filesystem.
s_ninode is the number of free i-numbers in the s_inode
array. To allocate an inode: if s_ninode is greater than 0,
decrement it and return s_inode[s_ninode]. If it was 0,
read the i-list and place the numbers of all free inodes (up
to NICINOD) into the s_inode array, then try again. To free
an inode, provided s_ninode is less than NICINOD, place its
number into s_inode[s_ninode] and increment s_ninode. If
s_ninode is already NICINOD, do not bother to enter the
freed inode into any table. This list of inodes only speeds
up the allocation process. The information about whether the
inode is really free is maintained in the inode itself.
s_tinode is the total free inodes available in the file
system.
The following applies only to S51K and AFS fileystems:
s_state indicates the state of the file system. A cleanly
unmounted, not damaged file system is indicated by the
FsOKAY state. After a file system has been mounted for
update, the state changes to FsACTIVE. A special case is
used for the root file system. If the root file system
appears damaged at boot time, it is mounted but marked
FsBAD. Lastly, after a file system has been unmounted, the
state reverts to FsOKAY.
s_flock and s_ilock are flags maintained in the core copy of
the filesystem while it is mounted and their values on disk
are immaterial. The value of s_fmod on disk is also
immaterial, and is used as a flag to indicate that the
super-block has changed and should be copied to the disk
during the next periodic update of file system information.
s_ronly is a read-only flag to indicate write-protection.
s_time is the last time the super-block of the file system
was changed, and is a double precision representation of the
number of seconds that have elapsed since 00:00 Jan. 1, 1970
(GMT). During a reboot, the s_time of the super-block for
the root file system is used to set the system's idea of the
time.
I-numbers begin at 1, and the storage for inodes begins in
block 2. Also, inodes are 64 bytes long, so 16 of them fit
into a block. Therefore, inode i is located in block
(i+31)/16, and begins 64x((i+31) (mod 16)) bytes from its
start. Inode 1 is reserved for future use. Inode 2 is
reserved for the root directory of the file system, but no
other i-number has a built-in meaning. Each inode
represents one file. For the format of an inode and its
flags, see inode(F).
Files
/usr/include/sys/filsys.h
/usr/include/sys/stat.h
See Also
fsck(ADM), mkfs(ADM), inode(F)
(printed 8/23/89) FILESYSTEM(F)