151139Sbostic /*- 251139Sbostic * Copyright (c) 1991 The Regents of the University of California. 351139Sbostic * All rights reserved. 451139Sbostic * 551139Sbostic * %sccs.include.redist.c% 651139Sbostic * 7*54685Sbostic * @(#)lfs.h 7.15 (Berkeley) 07/05/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. */ 6951850Sbostic u_long lfs_dbpseg; /* disk blocks per segment */ 7051139Sbostic u_long lfs_inopb; /* inodes per block */ 7151139Sbostic u_long lfs_ifpb; /* IFILE entries per block */ 7251850Sbostic u_long lfs_sepb; /* SEGUSE entries per block */ 7351139Sbostic u_long lfs_nindir; /* indirect pointers per block */ 7451139Sbostic u_long lfs_nseg; /* number of segments */ 7551139Sbostic u_long lfs_nspf; /* number of sectors per fragment */ 7651850Sbostic u_long lfs_cleansz; /* cleaner info size in blocks */ 7751139Sbostic u_long lfs_segtabsz; /* segment table size in blocks */ 7851139Sbostic 7951139Sbostic u_long lfs_segmask; /* calculate offset within a segment */ 8051139Sbostic u_long lfs_segshift; /* fast mult/div for segments */ 8151139Sbostic u_long lfs_bmask; /* calc block offset from file offset */ 8251139Sbostic u_long lfs_bshift; /* calc block number from file offset */ 8351139Sbostic u_long lfs_ffmask; /* calc frag offset from file offset */ 8451139Sbostic u_long lfs_ffshift; /* fast mult/div for frag from file */ 8551139Sbostic u_long lfs_fbmask; /* calc frag offset from block offset */ 8651139Sbostic u_long lfs_fbshift; /* fast mult/div for frag from block */ 8751139Sbostic u_long lfs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 8851139Sbostic 8951155Sbostic #define LFS_MIN_SBINTERVAL 5 /* minimum superblock segment spacing */ 9051155Sbostic #define LFS_MAXNUMSB 10 /* superblock disk offsets */ 9151155Sbostic daddr_t lfs_sboffs[LFS_MAXNUMSB]; 9251139Sbostic 9351155Sbostic /* These fields are set at mount time and are meaningless on disk. */ 9453146Sbostic struct vnode *lfs_ivnode; /* vnode for the ifile */ 95*54685Sbostic u_long lfs_seglock; /* single-thread the segment writer */ 9651303Sbostic u_long lfs_iocount; /* number of ios pending */ 9754264Sbostic u_long lfs_writer; /* don't allow any dirops to start */ 9854264Sbostic u_long lfs_dirops; /* count of active directory ops */ 9954264Sbostic u_long lfs_doifile; /* Write ifile blocks on next write */ 10051155Sbostic u_char lfs_fmod; /* super block modified flag */ 10151155Sbostic u_char lfs_clean; /* file system is clean flag */ 10251155Sbostic u_char lfs_ronly; /* mounted read-only flag */ 10351155Sbostic u_char lfs_flags; /* currently unused flag */ 104*54685Sbostic u_char lfs_fsmnt[MNAMELEN]; /* name mounted on */ 10551155Sbostic u_char pad[3]; /* long-align */ 10651139Sbostic 10751155Sbostic /* Checksum; valid on disk. */ 10851155Sbostic u_long lfs_cksum; /* checksum for superblock checking */ 10951183Sbostic }; 11051139Sbostic 11151155Sbostic /* 11252079Sbostic * Inode 0 is the out-of-band inode number, inode 1 is the inode number for 11352079Sbostic * the IFILE, the root inode is 2 and the lost+found inode is 3. 11451155Sbostic */ 11551139Sbostic 11651140Sbostic /* Fixed inode numbers. */ 11751303Sbostic #define LFS_UNUSED_INUM 0 /* out of band inode number */ 11852079Sbostic #define LFS_IFILE_INUM 1 /* IFILE inode number */ 11952079Sbostic #define LOSTFOUNDINO 3 /* lost+found inode number */ 12052079Sbostic #define LFS_FIRST_INUM 4 /* first free inode number */ 12151139Sbostic 12251155Sbostic /* 12351140Sbostic * Used to access the first spare of the dinode which we use to store 12451140Sbostic * the ifile number so we can identify them 12551140Sbostic */ 12651140Sbostic #define di_inum di_spare[0] 12751140Sbostic 12851850Sbostic /* Address calculations for metadata located in the inode */ 12951850Sbostic #define S_INDIR(fs) -NDADDR 13052997Sstaelin #define D_INDIR(fs) (S_INDIR(fs) - NINDIR(fs) - 1) 13152997Sstaelin #define T_INDIR(fs) (D_INDIR(fs) - NINDIR(fs) * NINDIR(fs) - 1) 13251183Sbostic 13351850Sbostic /* Structure used to pass around logical block paths. */ 13451850Sbostic typedef struct _indir { 13551850Sbostic long in_lbn; /* logical block number */ 13651850Sbostic int in_off; /* offset in buffer */ 13751850Sbostic } INDIR; 13851850Sbostic 13951350Sbostic /* Unassigned disk address. */ 14051350Sbostic #define UNASSIGNED -1 14151350Sbostic 14251183Sbostic typedef struct ifile IFILE; 14351183Sbostic struct ifile { 14451139Sbostic u_long if_version; /* inode version number */ 14551155Sbostic #define LFS_UNUSED_DADDR 0 /* out-of-band daddr */ 14651139Sbostic daddr_t if_daddr; /* inode disk address */ 14752079Sbostic ino_t if_nextfree; /* next-unallocated inode */ 14851183Sbostic }; 14951139Sbostic 15051850Sbostic /* 15151850Sbostic * Cleaner information structure. This resides in the ifile and is used 15251850Sbostic * to pass information between the cleaner and the kernel. 15351850Sbostic */ 15451850Sbostic typedef struct _cleanerinfo { 15551850Sbostic u_long clean; /* K: number of clean segments */ 15651850Sbostic u_long dirty; /* K: number of dirty segments */ 15751850Sbostic } CLEANERINFO; 15851139Sbostic 15951850Sbostic #define CLEANSIZE_SU(fs) \ 16051850Sbostic ((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift) 16151140Sbostic 16251140Sbostic /* 16351140Sbostic * All summary blocks are the same size, so we can always read a summary 16451303Sbostic * block easily from a segment. 16551140Sbostic */ 16651140Sbostic #define LFS_SUMMARY_SIZE 512 16751140Sbostic 16851139Sbostic /* On-disk segment summary information */ 16951183Sbostic typedef struct segsum SEGSUM; 17051183Sbostic struct segsum { 17151850Sbostic u_long ss_sumsum; /* check sum of summary block */ 17251850Sbostic u_long ss_datasum; /* check sum of data */ 17351139Sbostic daddr_t ss_next; /* next segment */ 17451139Sbostic u_long ss_create; /* creation time stamp */ 17554264Sbostic u_short ss_nfinfo; /* number of file info structures */ 17654264Sbostic u_short ss_ninos; /* number of inodes in summary */ 17754264Sbostic #define SS_DIROP 0x01 /* segment begins a dirop */ 17854264Sbostic #define SS_CONT 0x02 /* more partials to finish this write*/ 17954264Sbostic u_short ss_flags; /* used for directory operations */ 18054264Sbostic u_short ss_pad; /* extra space */ 18152993Sbostic /* FINFO's and inode daddr's... */ 18251183Sbostic }; 18351139Sbostic 18451155Sbostic /* NINDIR is the number of indirects in a file system block. */ 18551155Sbostic #define NINDIR(fs) ((fs)->lfs_nindir) 18651155Sbostic 18751155Sbostic /* INOPB is the number of inodes in a secondary storage block. */ 18851155Sbostic #define INOPB(fs) ((fs)->lfs_inopb) 18951155Sbostic 19051155Sbostic #define blksize(fs) ((fs)->lfs_bsize) 19151155Sbostic #define blkoff(fs, loc) ((loc) & (fs)->lfs_bmask) 19251155Sbostic #define fsbtodb(fs, b) ((b) << (fs)->lfs_fsbtodb) 19351155Sbostic #define lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift) 19451155Sbostic #define lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift) 19551183Sbostic #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ 19651183Sbostic ((loc) >> (fs)->lfs_bshift) 19751350Sbostic 19852079Sbostic #define datosn(fs, daddr) /* disk address to segment number */ \ 19952079Sbostic (((daddr) - (fs)->lfs_sboffs[0]) / fsbtodb((fs), (fs)->lfs_ssize)) 20052079Sbostic #define sntoda(fs, sn) /* segment number to disk address */ \ 20152079Sbostic ((daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) + \ 20252079Sbostic (fs)->lfs_sboffs[0])) 20352079Sbostic 20451925Sbostic /* Read in the block with the cleaner info from the ifile. */ 20551925Sbostic #define LFS_CLEANERINFO(CP, F, BP) { \ 20652079Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 20751936Sbostic if (bread((F)->lfs_ivnode, (daddr_t)0, (F)->lfs_bsize, NOCRED, &(BP))) \ 20851925Sbostic panic("lfs: ifile read"); \ 20951936Sbostic (CP) = (CLEANERINFO *)(BP)->b_un.b_addr; \ 21051925Sbostic } 21151925Sbostic 21251850Sbostic /* Read in the block with a specific inode from the ifile. */ 21351925Sbostic #define LFS_IENTRY(IP, F, IN, BP) { \ 21451936Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 21551850Sbostic if (bread((F)->lfs_ivnode, \ 21651850Sbostic (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz, \ 21751936Sbostic (F)->lfs_bsize, NOCRED, &(BP))) \ 21851481Sbostic panic("lfs: ifile read"); \ 21951936Sbostic (IP) = (IFILE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_ifpb; \ 22051481Sbostic } 22151481Sbostic 22251850Sbostic /* Read in the block with a specific segment usage entry from the ifile. */ 22351925Sbostic #define LFS_SEGENTRY(SP, F, IN, BP) { \ 22451936Sbostic VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 22551850Sbostic if (bread((F)->lfs_ivnode, (IN) / (F)->lfs_sepb + (F)->lfs_cleansz, \ 22651936Sbostic (F)->lfs_bsize, NOCRED, &(BP))) \ 22751850Sbostic panic("lfs: ifile read"); \ 22851936Sbostic (SP) = (SEGUSE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_sepb; \ 22951850Sbostic } 23051850Sbostic 23152079Sbostic /* Write a block and update the inode change times. */ 23252079Sbostic #define LFS_UBWRITE(BP) { \ 23352079Sbostic VTOI((BP)->b_vp)->i_flag |= ICHG | IUPD; \ 23453499Sheideman VOP_BWRITE(BP); \ 23551936Sbostic } 23651936Sbostic 23751850Sbostic /* 23851850Sbostic * Structures used by lfs_bmapv and lfs_markv to communicate information 23951850Sbostic * about inodes and data blocks. 24051850Sbostic */ 24151850Sbostic typedef struct block_info { 24251850Sbostic ino_t bi_inode; /* inode # */ 24351850Sbostic off_t bi_lbn; /* logical block w/in file */ 24451850Sbostic daddr_t bi_daddr; /* disk address of block */ 24551850Sbostic time_t bi_segcreate; /* origin segment create time */ 24651850Sbostic void *bi_bp; /* data buffer */ 24751850Sbostic } BLOCK_INFO; 24851850Sbostic 24951850Sbostic typedef struct inode_info { 25051850Sbostic ino_t ii_inode; /* inode # */ 25151850Sbostic daddr_t ii_daddr; /* disk address of block */ 25251850Sbostic time_t ii_segcreate; /* origin segment create time */ 25351850Sbostic struct dinode *ii_dinode; /* data buffer */ 25451850Sbostic } INODE_INFO; 255