151139Sbostic /*- 251139Sbostic * Copyright (c) 1991 The Regents of the University of California. 351139Sbostic * All rights reserved. 451139Sbostic * 551139Sbostic * %sccs.include.redist.c% 651139Sbostic * 7*55934Sbostic * @(#)lfs.h 7.21 (Berkeley) 08/21/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 */ 3455587Sbostic u_short su_nsums; /* number of summaries in segment */ 3555587Sbostic 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 4255793Sbostic #define SEGUPB(fs) (1 << (fs)->lfs_sushift) 4351850Sbostic #define SEGTABSIZE_SU(fs) \ 4455793Sbostic (((fs)->lfs_nseg + SEGUPB(fs) - 1) >> (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 */ 7155587Sbostic u_long lfs_bfree; /* number of free disk blocks */ 7251155Sbostic u_long lfs_nfiles; /* number of allocated inodes */ 73*55934Sbostic u_long lfs_avail; /* blocks available for writing */ 74*55934Sbostic u_long lfs_uinodes; /* inodes in cache not yet on disk */ 7551139Sbostic daddr_t lfs_idaddr; /* inode file disk address */ 7651139Sbostic ino_t lfs_ifile; /* inode file inode number */ 7751303Sbostic daddr_t lfs_lastseg; /* address of last segment written */ 7851303Sbostic daddr_t lfs_nextseg; /* address of next segment to write */ 7951912Sbostic daddr_t lfs_curseg; /* current segment being written */ 8051850Sbostic daddr_t lfs_offset; /* offset in curseg for next partial */ 8154264Sbostic daddr_t lfs_lastpseg; /* address of last partial written */ 8251139Sbostic u_long lfs_tstamp; /* time stamp */ 8351139Sbostic 8451139Sbostic /* These are configuration parameters. */ 8551139Sbostic u_long lfs_minfree; /* minimum percentage of free blocks */ 8651139Sbostic 8751139Sbostic /* These fields can be computed from the others. */ 8855454Sbostic u_quad_t lfs_maxfilesize; /* maximum representable file size */ 8951850Sbostic u_long lfs_dbpseg; /* disk blocks per segment */ 9051139Sbostic u_long lfs_inopb; /* inodes per block */ 9151139Sbostic u_long lfs_ifpb; /* IFILE entries per block */ 9251850Sbostic u_long lfs_sepb; /* SEGUSE entries per block */ 9351139Sbostic u_long lfs_nindir; /* indirect pointers per block */ 9451139Sbostic u_long lfs_nseg; /* number of segments */ 9551139Sbostic u_long lfs_nspf; /* number of sectors per fragment */ 9651850Sbostic u_long lfs_cleansz; /* cleaner info size in blocks */ 9751139Sbostic u_long lfs_segtabsz; /* segment table size in blocks */ 9851139Sbostic 9951139Sbostic u_long lfs_segmask; /* calculate offset within a segment */ 10051139Sbostic u_long lfs_segshift; /* fast mult/div for segments */ 10151139Sbostic u_long lfs_bmask; /* calc block offset from file offset */ 10251139Sbostic u_long lfs_bshift; /* calc block number from file offset */ 10351139Sbostic u_long lfs_ffmask; /* calc frag offset from file offset */ 10451139Sbostic u_long lfs_ffshift; /* fast mult/div for frag from file */ 10551139Sbostic u_long lfs_fbmask; /* calc frag offset from block offset */ 10651139Sbostic u_long lfs_fbshift; /* fast mult/div for frag from block */ 10751139Sbostic u_long lfs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 10855587Sbostic u_long lfs_sushift; /* fast mult/div for segusage table */ 10951139Sbostic 11051155Sbostic #define LFS_MIN_SBINTERVAL 5 /* minimum superblock segment spacing */ 11151155Sbostic #define LFS_MAXNUMSB 10 /* superblock disk offsets */ 11251155Sbostic daddr_t lfs_sboffs[LFS_MAXNUMSB]; 11351139Sbostic 11451155Sbostic /* These fields are set at mount time and are meaningless on disk. */ 11553146Sbostic struct vnode *lfs_ivnode; /* vnode for the ifile */ 11654685Sbostic u_long lfs_seglock; /* single-thread the segment writer */ 11751303Sbostic u_long lfs_iocount; /* number of ios pending */ 11854264Sbostic u_long lfs_writer; /* don't allow any dirops to start */ 11954264Sbostic u_long lfs_dirops; /* count of active directory ops */ 12054264Sbostic u_long lfs_doifile; /* Write ifile blocks on next write */ 121*55934Sbostic u_long lfs_nactive; /* Number of segments since last ckp */ 12251155Sbostic u_char lfs_fmod; /* super block modified flag */ 12351155Sbostic u_char lfs_clean; /* file system is clean flag */ 12451155Sbostic u_char lfs_ronly; /* mounted read-only flag */ 12551155Sbostic u_char lfs_flags; /* currently unused flag */ 12654685Sbostic u_char lfs_fsmnt[MNAMELEN]; /* name mounted on */ 12751155Sbostic u_char pad[3]; /* long-align */ 12851139Sbostic 12951155Sbostic /* Checksum; valid on disk. */ 13051155Sbostic u_long lfs_cksum; /* checksum for superblock checking */ 13151183Sbostic }; 13251139Sbostic 13351155Sbostic /* 13452079Sbostic * Inode 0 is the out-of-band inode number, inode 1 is the inode number for 13552079Sbostic * the IFILE, the root inode is 2 and the lost+found inode is 3. 13651155Sbostic */ 13751139Sbostic 13851140Sbostic /* Fixed inode numbers. */ 13951303Sbostic #define LFS_UNUSED_INUM 0 /* out of band inode number */ 14052079Sbostic #define LFS_IFILE_INUM 1 /* IFILE inode number */ 14152079Sbostic #define LOSTFOUNDINO 3 /* lost+found inode number */ 14252079Sbostic #define LFS_FIRST_INUM 4 /* first free inode number */ 14351139Sbostic 14451155Sbostic /* 14551140Sbostic * Used to access the first spare of the dinode which we use to store 14651140Sbostic * the ifile number so we can identify them 14751140Sbostic */ 14851140Sbostic #define di_inum di_spare[0] 14951140Sbostic 15051850Sbostic /* Address calculations for metadata located in the inode */ 15151850Sbostic #define S_INDIR(fs) -NDADDR 15252997Sstaelin #define D_INDIR(fs) (S_INDIR(fs) - NINDIR(fs) - 1) 15352997Sstaelin #define T_INDIR(fs) (D_INDIR(fs) - NINDIR(fs) * NINDIR(fs) - 1) 15451183Sbostic 15551850Sbostic /* Structure used to pass around logical block paths. */ 15651850Sbostic typedef struct _indir { 15751850Sbostic long in_lbn; /* logical block number */ 15851850Sbostic int in_off; /* offset in buffer */ 15951850Sbostic } INDIR; 16051850Sbostic 16151350Sbostic /* Unassigned disk address. */ 16251350Sbostic #define UNASSIGNED -1 16351350Sbostic 164*55934Sbostic /* Unused logical block number */ 165*55934Sbostic #define LFS_UNUSED_LBN -1 166*55934Sbostic 16751183Sbostic typedef struct ifile IFILE; 16851183Sbostic struct ifile { 16951139Sbostic u_long if_version; /* inode version number */ 17051155Sbostic #define LFS_UNUSED_DADDR 0 /* out-of-band daddr */ 17151139Sbostic daddr_t if_daddr; /* inode disk address */ 17252079Sbostic ino_t if_nextfree; /* next-unallocated inode */ 17351183Sbostic }; 17451139Sbostic 17551850Sbostic /* 17651850Sbostic * Cleaner information structure. This resides in the ifile and is used 17751850Sbostic * to pass information between the cleaner and the kernel. 17851850Sbostic */ 17951850Sbostic typedef struct _cleanerinfo { 18051850Sbostic u_long clean; /* K: number of clean segments */ 18151850Sbostic u_long dirty; /* K: number of dirty segments */ 18251850Sbostic } CLEANERINFO; 18351139Sbostic 18451850Sbostic #define CLEANSIZE_SU(fs) \ 18551850Sbostic ((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift) 18651140Sbostic 18751140Sbostic /* 18851140Sbostic * All summary blocks are the same size, so we can always read a summary 18951303Sbostic * block easily from a segment. 19051140Sbostic */ 19151140Sbostic #define LFS_SUMMARY_SIZE 512 19251140Sbostic 19351139Sbostic /* On-disk segment summary information */ 19451183Sbostic typedef struct segsum SEGSUM; 19551183Sbostic struct segsum { 19651850Sbostic u_long ss_sumsum; /* check sum of summary block */ 19751850Sbostic u_long ss_datasum; /* check sum of data */ 19851139Sbostic daddr_t ss_next; /* next segment */ 19951139Sbostic u_long ss_create; /* creation time stamp */ 20054264Sbostic u_short ss_nfinfo; /* number of file info structures */ 20154264Sbostic u_short ss_ninos; /* number of inodes in summary */ 20254264Sbostic #define SS_DIROP 0x01 /* segment begins a dirop */ 20354264Sbostic #define SS_CONT 0x02 /* more partials to finish this write*/ 20454264Sbostic u_short ss_flags; /* used for directory operations */ 20554264Sbostic u_short ss_pad; /* extra space */ 20652993Sbostic /* FINFO's and inode daddr's... */ 20751183Sbostic }; 20851139Sbostic 20951155Sbostic /* NINDIR is the number of indirects in a file system block. */ 21051155Sbostic #define NINDIR(fs) ((fs)->lfs_nindir) 21151155Sbostic 21251155Sbostic /* INOPB is the number of inodes in a secondary storage block. */ 21351155Sbostic #define INOPB(fs) ((fs)->lfs_inopb) 21451155Sbostic 21551155Sbostic #define blksize(fs) ((fs)->lfs_bsize) 21651155Sbostic #define blkoff(fs, loc) ((loc) & (fs)->lfs_bmask) 21751155Sbostic #define fsbtodb(fs, b) ((b) << (fs)->lfs_fsbtodb) 21855587Sbostic #define dbtofsb(fs, b) ((b) >> (fs)->lfs_fsbtodb) 21951155Sbostic #define lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift) 22051155Sbostic #define lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift) 22151183Sbostic #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ 22251183Sbostic ((loc) >> (fs)->lfs_bshift) 22351350Sbostic 22452079Sbostic #define datosn(fs, daddr) /* disk address to segment number */ \ 22552079Sbostic (((daddr) - (fs)->lfs_sboffs[0]) / fsbtodb((fs), (fs)->lfs_ssize)) 22652079Sbostic #define sntoda(fs, sn) /* segment number to disk address */ \ 22752079Sbostic ((daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) + \ 22852079Sbostic (fs)->lfs_sboffs[0])) 22952079Sbostic 23051925Sbostic /* Read in the block with the cleaner info from the ifile. */ 23151925Sbostic #define LFS_CLEANERINFO(CP, F, BP) { \ 23252079Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 23351936Sbostic if (bread((F)->lfs_ivnode, (daddr_t)0, (F)->lfs_bsize, NOCRED, &(BP))) \ 23451925Sbostic panic("lfs: ifile read"); \ 23551936Sbostic (CP) = (CLEANERINFO *)(BP)->b_un.b_addr; \ 23651925Sbostic } 23751925Sbostic 23851850Sbostic /* Read in the block with a specific inode from the ifile. */ 23951925Sbostic #define LFS_IENTRY(IP, F, IN, BP) { \ 240*55934Sbostic int _e; \ 24151936Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 242*55934Sbostic if (_e = bread((F)->lfs_ivnode, \ 24351850Sbostic (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz, \ 24451936Sbostic (F)->lfs_bsize, NOCRED, &(BP))) \ 245*55934Sbostic panic("lfs: ifile read %d", _e); \ 24651936Sbostic (IP) = (IFILE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_ifpb; \ 24751481Sbostic } 24851481Sbostic 24951850Sbostic /* Read in the block with a specific segment usage entry from the ifile. */ 25051925Sbostic #define LFS_SEGENTRY(SP, F, IN, BP) { \ 251*55934Sbostic int _e; \ 25251936Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 253*55934Sbostic if (_e = bread((F)->lfs_ivnode, \ 25455587Sbostic ((IN) >> (F)->lfs_sushift) + (F)->lfs_cleansz, \ 25551936Sbostic (F)->lfs_bsize, NOCRED, &(BP))) \ 256*55934Sbostic panic("lfs: ifile read: %d", _e); \ 25755587Sbostic (SP) = (SEGUSE *)(BP)->b_un.b_addr + ((IN) & (F)->lfs_sepb - 1); \ 25851850Sbostic } 25951850Sbostic 260*55934Sbostic /* 261*55934Sbostic * Determine if there is enough room currently available to write db 262*55934Sbostic * disk blocks. We need enough blocks for the new blocks, the current, 263*55934Sbostic * inode blocks, a summary block, plus potentially the ifile inode and 264*55934Sbostic * the segment usage table, plus an ifile page. 265*55934Sbostic */ 266*55934Sbostic #define LFS_FITS(fs, db) \ 267*55934Sbostic ((db + ((fs)->lfs_uinodes + INOPB((fs))) / INOPB((fs)) + \ 268*55934Sbostic fsbtodb(fs, 1) + LFS_SUMMARY_SIZE / DEV_BSIZE + (fs)->lfs_segtabsz)\ 269*55934Sbostic < (fs)->lfs_avail) 27051936Sbostic 271*55934Sbostic /* Determine if a buffer belongs to the ifile */ 272*55934Sbostic #define IS_IFILE(bp) (VTOI(bp->b_vp)->i_number == LFS_IFILE_INUM) 27351850Sbostic /* 27451850Sbostic * Structures used by lfs_bmapv and lfs_markv to communicate information 27551850Sbostic * about inodes and data blocks. 27651850Sbostic */ 27751850Sbostic typedef struct block_info { 27851850Sbostic ino_t bi_inode; /* inode # */ 27955667Sbostic daddr_t bi_lbn; /* logical block w/in file */ 28051850Sbostic daddr_t bi_daddr; /* disk address of block */ 28151850Sbostic time_t bi_segcreate; /* origin segment create time */ 28251850Sbostic void *bi_bp; /* data buffer */ 28351850Sbostic } BLOCK_INFO; 28451850Sbostic 28551850Sbostic typedef struct inode_info { 28651850Sbostic ino_t ii_inode; /* inode # */ 28751850Sbostic daddr_t ii_daddr; /* disk address of block */ 28851850Sbostic time_t ii_segcreate; /* origin segment create time */ 28951850Sbostic struct dinode *ii_dinode; /* data buffer */ 29051850Sbostic } INODE_INFO; 291*55934Sbostic 292*55934Sbostic /* In-memory description of a segment about to be written. */ 293*55934Sbostic struct segment { 294*55934Sbostic struct lfs *fs; /* file system pointer */ 295*55934Sbostic struct buf **bpp; /* pointer to buffer array */ 296*55934Sbostic struct buf **cbpp; /* pointer to next available bp */ 297*55934Sbostic struct buf **start_bpp; /* pointer to first bp in this set */ 298*55934Sbostic struct buf *ibp; /* buffer pointer to inode page */ 299*55934Sbostic struct finfo *fip; /* current fileinfo pointer */ 300*55934Sbostic void *segsum; /* segment summary info */ 301*55934Sbostic u_long ninodes; /* number of inodes in this segment */ 302*55934Sbostic u_long seg_bytes_left; /* bytes left in segment */ 303*55934Sbostic u_long sum_bytes_left; /* bytes left in summary block */ 304*55934Sbostic u_long seg_number; /* number of this segment */ 305*55934Sbostic daddr_t *start_lbp; /* beginning lbn for this set */ 306*55934Sbostic #define SEGM_CKP 0x01 /* doing a checkpoint */ 307*55934Sbostic #define SEGM_CLEAN 0x02 /* cleaner call; don't sort */ 308*55934Sbostic u_long seg_flags; /* run-time flags for this segment */ 309*55934Sbostic }; 310