glenda.party
term% ls -F
term% cat index.txt
FILSYS(5)                     File Formats Manual                    FILSYS(5)



NAME
       filsys, flblk, ino - format of file system volume

SYNOPSIS
       #include <sys/types.h>
       #include <sys/fblk.h>
       #include <sys/filsys.h>
       #include <sys/ino.h>

DESCRIPTION
       Every  file  system is divided into a certain number of blocks of 1K or
       4K bytes, as determined by the predicate BITFS() applied to  the  minor
       device  number where the file system is mounted.  Block 0 is unused and
       is available to contain a bootstrap program, pack label, or  other  in‐
       formation.

       Block  1  is the super block.  The layout of the super block as defined
       by the include file <sys/filsys.h> is:

       S_isize is the address of the  first  block  after  the  i-list,  which
       starts  just  after  the  super-block,  in block 2.  Thus the i-list is
       s_isize-2 blocks long.  S_fsize is the address of the first  block  not
       potentially available for allocation to a file.  These numbers are used
       by the system to check for bad  block  addresses;  if  an  `impossible'
       block address is allocated from the free list or is freed, a diagnostic
       is written on  the  on-line  console.   Moreover,  the  free  array  is
       cleared,  so  as  to  prevent further allocation from a presumably cor‐
       rupted free list.

       The free list for a 1K file  system  is  maintained  as  follows.   The
       s_free  array  contains,  in  s_free[1], ... , s_free[s_nfree-1], up to
       NICFREE free block  numbers.   NICFREE  is  a  configuration  constant.
       S_free[0] is the block address of the head of a chain of blocks consti‐
       tuting the free list.  The layout of each block of the  free  chain  as
       defined in the include file <sys/fblk.h> is:

       The  fields  df_nfree and df_free in a free block are used exactly like
       s_nfree and s_free in the super block.  To allocate a block:  decrement
       s_nfree, and the new block number is s_free[s_nfree].  If the new block
       address is 0, there are no blocks left, so give an error.   If  s_nfree
       became 0, read the new block into s_nfree and s_free.  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 address and increment s_nfree.

       The  free  list  for  a  4K  file  system  is  a   bitmap.    The   bit
       (s_bfree[i/w]>>(i%w))&1,  where w is the bit size of a long, is nonzero
       if the ith data block is free.  The bitmap of a mounted file system  is
       maintained  only in main memory; the bitmap on the medium is marked in‐
       valid by setting s_valid to zero.  Unmounting updates the  medium  copy
       and  sets  s_valid  to  1.   A  file  system with invalid bitmap may be
       mounted read-only; its bitmap can be corrected by fsck(8).

       S_ninode is the number of free i-numbers in the s_inode array.  To  al‐
       locate  an  i-node: if s_ninode is greater than 0, decrement it and re‐
       turn 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 i-node, provided s_ninode is less than NICINODE,
       place  its  number  into  s_inode[s_ninode] and increment s_ninode.  If
       s_ninode is already NICINODE, don't bother to enter  the  freed  i-node
       into  any  table.  This list of i-nodes is only to speed up the alloca‐
       tion process; the information as to whether the inode is really free or
       not is maintained in the inode itself.

       The  fields s_lasti and s_nbehind are used to avoid searching the inode
       list from the beginning each  time  the  system  runs  out  of  inodes.
       S_lasti  gives  the  base  of  the block of inodes last searched on the
       filesystem when inodes ran out, and s_nbehind gives the number  of  in‐
       odes,  whose  numbers  were less than s_lasti when they were freed with
       s_ninode already NICINODE.  Thus s_ninode is the number of free  inodes
       before  s_lasti.   The  system will search forward for free inodes from
       s_lasti for more inodes unless  s_nbehind  is  sufficiently  large,  in
       which  case  it  will search the file system inode list from the begin‐
       ning.  This mechanism avoids quadratic behavior in allocating inodes.

       S_flock and s_ilock are flags maintained in the core copy of  the  file
       system  while  it  is  mounted and their values on disk are immaterial.
       The value of s_fmod on disk is likewise immaterial; it  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 write-protection indicator; its disk value is also immate‐
       rial.

       S_time is the last time the super-block of the file system was changed.
       During  a reboot, s_time of the super-block for the root file system is
       used to set the system's idea of the time.

       The fields s_tfree, s_tinode, s_fname and  s_fpack  are  not  currently
       maintained.

       I-numbers  begin  at  1, and the storage for i-nodes begins in block 2.
       I-nodes are 64 bytes long, so 16 of them fit into a block.  I-node 2 is
       reserved for the root directory of the file system, but no other i-num‐
       ber has a built-in meaning.  Each i-node represents one file.  The for‐
       mat of an i-node as given in the include file <sys/ino.h> is:

       Di_mode  tells  the  kind  of  file;  it  is encoded identically to the
       st_mode field of stat(2).  Di_nlink is the number of directory  entries
       (links)  that  refer to this i-node.  Di_uid and di_gid are the owner's
       user and group IDs.  Size is the number of bytes in the file.  Di_atime
       and  di_mtime are the times of last access and modification of the file
       contents (read, write or create) (see times(2)); Di_ctime  records  the
       time  of  last modification to the inode or to the file, and is used to
       determine whether it should be dumped.

       Special files are recognized by their modes and  not  by  i-number.   A
       block-type  special  file  is one which can potentially be mounted as a
       file system; a character-type special file cannot,  though  it  is  not
       necessarily  character-oriented.   For special files, the di_addr field
       is occupied by the device code (see types(5)).   The  device  codes  of
       block and character special files overlap.

       A symbolic link is, aside from mode, a plain file whose sole content is
       the name of the file linked to.

       Disk addresses of plain files and directories are  kept  in  the  array
       di_addr  packed  into 3 bytes each.  The first 10 addresses specify de‐
       vice blocks directly.  The last 3 addresses  are  singly,  doubly,  and
       triply indirect and point to blocks of 256 block pointers.  Pointers in
       indirect blocks have the type daddr_t (see types(5)).

       For block b in a file to exist, it is not  necessary  that  all  blocks
       less  than b exist.  A zero block number either in the address words of
       the i-node or in an indirect block  indicates  that  the  corresponding
       block  has  never  been allocated.  Such a missing block reads as if it
       contained all zero words.

SEE ALSO
       fsck(8), icheck(8), dcheck(8), dir(5), mount(8), stat(2), types(5)



                                                                     FILSYS(5)