151139Sbostic /*- 251139Sbostic * Copyright (c) 1991 The Regents of the University of California. 351139Sbostic * All rights reserved. 451139Sbostic * 551139Sbostic * %sccs.include.redist.c% 651139Sbostic * 7*55454Sbostic * @(#)lfs.h 7.16 (Berkeley) 07/20/92 851139Sbostic */ 951139Sbostic 1051140Sbostic #define LFS_LABELPAD 8192 /* LFS label size */ 1151140Sbostic #define LFS_SBPAD 8192 /* LFS superblock size */ 1251139Sbostic 1351155Sbostic /* On-disk and in-memory checkpoint segment usage structure. */ 1451183Sbostic typedef struct segusage SEGUSE; 1551183Sbostic struct segusage { 1651155Sbostic u_long su_nbytes; /* number of live bytes */ 1751350Sbostic u_long su_lastmod; /* SEGUSE last modified timestamp */ 1851912Sbostic #define SEGUSE_ACTIVE 0x1 /* segment is currently being written */ 1951912Sbostic #define SEGUSE_DIRTY 0x2 /* segment has data in it */ 2051912Sbostic #define SEGUSE_SUPERBLOCK 0x4 /* segment contains a superblock */ 2154264Sbostic #define SEGUSE_LIVELOG 0x8 /* segment has not been checkpointed */ 2251155Sbostic u_long su_flags; 2351183Sbostic }; 2451155Sbostic 2551850Sbostic #define SEGTABSIZE_SU(fs) \ 2651850Sbostic (((fs)->lfs_nseg * sizeof(SEGUSE) + \ 2751850Sbostic ((fs)->lfs_bsize - 1)) >> (fs)->lfs_bshift) 2851850Sbostic 2951183Sbostic /* On-disk file information. One per file with data blocks in the segment. */ 3051183Sbostic typedef struct finfo FINFO; 3151183Sbostic struct finfo { 3251183Sbostic u_long fi_nblocks; /* number of blocks */ 3351183Sbostic u_long fi_version; /* version number */ 3451215Sbostic u_long fi_ino; /* inode number */ 3551183Sbostic long fi_blocks[1]; /* array of logical block numbers */ 3651183Sbostic }; 3751183Sbostic 3851155Sbostic /* On-disk and in-memory super block. */ 3951183Sbostic struct lfs { 4052149Sbostic #define LFS_MAGIC 0x070162 4151139Sbostic u_long lfs_magic; /* magic number */ 4251140Sbostic #define LFS_VERSION 1 4351139Sbostic u_long lfs_version; /* version number */ 4451139Sbostic 4551139Sbostic u_long lfs_size; /* number of blocks in fs */ 4651139Sbostic u_long lfs_ssize; /* number of blocks per segment */ 4751139Sbostic u_long lfs_dsize; /* number of data blocks in fs */ 4851139Sbostic u_long lfs_bsize; /* size of basic blocks in fs */ 4951139Sbostic u_long lfs_fsize; /* size of frag blocks in fs */ 5051139Sbostic u_long lfs_frag; /* number of frags in a block in fs */ 5151139Sbostic 5251139Sbostic /* Checkpoint region. */ 5351139Sbostic ino_t lfs_free; /* start of the free list */ 5451155Sbostic u_long lfs_bfree; /* number of free blocks */ 5551155Sbostic u_long lfs_nfiles; /* number of allocated inodes */ 5651139Sbostic daddr_t lfs_idaddr; /* inode file disk address */ 5751139Sbostic ino_t lfs_ifile; /* inode file inode number */ 5851303Sbostic daddr_t lfs_lastseg; /* address of last segment written */ 5951303Sbostic daddr_t lfs_nextseg; /* address of next segment to write */ 6051912Sbostic daddr_t lfs_curseg; /* current segment being written */ 6151850Sbostic daddr_t lfs_offset; /* offset in curseg for next partial */ 6254264Sbostic daddr_t lfs_lastpseg; /* address of last partial written */ 6351139Sbostic u_long lfs_tstamp; /* time stamp */ 6451139Sbostic 6551139Sbostic /* These are configuration parameters. */ 6651139Sbostic u_long lfs_minfree; /* minimum percentage of free blocks */ 6751139Sbostic 6851139Sbostic /* These fields can be computed from the others. */ 69*55454Sbostic u_quad_t lfs_maxfilesize; /* maximum representable file size */ 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 */ 9654685Sbostic u_long lfs_seglock; /* single-thread the segment writer */ 9751303Sbostic u_long lfs_iocount; /* number of ios pending */ 9854264Sbostic u_long lfs_writer; /* don't allow any dirops to start */ 9954264Sbostic u_long lfs_dirops; /* count of active directory ops */ 10054264Sbostic u_long lfs_doifile; /* Write ifile blocks on next write */ 10151155Sbostic u_char lfs_fmod; /* super block modified flag */ 10251155Sbostic u_char lfs_clean; /* file system is clean flag */ 10351155Sbostic u_char lfs_ronly; /* mounted read-only flag */ 10451155Sbostic u_char lfs_flags; /* currently unused flag */ 10554685Sbostic u_char lfs_fsmnt[MNAMELEN]; /* name mounted on */ 10651155Sbostic u_char pad[3]; /* long-align */ 10751139Sbostic 10851155Sbostic /* Checksum; valid on disk. */ 10951155Sbostic u_long lfs_cksum; /* checksum for superblock checking */ 11051183Sbostic }; 11151139Sbostic 11251155Sbostic /* 11352079Sbostic * Inode 0 is the out-of-band inode number, inode 1 is the inode number for 11452079Sbostic * the IFILE, the root inode is 2 and the lost+found inode is 3. 11551155Sbostic */ 11651139Sbostic 11751140Sbostic /* Fixed inode numbers. */ 11851303Sbostic #define LFS_UNUSED_INUM 0 /* out of band inode number */ 11952079Sbostic #define LFS_IFILE_INUM 1 /* IFILE inode number */ 12052079Sbostic #define LOSTFOUNDINO 3 /* lost+found inode number */ 12152079Sbostic #define LFS_FIRST_INUM 4 /* first free inode number */ 12251139Sbostic 12351155Sbostic /* 12451140Sbostic * Used to access the first spare of the dinode which we use to store 12551140Sbostic * the ifile number so we can identify them 12651140Sbostic */ 12751140Sbostic #define di_inum di_spare[0] 12851140Sbostic 12951850Sbostic /* Address calculations for metadata located in the inode */ 13051850Sbostic #define S_INDIR(fs) -NDADDR 13152997Sstaelin #define D_INDIR(fs) (S_INDIR(fs) - NINDIR(fs) - 1) 13252997Sstaelin #define T_INDIR(fs) (D_INDIR(fs) - NINDIR(fs) * NINDIR(fs) - 1) 13351183Sbostic 13451850Sbostic /* Structure used to pass around logical block paths. */ 13551850Sbostic typedef struct _indir { 13651850Sbostic long in_lbn; /* logical block number */ 13751850Sbostic int in_off; /* offset in buffer */ 13851850Sbostic } INDIR; 13951850Sbostic 14051350Sbostic /* Unassigned disk address. */ 14151350Sbostic #define UNASSIGNED -1 14251350Sbostic 14351183Sbostic typedef struct ifile IFILE; 14451183Sbostic struct ifile { 14551139Sbostic u_long if_version; /* inode version number */ 14651155Sbostic #define LFS_UNUSED_DADDR 0 /* out-of-band daddr */ 14751139Sbostic daddr_t if_daddr; /* inode disk address */ 14852079Sbostic ino_t if_nextfree; /* next-unallocated inode */ 14951183Sbostic }; 15051139Sbostic 15151850Sbostic /* 15251850Sbostic * Cleaner information structure. This resides in the ifile and is used 15351850Sbostic * to pass information between the cleaner and the kernel. 15451850Sbostic */ 15551850Sbostic typedef struct _cleanerinfo { 15651850Sbostic u_long clean; /* K: number of clean segments */ 15751850Sbostic u_long dirty; /* K: number of dirty segments */ 15851850Sbostic } CLEANERINFO; 15951139Sbostic 16051850Sbostic #define CLEANSIZE_SU(fs) \ 16151850Sbostic ((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift) 16251140Sbostic 16351140Sbostic /* 16451140Sbostic * All summary blocks are the same size, so we can always read a summary 16551303Sbostic * block easily from a segment. 16651140Sbostic */ 16751140Sbostic #define LFS_SUMMARY_SIZE 512 16851140Sbostic 16951139Sbostic /* On-disk segment summary information */ 17051183Sbostic typedef struct segsum SEGSUM; 17151183Sbostic struct segsum { 17251850Sbostic u_long ss_sumsum; /* check sum of summary block */ 17351850Sbostic u_long ss_datasum; /* check sum of data */ 17451139Sbostic daddr_t ss_next; /* next segment */ 17551139Sbostic u_long ss_create; /* creation time stamp */ 17654264Sbostic u_short ss_nfinfo; /* number of file info structures */ 17754264Sbostic u_short ss_ninos; /* number of inodes in summary */ 17854264Sbostic #define SS_DIROP 0x01 /* segment begins a dirop */ 17954264Sbostic #define SS_CONT 0x02 /* more partials to finish this write*/ 18054264Sbostic u_short ss_flags; /* used for directory operations */ 18154264Sbostic u_short ss_pad; /* extra space */ 18252993Sbostic /* FINFO's and inode daddr's... */ 18351183Sbostic }; 18451139Sbostic 18551155Sbostic /* NINDIR is the number of indirects in a file system block. */ 18651155Sbostic #define NINDIR(fs) ((fs)->lfs_nindir) 18751155Sbostic 18851155Sbostic /* INOPB is the number of inodes in a secondary storage block. */ 18951155Sbostic #define INOPB(fs) ((fs)->lfs_inopb) 19051155Sbostic 19151155Sbostic #define blksize(fs) ((fs)->lfs_bsize) 19251155Sbostic #define blkoff(fs, loc) ((loc) & (fs)->lfs_bmask) 19351155Sbostic #define fsbtodb(fs, b) ((b) << (fs)->lfs_fsbtodb) 19451155Sbostic #define lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift) 19551155Sbostic #define lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift) 19651183Sbostic #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ 19751183Sbostic ((loc) >> (fs)->lfs_bshift) 19851350Sbostic 19952079Sbostic #define datosn(fs, daddr) /* disk address to segment number */ \ 20052079Sbostic (((daddr) - (fs)->lfs_sboffs[0]) / fsbtodb((fs), (fs)->lfs_ssize)) 20152079Sbostic #define sntoda(fs, sn) /* segment number to disk address */ \ 20252079Sbostic ((daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) + \ 20352079Sbostic (fs)->lfs_sboffs[0])) 20452079Sbostic 20551925Sbostic /* Read in the block with the cleaner info from the ifile. */ 20651925Sbostic #define LFS_CLEANERINFO(CP, F, BP) { \ 20752079Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 20851936Sbostic if (bread((F)->lfs_ivnode, (daddr_t)0, (F)->lfs_bsize, NOCRED, &(BP))) \ 20951925Sbostic panic("lfs: ifile read"); \ 21051936Sbostic (CP) = (CLEANERINFO *)(BP)->b_un.b_addr; \ 21151925Sbostic } 21251925Sbostic 21351850Sbostic /* Read in the block with a specific inode from the ifile. */ 21451925Sbostic #define LFS_IENTRY(IP, F, IN, BP) { \ 21551936Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 21651850Sbostic if (bread((F)->lfs_ivnode, \ 21751850Sbostic (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz, \ 21851936Sbostic (F)->lfs_bsize, NOCRED, &(BP))) \ 21951481Sbostic panic("lfs: ifile read"); \ 22051936Sbostic (IP) = (IFILE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_ifpb; \ 22151481Sbostic } 22251481Sbostic 22351850Sbostic /* Read in the block with a specific segment usage entry from the ifile. */ 22451925Sbostic #define LFS_SEGENTRY(SP, F, IN, BP) { \ 22551936Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 22651850Sbostic if (bread((F)->lfs_ivnode, (IN) / (F)->lfs_sepb + (F)->lfs_cleansz, \ 22751936Sbostic (F)->lfs_bsize, NOCRED, &(BP))) \ 22851850Sbostic panic("lfs: ifile read"); \ 22951936Sbostic (SP) = (SEGUSE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_sepb; \ 23051850Sbostic } 23151850Sbostic 23252079Sbostic /* Write a block and update the inode change times. */ 23352079Sbostic #define LFS_UBWRITE(BP) { \ 23452079Sbostic VTOI((BP)->b_vp)->i_flag |= ICHG | IUPD; \ 23553499Sheideman VOP_BWRITE(BP); \ 23651936Sbostic } 23751936Sbostic 23851850Sbostic /* 23951850Sbostic * Structures used by lfs_bmapv and lfs_markv to communicate information 24051850Sbostic * about inodes and data blocks. 24151850Sbostic */ 24251850Sbostic typedef struct block_info { 24351850Sbostic ino_t bi_inode; /* inode # */ 24451850Sbostic off_t bi_lbn; /* logical block w/in file */ 24551850Sbostic daddr_t bi_daddr; /* disk address of block */ 24651850Sbostic time_t bi_segcreate; /* origin segment create time */ 24751850Sbostic void *bi_bp; /* data buffer */ 24851850Sbostic } BLOCK_INFO; 24951850Sbostic 25051850Sbostic typedef struct inode_info { 25151850Sbostic ino_t ii_inode; /* inode # */ 25251850Sbostic daddr_t ii_daddr; /* disk address of block */ 25351850Sbostic time_t ii_segcreate; /* origin segment create time */ 25451850Sbostic struct dinode *ii_dinode; /* data buffer */ 25551850Sbostic } INODE_INFO; 256