151139Sbostic /*- 251139Sbostic * Copyright (c) 1991 The Regents of the University of California. 351139Sbostic * All rights reserved. 451139Sbostic * 551139Sbostic * %sccs.include.redist.c% 651139Sbostic * 7*54264Sbostic * @(#)lfs.h 7.14 (Berkeley) 06/23/92 851139Sbostic */ 951139Sbostic 1051140Sbostic #define LFS_LABELPAD 8192 /* LFS label size */ 1151140Sbostic #define LFS_SBPAD 8192 /* LFS superblock size */ 1251140Sbostic #define MAXMNTLEN 512 /* XXX move from fs.h to mount.h */ 1351139Sbostic 1451155Sbostic /* On-disk and in-memory checkpoint segment usage structure. */ 1551183Sbostic typedef struct segusage SEGUSE; 1651183Sbostic struct segusage { 1751155Sbostic u_long su_nbytes; /* number of live bytes */ 1851350Sbostic u_long su_lastmod; /* SEGUSE last modified timestamp */ 1951912Sbostic #define SEGUSE_ACTIVE 0x1 /* segment is currently being written */ 2051912Sbostic #define SEGUSE_DIRTY 0x2 /* segment has data in it */ 2151912Sbostic #define SEGUSE_SUPERBLOCK 0x4 /* segment contains a superblock */ 22*54264Sbostic #define SEGUSE_LIVELOG 0x8 /* segment has not been checkpointed */ 2351155Sbostic u_long su_flags; 2451183Sbostic }; 2551155Sbostic 2651850Sbostic #define SEGTABSIZE_SU(fs) \ 2751850Sbostic (((fs)->lfs_nseg * sizeof(SEGUSE) + \ 2851850Sbostic ((fs)->lfs_bsize - 1)) >> (fs)->lfs_bshift) 2951850Sbostic 3051183Sbostic /* On-disk file information. One per file with data blocks in the segment. */ 3151183Sbostic typedef struct finfo FINFO; 3251183Sbostic struct finfo { 3351183Sbostic u_long fi_nblocks; /* number of blocks */ 3451183Sbostic u_long fi_version; /* version number */ 3551215Sbostic u_long fi_ino; /* inode number */ 3651183Sbostic long fi_blocks[1]; /* array of logical block numbers */ 3751183Sbostic }; 3851183Sbostic 3951155Sbostic /* On-disk and in-memory super block. */ 4051183Sbostic struct lfs { 4152149Sbostic #define LFS_MAGIC 0x070162 4251139Sbostic u_long lfs_magic; /* magic number */ 4351140Sbostic #define LFS_VERSION 1 4451139Sbostic u_long lfs_version; /* version number */ 4551139Sbostic 4651139Sbostic u_long lfs_size; /* number of blocks in fs */ 4751139Sbostic u_long lfs_ssize; /* number of blocks per segment */ 4851139Sbostic u_long lfs_dsize; /* number of data blocks in fs */ 4951139Sbostic u_long lfs_bsize; /* size of basic blocks in fs */ 5051139Sbostic u_long lfs_fsize; /* size of frag blocks in fs */ 5151139Sbostic u_long lfs_frag; /* number of frags in a block in fs */ 5251139Sbostic 5351139Sbostic /* Checkpoint region. */ 5451139Sbostic ino_t lfs_free; /* start of the free list */ 5551155Sbostic u_long lfs_bfree; /* number of free blocks */ 5651155Sbostic u_long lfs_nfiles; /* number of allocated inodes */ 5751139Sbostic daddr_t lfs_idaddr; /* inode file disk address */ 5851139Sbostic ino_t lfs_ifile; /* inode file inode number */ 5951303Sbostic daddr_t lfs_lastseg; /* address of last segment written */ 6051303Sbostic daddr_t lfs_nextseg; /* address of next segment to write */ 6151912Sbostic daddr_t lfs_curseg; /* current segment being written */ 6251850Sbostic daddr_t lfs_offset; /* offset in curseg for next partial */ 63*54264Sbostic daddr_t lfs_lastpseg; /* address of last partial written */ 6451139Sbostic u_long lfs_tstamp; /* time stamp */ 6551139Sbostic 6651139Sbostic /* These are configuration parameters. */ 6751139Sbostic u_long lfs_minfree; /* minimum percentage of free blocks */ 6851139Sbostic 6951139Sbostic /* These fields can be computed from the others. */ 7051850Sbostic u_long lfs_dbpseg; /* disk blocks per segment */ 7151139Sbostic u_long lfs_inopb; /* inodes per block */ 7251139Sbostic u_long lfs_ifpb; /* IFILE entries per block */ 7351850Sbostic u_long lfs_sepb; /* SEGUSE entries per block */ 7451139Sbostic u_long lfs_nindir; /* indirect pointers per block */ 7551139Sbostic u_long lfs_nseg; /* number of segments */ 7651139Sbostic u_long lfs_nspf; /* number of sectors per fragment */ 7751850Sbostic u_long lfs_cleansz; /* cleaner info size in blocks */ 7851139Sbostic u_long lfs_segtabsz; /* segment table size in blocks */ 7951139Sbostic 8051139Sbostic u_long lfs_segmask; /* calculate offset within a segment */ 8151139Sbostic u_long lfs_segshift; /* fast mult/div for segments */ 8251139Sbostic u_long lfs_bmask; /* calc block offset from file offset */ 8351139Sbostic u_long lfs_bshift; /* calc block number from file offset */ 8451139Sbostic u_long lfs_ffmask; /* calc frag offset from file offset */ 8551139Sbostic u_long lfs_ffshift; /* fast mult/div for frag from file */ 8651139Sbostic u_long lfs_fbmask; /* calc frag offset from block offset */ 8751139Sbostic u_long lfs_fbshift; /* fast mult/div for frag from block */ 8851139Sbostic u_long lfs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 8951139Sbostic 9051155Sbostic #define LFS_MIN_SBINTERVAL 5 /* minimum superblock segment spacing */ 9151155Sbostic #define LFS_MAXNUMSB 10 /* superblock disk offsets */ 9251155Sbostic daddr_t lfs_sboffs[LFS_MAXNUMSB]; 9351139Sbostic 9451155Sbostic /* These fields are set at mount time and are meaningless on disk. */ 9553146Sbostic struct vnode *lfs_ivnode; /* vnode for the ifile */ 9651155Sbostic SEGUSE *lfs_segtab; /* in-memory segment usage table */ 9751850Sbostic /* XXX NOT USED */ 9851850Sbostic void *XXXlfs_seglist; /* list of segments being written */ 9951303Sbostic u_long lfs_iocount; /* number of ios pending */ 100*54264Sbostic u_long lfs_writer; /* don't allow any dirops to start */ 101*54264Sbostic u_long lfs_dirops; /* count of active directory ops */ 102*54264Sbostic u_long lfs_doifile; /* Write ifile blocks on next write */ 10351155Sbostic u_char lfs_fmod; /* super block modified flag */ 10451155Sbostic u_char lfs_clean; /* file system is clean flag */ 10551155Sbostic u_char lfs_ronly; /* mounted read-only flag */ 10651155Sbostic u_char lfs_flags; /* currently unused flag */ 10751155Sbostic u_char lfs_fsmnt[MAXMNTLEN]; /* name mounted on */ 10851155Sbostic u_char pad[3]; /* long-align */ 10951139Sbostic 11051155Sbostic /* Checksum; valid on disk. */ 11151155Sbostic u_long lfs_cksum; /* checksum for superblock checking */ 11251183Sbostic }; 11351139Sbostic 11451155Sbostic /* 11552079Sbostic * Inode 0 is the out-of-band inode number, inode 1 is the inode number for 11652079Sbostic * the IFILE, the root inode is 2 and the lost+found inode is 3. 11751155Sbostic */ 11851139Sbostic 11951140Sbostic /* Fixed inode numbers. */ 12051303Sbostic #define LFS_UNUSED_INUM 0 /* out of band inode number */ 12152079Sbostic #define LFS_IFILE_INUM 1 /* IFILE inode number */ 12252079Sbostic #define LOSTFOUNDINO 3 /* lost+found inode number */ 12352079Sbostic #define LFS_FIRST_INUM 4 /* first free inode number */ 12451139Sbostic 12551155Sbostic /* 12651140Sbostic * Used to access the first spare of the dinode which we use to store 12751140Sbostic * the ifile number so we can identify them 12851140Sbostic */ 12951140Sbostic #define di_inum di_spare[0] 13051140Sbostic 13151850Sbostic /* Address calculations for metadata located in the inode */ 13251850Sbostic #define S_INDIR(fs) -NDADDR 13352997Sstaelin #define D_INDIR(fs) (S_INDIR(fs) - NINDIR(fs) - 1) 13452997Sstaelin #define T_INDIR(fs) (D_INDIR(fs) - NINDIR(fs) * NINDIR(fs) - 1) 13551183Sbostic 13651850Sbostic /* Structure used to pass around logical block paths. */ 13751850Sbostic typedef struct _indir { 13851850Sbostic long in_lbn; /* logical block number */ 13951850Sbostic int in_off; /* offset in buffer */ 14051850Sbostic } INDIR; 14151850Sbostic 14251350Sbostic /* Unassigned disk address. */ 14351350Sbostic #define UNASSIGNED -1 14451350Sbostic 14551183Sbostic typedef struct ifile IFILE; 14651183Sbostic struct ifile { 14751139Sbostic u_long if_version; /* inode version number */ 14851155Sbostic #define LFS_UNUSED_DADDR 0 /* out-of-band daddr */ 14951139Sbostic daddr_t if_daddr; /* inode disk address */ 15052079Sbostic ino_t if_nextfree; /* next-unallocated inode */ 15151183Sbostic }; 15251139Sbostic 15351850Sbostic /* 15451850Sbostic * Cleaner information structure. This resides in the ifile and is used 15551850Sbostic * to pass information between the cleaner and the kernel. 15651850Sbostic */ 15751850Sbostic typedef struct _cleanerinfo { 15851850Sbostic u_long clean; /* K: number of clean segments */ 15951850Sbostic u_long dirty; /* K: number of dirty segments */ 16051850Sbostic } CLEANERINFO; 16151139Sbostic 16251850Sbostic #define CLEANSIZE_SU(fs) \ 16351850Sbostic ((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift) 16451140Sbostic 16551140Sbostic /* 16651140Sbostic * All summary blocks are the same size, so we can always read a summary 16751303Sbostic * block easily from a segment. 16851140Sbostic */ 16951140Sbostic #define LFS_SUMMARY_SIZE 512 17051140Sbostic 17151139Sbostic /* On-disk segment summary information */ 17251183Sbostic typedef struct segsum SEGSUM; 17351183Sbostic struct segsum { 17451850Sbostic u_long ss_sumsum; /* check sum of summary block */ 17551850Sbostic u_long ss_datasum; /* check sum of data */ 17651139Sbostic daddr_t ss_next; /* next segment */ 17751139Sbostic u_long ss_create; /* creation time stamp */ 178*54264Sbostic u_short ss_nfinfo; /* number of file info structures */ 179*54264Sbostic u_short ss_ninos; /* number of inodes in summary */ 180*54264Sbostic #define SS_DIROP 0x01 /* segment begins a dirop */ 181*54264Sbostic #define SS_CONT 0x02 /* more partials to finish this write*/ 182*54264Sbostic u_short ss_flags; /* used for directory operations */ 183*54264Sbostic u_short ss_pad; /* extra space */ 18452993Sbostic /* FINFO's and inode daddr's... */ 18551183Sbostic }; 18651139Sbostic 18751155Sbostic /* NINDIR is the number of indirects in a file system block. */ 18851155Sbostic #define NINDIR(fs) ((fs)->lfs_nindir) 18951155Sbostic 19051155Sbostic /* INOPB is the number of inodes in a secondary storage block. */ 19151155Sbostic #define INOPB(fs) ((fs)->lfs_inopb) 19251155Sbostic 19351155Sbostic #define blksize(fs) ((fs)->lfs_bsize) 19451155Sbostic #define blkoff(fs, loc) ((loc) & (fs)->lfs_bmask) 19551155Sbostic #define fsbtodb(fs, b) ((b) << (fs)->lfs_fsbtodb) 19651155Sbostic #define lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift) 19751155Sbostic #define lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift) 19851183Sbostic #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ 19951183Sbostic ((loc) >> (fs)->lfs_bshift) 20051350Sbostic 20152079Sbostic #define datosn(fs, daddr) /* disk address to segment number */ \ 20252079Sbostic (((daddr) - (fs)->lfs_sboffs[0]) / fsbtodb((fs), (fs)->lfs_ssize)) 20352079Sbostic #define sntoda(fs, sn) /* segment number to disk address */ \ 20452079Sbostic ((daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) + \ 20552079Sbostic (fs)->lfs_sboffs[0])) 20652079Sbostic 20751925Sbostic /* Read in the block with the cleaner info from the ifile. */ 20851925Sbostic #define LFS_CLEANERINFO(CP, F, BP) { \ 20952079Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 21051936Sbostic if (bread((F)->lfs_ivnode, (daddr_t)0, (F)->lfs_bsize, NOCRED, &(BP))) \ 21151925Sbostic panic("lfs: ifile read"); \ 21251936Sbostic (CP) = (CLEANERINFO *)(BP)->b_un.b_addr; \ 21351925Sbostic } 21451925Sbostic 21551850Sbostic /* Read in the block with a specific inode from the ifile. */ 21651925Sbostic #define LFS_IENTRY(IP, F, IN, BP) { \ 21751936Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 21851850Sbostic if (bread((F)->lfs_ivnode, \ 21951850Sbostic (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz, \ 22051936Sbostic (F)->lfs_bsize, NOCRED, &(BP))) \ 22151481Sbostic panic("lfs: ifile read"); \ 22251936Sbostic (IP) = (IFILE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_ifpb; \ 22351481Sbostic } 22451481Sbostic 22551850Sbostic /* Read in the block with a specific segment usage entry from the ifile. */ 22651925Sbostic #define LFS_SEGENTRY(SP, F, IN, BP) { \ 22751936Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 22851850Sbostic if (bread((F)->lfs_ivnode, (IN) / (F)->lfs_sepb + (F)->lfs_cleansz, \ 22951936Sbostic (F)->lfs_bsize, NOCRED, &(BP))) \ 23051850Sbostic panic("lfs: ifile read"); \ 23151936Sbostic (SP) = (SEGUSE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_sepb; \ 23251850Sbostic } 23351850Sbostic 23452079Sbostic /* Write a block and update the inode change times. */ 23552079Sbostic #define LFS_UBWRITE(BP) { \ 23653499Sheideman USES_VOP_BWRITE; \ 23752079Sbostic VTOI((BP)->b_vp)->i_flag |= ICHG | IUPD; \ 23853499Sheideman VOP_BWRITE(BP); \ 23951936Sbostic } 24051936Sbostic 24151850Sbostic /* 24251850Sbostic * Structures used by lfs_bmapv and lfs_markv to communicate information 24351850Sbostic * about inodes and data blocks. 24451850Sbostic */ 24551850Sbostic typedef struct block_info { 24651850Sbostic ino_t bi_inode; /* inode # */ 24751850Sbostic off_t bi_lbn; /* logical block w/in file */ 24851850Sbostic daddr_t bi_daddr; /* disk address of block */ 24951850Sbostic time_t bi_segcreate; /* origin segment create time */ 25051850Sbostic void *bi_bp; /* data buffer */ 25151850Sbostic } BLOCK_INFO; 25251850Sbostic 25351850Sbostic typedef struct inode_info { 25451850Sbostic ino_t ii_inode; /* inode # */ 25551850Sbostic daddr_t ii_daddr; /* disk address of block */ 25651850Sbostic time_t ii_segcreate; /* origin segment create time */ 25751850Sbostic struct dinode *ii_dinode; /* data buffer */ 25851850Sbostic } INODE_INFO; 259