151139Sbostic /*- 251139Sbostic * Copyright (c) 1991 The Regents of the University of California. 351139Sbostic * All rights reserved. 451139Sbostic * 551139Sbostic * %sccs.include.redist.c% 651139Sbostic * 7*55587Sbostic * @(#)lfs.h 7.18 (Berkeley) 07/23/92 851139Sbostic */ 951139Sbostic 1051140Sbostic #define LFS_LABELPAD 8192 /* LFS label size */ 1151140Sbostic #define LFS_SBPAD 8192 /* LFS superblock size */ 1251139Sbostic 1355546Sbostic /* 1455546Sbostic * XXX 1555546Sbostic * This is a kluge and NEEDS to go away. 1655546Sbostic * 1755546Sbostic * Right now, ufs code handles most of the calls for directory operations 1855546Sbostic * such as create, mkdir, link, etc. As a result VOP_UPDATE is being 1955546Sbostic * called with waitfor set (since ffs does these things synchronously). 2055546Sbostic * Since LFS does not want to do these synchronously, we treat the last 2155546Sbostic * argument to lfs_update as a set of flags. If LFS_SYNC is set, then 2255546Sbostic * the update should be synchronous, if not, do it asynchronously. 2355546Sbostic * Unfortunately, this means that LFS won't work with NFS yet because 2455546Sbostic * NFS goes through paths that will make normal calls to ufs which will 2555546Sbostic * call lfs with a last argument of 1. 2655546Sbostic */ 2755546Sbostic #define LFS_SYNC 0x02 2855546Sbostic 2951155Sbostic /* On-disk and in-memory checkpoint segment usage structure. */ 3051183Sbostic typedef struct segusage SEGUSE; 3151183Sbostic struct segusage { 3251155Sbostic u_long su_nbytes; /* number of live bytes */ 3351350Sbostic u_long su_lastmod; /* SEGUSE last modified timestamp */ 34*55587Sbostic u_short su_nsums; /* number of summaries in segment */ 35*55587Sbostic u_short su_ninos; /* number of inode blocks in seg */ 3651912Sbostic #define SEGUSE_ACTIVE 0x1 /* segment is currently being written */ 3751912Sbostic #define SEGUSE_DIRTY 0x2 /* segment has data in it */ 3851912Sbostic #define SEGUSE_SUPERBLOCK 0x4 /* segment contains a superblock */ 3951155Sbostic u_long su_flags; 4051183Sbostic }; 4151155Sbostic 42*55587Sbostic #define SEGUPB(fs) (1 << (fs)->lfs_sushift); 4351850Sbostic #define SEGTABSIZE_SU(fs) \ 44*55587Sbostic ((fs)->lfs_nseg >> ((fs)->lfs_bshift - (fs)->lfs_sushift)) 4551850Sbostic 4651183Sbostic /* On-disk file information. One per file with data blocks in the segment. */ 4751183Sbostic typedef struct finfo FINFO; 4851183Sbostic struct finfo { 4951183Sbostic u_long fi_nblocks; /* number of blocks */ 5051183Sbostic u_long fi_version; /* version number */ 5151215Sbostic u_long fi_ino; /* inode number */ 5251183Sbostic long fi_blocks[1]; /* array of logical block numbers */ 5351183Sbostic }; 5451183Sbostic 5551155Sbostic /* On-disk and in-memory super block. */ 5651183Sbostic struct lfs { 5752149Sbostic #define LFS_MAGIC 0x070162 5851139Sbostic u_long lfs_magic; /* magic number */ 5951140Sbostic #define LFS_VERSION 1 6051139Sbostic u_long lfs_version; /* version number */ 6151139Sbostic 6251139Sbostic u_long lfs_size; /* number of blocks in fs */ 6351139Sbostic u_long lfs_ssize; /* number of blocks per segment */ 6451139Sbostic u_long lfs_dsize; /* number of data blocks in fs */ 6551139Sbostic u_long lfs_bsize; /* size of basic blocks in fs */ 6651139Sbostic u_long lfs_fsize; /* size of frag blocks in fs */ 6751139Sbostic u_long lfs_frag; /* number of frags in a block in fs */ 6851139Sbostic 6951139Sbostic /* Checkpoint region. */ 7051139Sbostic ino_t lfs_free; /* start of the free list */ 71*55587Sbostic u_long lfs_bfree; /* number of free disk blocks */ 7251155Sbostic u_long lfs_nfiles; /* number of allocated inodes */ 7351139Sbostic daddr_t lfs_idaddr; /* inode file disk address */ 7451139Sbostic ino_t lfs_ifile; /* inode file inode number */ 7551303Sbostic daddr_t lfs_lastseg; /* address of last segment written */ 7651303Sbostic daddr_t lfs_nextseg; /* address of next segment to write */ 7751912Sbostic daddr_t lfs_curseg; /* current segment being written */ 7851850Sbostic daddr_t lfs_offset; /* offset in curseg for next partial */ 7954264Sbostic daddr_t lfs_lastpseg; /* address of last partial written */ 8051139Sbostic u_long lfs_tstamp; /* time stamp */ 8151139Sbostic 8251139Sbostic /* These are configuration parameters. */ 8351139Sbostic u_long lfs_minfree; /* minimum percentage of free blocks */ 8451139Sbostic 8551139Sbostic /* These fields can be computed from the others. */ 8655454Sbostic u_quad_t lfs_maxfilesize; /* maximum representable file size */ 8751850Sbostic u_long lfs_dbpseg; /* disk blocks per segment */ 8851139Sbostic u_long lfs_inopb; /* inodes per block */ 8951139Sbostic u_long lfs_ifpb; /* IFILE entries per block */ 9051850Sbostic u_long lfs_sepb; /* SEGUSE entries per block */ 9151139Sbostic u_long lfs_nindir; /* indirect pointers per block */ 9251139Sbostic u_long lfs_nseg; /* number of segments */ 9351139Sbostic u_long lfs_nspf; /* number of sectors per fragment */ 9451850Sbostic u_long lfs_cleansz; /* cleaner info size in blocks */ 9551139Sbostic u_long lfs_segtabsz; /* segment table size in blocks */ 9651139Sbostic 9751139Sbostic u_long lfs_segmask; /* calculate offset within a segment */ 9851139Sbostic u_long lfs_segshift; /* fast mult/div for segments */ 9951139Sbostic u_long lfs_bmask; /* calc block offset from file offset */ 10051139Sbostic u_long lfs_bshift; /* calc block number from file offset */ 10151139Sbostic u_long lfs_ffmask; /* calc frag offset from file offset */ 10251139Sbostic u_long lfs_ffshift; /* fast mult/div for frag from file */ 10351139Sbostic u_long lfs_fbmask; /* calc frag offset from block offset */ 10451139Sbostic u_long lfs_fbshift; /* fast mult/div for frag from block */ 10551139Sbostic u_long lfs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 106*55587Sbostic u_long lfs_sushift; /* fast mult/div for segusage table */ 10751139Sbostic 10851155Sbostic #define LFS_MIN_SBINTERVAL 5 /* minimum superblock segment spacing */ 10951155Sbostic #define LFS_MAXNUMSB 10 /* superblock disk offsets */ 11051155Sbostic daddr_t lfs_sboffs[LFS_MAXNUMSB]; 11151139Sbostic 11251155Sbostic /* These fields are set at mount time and are meaningless on disk. */ 11353146Sbostic struct vnode *lfs_ivnode; /* vnode for the ifile */ 11454685Sbostic u_long lfs_seglock; /* single-thread the segment writer */ 11551303Sbostic u_long lfs_iocount; /* number of ios pending */ 11654264Sbostic u_long lfs_writer; /* don't allow any dirops to start */ 11754264Sbostic u_long lfs_dirops; /* count of active directory ops */ 11854264Sbostic u_long lfs_doifile; /* Write ifile blocks on next write */ 11951155Sbostic u_char lfs_fmod; /* super block modified flag */ 12051155Sbostic u_char lfs_clean; /* file system is clean flag */ 12151155Sbostic u_char lfs_ronly; /* mounted read-only flag */ 12251155Sbostic u_char lfs_flags; /* currently unused flag */ 12354685Sbostic u_char lfs_fsmnt[MNAMELEN]; /* name mounted on */ 12451155Sbostic u_char pad[3]; /* long-align */ 12551139Sbostic 12651155Sbostic /* Checksum; valid on disk. */ 12751155Sbostic u_long lfs_cksum; /* checksum for superblock checking */ 12851183Sbostic }; 12951139Sbostic 13051155Sbostic /* 13152079Sbostic * Inode 0 is the out-of-band inode number, inode 1 is the inode number for 13252079Sbostic * the IFILE, the root inode is 2 and the lost+found inode is 3. 13351155Sbostic */ 13451139Sbostic 13551140Sbostic /* Fixed inode numbers. */ 13651303Sbostic #define LFS_UNUSED_INUM 0 /* out of band inode number */ 13752079Sbostic #define LFS_IFILE_INUM 1 /* IFILE inode number */ 13852079Sbostic #define LOSTFOUNDINO 3 /* lost+found inode number */ 13952079Sbostic #define LFS_FIRST_INUM 4 /* first free inode number */ 14051139Sbostic 14151155Sbostic /* 14251140Sbostic * Used to access the first spare of the dinode which we use to store 14351140Sbostic * the ifile number so we can identify them 14451140Sbostic */ 14551140Sbostic #define di_inum di_spare[0] 14651140Sbostic 14751850Sbostic /* Address calculations for metadata located in the inode */ 14851850Sbostic #define S_INDIR(fs) -NDADDR 14952997Sstaelin #define D_INDIR(fs) (S_INDIR(fs) - NINDIR(fs) - 1) 15052997Sstaelin #define T_INDIR(fs) (D_INDIR(fs) - NINDIR(fs) * NINDIR(fs) - 1) 15151183Sbostic 15251850Sbostic /* Structure used to pass around logical block paths. */ 15351850Sbostic typedef struct _indir { 15451850Sbostic long in_lbn; /* logical block number */ 15551850Sbostic int in_off; /* offset in buffer */ 15651850Sbostic } INDIR; 15751850Sbostic 15851350Sbostic /* Unassigned disk address. */ 15951350Sbostic #define UNASSIGNED -1 16051350Sbostic 16151183Sbostic typedef struct ifile IFILE; 16251183Sbostic struct ifile { 16351139Sbostic u_long if_version; /* inode version number */ 16451155Sbostic #define LFS_UNUSED_DADDR 0 /* out-of-band daddr */ 16551139Sbostic daddr_t if_daddr; /* inode disk address */ 16652079Sbostic ino_t if_nextfree; /* next-unallocated inode */ 16751183Sbostic }; 16851139Sbostic 16951850Sbostic /* 17051850Sbostic * Cleaner information structure. This resides in the ifile and is used 17151850Sbostic * to pass information between the cleaner and the kernel. 17251850Sbostic */ 17351850Sbostic typedef struct _cleanerinfo { 17451850Sbostic u_long clean; /* K: number of clean segments */ 17551850Sbostic u_long dirty; /* K: number of dirty segments */ 17651850Sbostic } CLEANERINFO; 17751139Sbostic 17851850Sbostic #define CLEANSIZE_SU(fs) \ 17951850Sbostic ((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift) 18051140Sbostic 18151140Sbostic /* 18251140Sbostic * All summary blocks are the same size, so we can always read a summary 18351303Sbostic * block easily from a segment. 18451140Sbostic */ 18551140Sbostic #define LFS_SUMMARY_SIZE 512 18651140Sbostic 18751139Sbostic /* On-disk segment summary information */ 18851183Sbostic typedef struct segsum SEGSUM; 18951183Sbostic struct segsum { 19051850Sbostic u_long ss_sumsum; /* check sum of summary block */ 19151850Sbostic u_long ss_datasum; /* check sum of data */ 19251139Sbostic daddr_t ss_next; /* next segment */ 19351139Sbostic u_long ss_create; /* creation time stamp */ 19454264Sbostic u_short ss_nfinfo; /* number of file info structures */ 19554264Sbostic u_short ss_ninos; /* number of inodes in summary */ 19654264Sbostic #define SS_DIROP 0x01 /* segment begins a dirop */ 19754264Sbostic #define SS_CONT 0x02 /* more partials to finish this write*/ 19854264Sbostic u_short ss_flags; /* used for directory operations */ 19954264Sbostic u_short ss_pad; /* extra space */ 20052993Sbostic /* FINFO's and inode daddr's... */ 20151183Sbostic }; 20251139Sbostic 20351155Sbostic /* NINDIR is the number of indirects in a file system block. */ 20451155Sbostic #define NINDIR(fs) ((fs)->lfs_nindir) 20551155Sbostic 20651155Sbostic /* INOPB is the number of inodes in a secondary storage block. */ 20751155Sbostic #define INOPB(fs) ((fs)->lfs_inopb) 20851155Sbostic 20951155Sbostic #define blksize(fs) ((fs)->lfs_bsize) 21051155Sbostic #define blkoff(fs, loc) ((loc) & (fs)->lfs_bmask) 21151155Sbostic #define fsbtodb(fs, b) ((b) << (fs)->lfs_fsbtodb) 212*55587Sbostic #define dbtofsb(fs, b) ((b) >> (fs)->lfs_fsbtodb) 21351155Sbostic #define lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift) 21451155Sbostic #define lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift) 21551183Sbostic #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ 21651183Sbostic ((loc) >> (fs)->lfs_bshift) 21751350Sbostic 21852079Sbostic #define datosn(fs, daddr) /* disk address to segment number */ \ 21952079Sbostic (((daddr) - (fs)->lfs_sboffs[0]) / fsbtodb((fs), (fs)->lfs_ssize)) 22052079Sbostic #define sntoda(fs, sn) /* segment number to disk address */ \ 22152079Sbostic ((daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) + \ 22252079Sbostic (fs)->lfs_sboffs[0])) 22352079Sbostic 22451925Sbostic /* Read in the block with the cleaner info from the ifile. */ 22551925Sbostic #define LFS_CLEANERINFO(CP, F, BP) { \ 22652079Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 22751936Sbostic if (bread((F)->lfs_ivnode, (daddr_t)0, (F)->lfs_bsize, NOCRED, &(BP))) \ 22851925Sbostic panic("lfs: ifile read"); \ 22951936Sbostic (CP) = (CLEANERINFO *)(BP)->b_un.b_addr; \ 23051925Sbostic } 23151925Sbostic 23251850Sbostic /* Read in the block with a specific inode from the ifile. */ 23351925Sbostic #define LFS_IENTRY(IP, F, IN, BP) { \ 23451936Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 23551850Sbostic if (bread((F)->lfs_ivnode, \ 23651850Sbostic (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz, \ 23751936Sbostic (F)->lfs_bsize, NOCRED, &(BP))) \ 23851481Sbostic panic("lfs: ifile read"); \ 23951936Sbostic (IP) = (IFILE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_ifpb; \ 24051481Sbostic } 24151481Sbostic 24251850Sbostic /* Read in the block with a specific segment usage entry from the ifile. */ 24351925Sbostic #define LFS_SEGENTRY(SP, F, IN, BP) { \ 24451936Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 245*55587Sbostic if (bread((F)->lfs_ivnode, \ 246*55587Sbostic ((IN) >> (F)->lfs_sushift) + (F)->lfs_cleansz, \ 24751936Sbostic (F)->lfs_bsize, NOCRED, &(BP))) \ 24851850Sbostic panic("lfs: ifile read"); \ 249*55587Sbostic (SP) = (SEGUSE *)(BP)->b_un.b_addr + ((IN) & (F)->lfs_sepb - 1); \ 25051850Sbostic } 25151850Sbostic 25252079Sbostic /* Write a block and update the inode change times. */ 25352079Sbostic #define LFS_UBWRITE(BP) { \ 25452079Sbostic VTOI((BP)->b_vp)->i_flag |= ICHG | IUPD; \ 25553499Sheideman VOP_BWRITE(BP); \ 25651936Sbostic } 25751936Sbostic 25851850Sbostic /* 25951850Sbostic * Structures used by lfs_bmapv and lfs_markv to communicate information 26051850Sbostic * about inodes and data blocks. 26151850Sbostic */ 26251850Sbostic typedef struct block_info { 26351850Sbostic ino_t bi_inode; /* inode # */ 26451850Sbostic off_t bi_lbn; /* logical block w/in file */ 26551850Sbostic daddr_t bi_daddr; /* disk address of block */ 26651850Sbostic time_t bi_segcreate; /* origin segment create time */ 26751850Sbostic void *bi_bp; /* data buffer */ 26851850Sbostic } BLOCK_INFO; 26951850Sbostic 27051850Sbostic typedef struct inode_info { 27151850Sbostic ino_t ii_inode; /* inode # */ 27251850Sbostic daddr_t ii_daddr; /* disk address of block */ 27351850Sbostic time_t ii_segcreate; /* origin segment create time */ 27451850Sbostic struct dinode *ii_dinode; /* data buffer */ 27551850Sbostic } INODE_INFO; 276