FILSYS(5) FILSYS(5) NAME filsys, flblk, ino - format of a disk file system 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 information. Block 1 is the `super-block'. Its layout is defined in `<sys/filsys.h>': struct filsys { unsigned short s_isize; daddr_t s_fsize; short s_ninode; ino_t s_inode[NICINOD]; char s_flock; char s_ilock; char s_fmod; char s_ronly; time_t s_time; daddr_t s_tfree; ino_t s_tinode; short s_dinfo[2]; #define s_m s_dinfo[0] #define s_n s_dinfo[1] #define s_cylsize s_dinfo[0] #define s_aspace s_dinfo[1] char s_fsmnt[14]; ino_t s_lasti; ino_t s_nbehind; union { struct { short S_nfree; daddr_t S_free[NICFREE]; } R; struct { char S_valid; #define BITMAP 961 long S_bfree[BITMAP]; } B; struct { FILSYS(5) FILSYS(5) char S_valid; char S_flag; /* 1 means bitmap not in S_bfree */ long S_bsize; /* size of bitmap blocks */ struct buf *S_blk[BITMAP-1]; } N; } U; }; #define s_nfree U.R.S_nfree #define s_free U.R.S_free #define s_valid U.B.S_valid #define s_bfree U.B.S_bfree s_isize The address of the first block after the i-list, which starts in block 2. Thus the i-list is `s_isize-2' blocks long. s_fsize The address of the first block not in the file sys- tem. s_inode Array of free inode numbers. s_ninode The number of free i-numbers in the `s_inode' array. Inodes are placed in the list in LIFO order. If the list underflows, it is replenished by searching the i-list to obtain the numbers of free inodes. When the list is full, freed inodes are not recorded in `s_inode'. s_lasti Where the last search for free inodes ended. s_nbehind Number of free inodes before `s_lasti' that are not listed in `s_inode'. The system will search for- ward for free inodes from `s_lasti' for more inodes unless `s_nbehind' is sufficiently large, in which case it will search the i-list from the beginning. s_flock s_ilock Flags maintained in the core copy of the super- block while the file system while it is mounted. The values on disk are immaterial. s_fmod 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. The value on disk is immaterial. s_ronly Flag for read-only file system. The value on disk is immaterial. s_time Time of the last change to the super block. FILSYS(5) FILSYS(5) s_dinfo Disk interleave information: s_cylsize= blocks per cylinder, s_aspace= blocks to skip; see fsck(8). s_fsmnt Unused. s_tfree s_tinode Numbers of free blocks and free inodes. Maintained for the benefit of df (see du(1)), these values are otherwise irrelevant. Different data are used to manage free space in 1K and 4K file systems. These fields are for 1K file systems: s_free An array of free block numbers. `s_free[0]' is the block address of the next in a chain of blocks con- stituting the free list. The layout of these blocks is defined in `<sys/fblk.h>': struct fblk { int df_nfree; daddr_t df_free[NICFREE]; } where `df_nfree' and `df_free' are exactly like `s_nfree' and `s_free.' s_nfree Blocks given in `s_free[1]' through `s_free[s_nfree-1]' are available for allocation. Blocks are allocated in LIFO fashion from this list. If freeing would cause the array to overflow, it is cleared by copying into the newly freed block, which is pushed onto the free chain. If allocation would cause underflow, the array is replenished from the next block on the chain. These are for 4K file systems: s_bfree a bit array specifying the free blocks of a 4K file system. 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. If the file system is too large for the bitmap to fit here, then it is stored at the end of the file system, and locked into mem- ory when the file system is mounted. The N variant of the union is used by the kernel in this case. s_valid The bitmap of a mounted file system is maintained only in main memory; the bitmap on the medium is marked invalid 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 cor- rected by chuck(8). FILSYS(5) FILSYS(5) I-numbers begin at 1, and the storage for inodes begins in block 2. Inodes are 64 bytes long. 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. The layout of an inode is defined in `<sys/ino.h>': struct dinode { unsigned short di_mode; short di_nlink; short di_uid; short di_gid; off_t di_size; char di_addr[40]; time_t di_atime; time_t di_mtime; time_t di_ctime; }; di_mode The kind of file; it is encoded as `st_mode field of' stat(2), and is 0 for a free inode. di_nlink The number of directory entries (links) that refer to this inode di_uid Owner's userid. di_gid Owner's groupid. di_size Number of bytes in the file. di_atime Time of last access; see times(2). di_mtime Time of last modification. di_ctime Time of last change to inode or contents. di_addr For special files the first two bytes of `di_addr' contain the device code; see intro(4) and types(5). For plain files and directories `di_addr' contains block numbers packed into 3 bytes each. The first 10 numbers specify device blocks directly. The last 3 are singly, doubly, and triply indirect and point to blocks of block pointers of type `daddr_t' (see types(5)). A zero pointer indicates a `hole' where no data has been written. Holes read as if they contained all zeros. A symbolic link is, aside from mode, a plain file whose sole content is the name of the file linked to. FILSYS(5) FILSYS(5) SEE ALSO chuck(8), fsck(8), icheck(8), dir(5), mount(8), stat(2), types(5), l3tol(3)