151139Sbostic /*- 251139Sbostic * Copyright (c) 1991 The Regents of the University of California. 351139Sbostic * All rights reserved. 451139Sbostic * 551139Sbostic * %sccs.include.redist.c% 651139Sbostic * 7*51912Sbostic * @(#)lfs.h 7.4 (Berkeley) 12/13/91 851139Sbostic */ 951139Sbostic 1051183Sbostic typedef struct buf BUF; 1151183Sbostic typedef struct dinode DINODE; 1251183Sbostic typedef struct inode INODE; 1351183Sbostic typedef struct mount MOUNT; 1451183Sbostic typedef struct ucred UCRED; 1551183Sbostic typedef struct ufsmount UFSMOUNT; 1651183Sbostic typedef struct vnode VNODE; 1751183Sbostic 1851140Sbostic #define LFS_LABELPAD 8192 /* LFS label size */ 1951140Sbostic #define LFS_SBPAD 8192 /* LFS superblock size */ 2051140Sbostic #define MAXMNTLEN 512 /* XXX move from fs.h to mount.h */ 2151139Sbostic 2251155Sbostic /* On-disk and in-memory checkpoint segment usage structure. */ 2351183Sbostic typedef struct segusage SEGUSE; 2451183Sbostic struct segusage { 2551155Sbostic u_long su_nbytes; /* number of live bytes */ 2651350Sbostic u_long su_lastmod; /* SEGUSE last modified timestamp */ 27*51912Sbostic #define SEGUSE_ACTIVE 0x1 /* segment is currently being written */ 28*51912Sbostic #define SEGUSE_DIRTY 0x2 /* segment has data in it */ 29*51912Sbostic #define SEGUSE_SUPERBLOCK 0x4 /* segment contains a superblock */ 3051155Sbostic u_long su_flags; 3151183Sbostic }; 3251155Sbostic 3351850Sbostic #define SEGTABSIZE_SU(fs) \ 3451850Sbostic (((fs)->lfs_nseg * sizeof(SEGUSE) + \ 3551850Sbostic ((fs)->lfs_bsize - 1)) >> (fs)->lfs_bshift) 3651850Sbostic 3751183Sbostic /* On-disk file information. One per file with data blocks in the segment. */ 3851183Sbostic typedef struct finfo FINFO; 3951183Sbostic struct finfo { 4051183Sbostic u_long fi_nblocks; /* number of blocks */ 4151183Sbostic u_long fi_version; /* version number */ 4251215Sbostic u_long fi_ino; /* inode number */ 4351183Sbostic long fi_blocks[1]; /* array of logical block numbers */ 4451183Sbostic }; 4551183Sbostic 4651155Sbostic /* On-disk and in-memory super block. */ 4751183Sbostic struct lfs { 4851155Sbostic #define LFS_MAGIC 0xbedead 4951139Sbostic u_long lfs_magic; /* magic number */ 5051140Sbostic #define LFS_VERSION 1 5151139Sbostic u_long lfs_version; /* version number */ 5251139Sbostic 5351139Sbostic u_long lfs_size; /* number of blocks in fs */ 5451139Sbostic u_long lfs_ssize; /* number of blocks per segment */ 5551139Sbostic u_long lfs_dsize; /* number of data blocks in fs */ 5651139Sbostic u_long lfs_bsize; /* size of basic blocks in fs */ 5751139Sbostic u_long lfs_fsize; /* size of frag blocks in fs */ 5851139Sbostic u_long lfs_frag; /* number of frags in a block in fs */ 5951139Sbostic 6051139Sbostic /* Checkpoint region. */ 6151139Sbostic ino_t lfs_free; /* start of the free list */ 6251155Sbostic u_long lfs_bfree; /* number of free blocks */ 6351155Sbostic u_long lfs_nfiles; /* number of allocated inodes */ 6451139Sbostic daddr_t lfs_idaddr; /* inode file disk address */ 6551139Sbostic ino_t lfs_ifile; /* inode file inode number */ 6651303Sbostic daddr_t lfs_lastseg; /* address of last segment written */ 6751303Sbostic daddr_t lfs_nextseg; /* address of next segment to write */ 68*51912Sbostic daddr_t lfs_curseg; /* current segment being written */ 6951850Sbostic daddr_t lfs_offset; /* offset in curseg for next partial */ 7051139Sbostic u_long lfs_tstamp; /* time stamp */ 7151139Sbostic 7251139Sbostic /* These are configuration parameters. */ 7351139Sbostic u_long lfs_minfree; /* minimum percentage of free blocks */ 7451139Sbostic 7551139Sbostic /* These fields can be computed from the others. */ 7651850Sbostic u_long lfs_dbpseg; /* disk blocks per segment */ 7751139Sbostic u_long lfs_inopb; /* inodes per block */ 7851139Sbostic u_long lfs_ifpb; /* IFILE entries per block */ 7951850Sbostic u_long lfs_sepb; /* SEGUSE entries per block */ 8051139Sbostic u_long lfs_nindir; /* indirect pointers per block */ 8151139Sbostic u_long lfs_nseg; /* number of segments */ 8251139Sbostic u_long lfs_nspf; /* number of sectors per fragment */ 8351850Sbostic u_long lfs_cleansz; /* cleaner info size in blocks */ 8451139Sbostic u_long lfs_segtabsz; /* segment table size in blocks */ 8551139Sbostic 8651139Sbostic u_long lfs_segmask; /* calculate offset within a segment */ 8751139Sbostic u_long lfs_segshift; /* fast mult/div for segments */ 8851139Sbostic u_long lfs_bmask; /* calc block offset from file offset */ 8951139Sbostic u_long lfs_bshift; /* calc block number from file offset */ 9051139Sbostic u_long lfs_ffmask; /* calc frag offset from file offset */ 9151139Sbostic u_long lfs_ffshift; /* fast mult/div for frag from file */ 9251139Sbostic u_long lfs_fbmask; /* calc frag offset from block offset */ 9351139Sbostic u_long lfs_fbshift; /* fast mult/div for frag from block */ 9451139Sbostic u_long lfs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 9551139Sbostic 9651155Sbostic #define LFS_MIN_SBINTERVAL 5 /* minimum superblock segment spacing */ 9751155Sbostic #define LFS_MAXNUMSB 10 /* superblock disk offsets */ 9851155Sbostic daddr_t lfs_sboffs[LFS_MAXNUMSB]; 9951139Sbostic 10051155Sbostic /* These fields are set at mount time and are meaningless on disk. */ 10151183Sbostic VNODE *lfs_ivnode; /* vnode for the ifile */ 10251155Sbostic SEGUSE *lfs_segtab; /* in-memory segment usage table */ 10351850Sbostic /* XXX NOT USED */ 10451850Sbostic void *XXXlfs_seglist; /* list of segments being written */ 10551303Sbostic u_long lfs_iocount; /* number of ios pending */ 10651155Sbostic u_char lfs_fmod; /* super block modified flag */ 10751155Sbostic u_char lfs_clean; /* file system is clean flag */ 10851155Sbostic u_char lfs_ronly; /* mounted read-only flag */ 10951155Sbostic u_char lfs_flags; /* currently unused flag */ 11051155Sbostic u_char lfs_fsmnt[MAXMNTLEN]; /* name mounted on */ 11151155Sbostic u_char pad[3]; /* long-align */ 11251139Sbostic 11351155Sbostic /* Checksum; valid on disk. */ 11451155Sbostic u_long lfs_cksum; /* checksum for superblock checking */ 11551183Sbostic }; 11651139Sbostic 11751155Sbostic /* 11851539Sbostic * Inode 0 is the out-of-band inode, and inode 1 is the inode number for the 11951539Sbostic * ifile. Thus the root inode is 2, and the lost+found inode is 3. 12051155Sbostic */ 12151155Sbostic #define LOSTFOUNDINO ((ino_t)3) 12251139Sbostic 12351140Sbostic /* Fixed inode numbers. */ 12451303Sbostic #define LFS_UNUSED_INUM 0 /* out of band inode number */ 12551303Sbostic #define LFS_IFILE_INUM 1 /* inode number of the ifile */ 12651303Sbostic /* first free inode number */ 12751155Sbostic #define LFS_FIRST_INUM (LOSTFOUNDINO + 1) 12851139Sbostic 12951155Sbostic /* 13051140Sbostic * Used to access the first spare of the dinode which we use to store 13151140Sbostic * the ifile number so we can identify them 13251140Sbostic */ 13351140Sbostic #define di_inum di_spare[0] 13451140Sbostic 13551850Sbostic /* Address calculations for metadata located in the inode */ 13651850Sbostic #define S_INDIR(fs) -NDADDR 13751850Sbostic #define D_INDIR(fs) (S_INDIR - NINDIR(fs) - 1) 13851850Sbostic #define T_INDIR(fs) (D_INDIR - NINDIR(fs) * NINDIR(fs) - 1) 13951183Sbostic 14051850Sbostic /* Structure used to pass around logical block paths. */ 14151850Sbostic typedef struct _indir { 14251850Sbostic long in_lbn; /* logical block number */ 14351850Sbostic int in_off; /* offset in buffer */ 14451850Sbostic } INDIR; 14551850Sbostic 14651350Sbostic /* Unassigned disk address. */ 14751350Sbostic #define UNASSIGNED -1 14851350Sbostic 14951183Sbostic typedef struct ifile IFILE; 15051183Sbostic struct ifile { 15151139Sbostic u_long if_version; /* inode version number */ 15251155Sbostic #define LFS_UNUSED_DADDR 0 /* out-of-band daddr */ 15351139Sbostic daddr_t if_daddr; /* inode disk address */ 15451139Sbostic union { 15551139Sbostic ino_t nextfree; /* next-unallocated inode */ 15651139Sbostic time_t st_atime; /* access time */ 15751139Sbostic } __ifile_u; 15851140Sbostic #define if_st_atime __ifile_u.st_atime 15951140Sbostic #define if_nextfree __ifile_u.nextfree 16051183Sbostic }; 16151139Sbostic 16251850Sbostic /* 16351850Sbostic * Cleaner information structure. This resides in the ifile and is used 16451850Sbostic * to pass information between the cleaner and the kernel. 16551850Sbostic */ 16651850Sbostic typedef struct _cleanerinfo { 16751850Sbostic u_long clean; /* K: number of clean segments */ 16851850Sbostic u_long dirty; /* K: number of dirty segments */ 16951850Sbostic u_long last_seg; /* K: index of last seg written */ 17051850Sbostic time_t last_time; /* K: timestamp of last seg written */ 17151850Sbostic } CLEANERINFO; 17251139Sbostic 17351850Sbostic #define CLEANSIZE_SU(fs) \ 17451850Sbostic ((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift) 17551140Sbostic 17651140Sbostic /* 17751140Sbostic * All summary blocks are the same size, so we can always read a summary 17851303Sbostic * block easily from a segment. 17951140Sbostic */ 18051140Sbostic #define LFS_SUMMARY_SIZE 512 18151140Sbostic 18251139Sbostic /* On-disk segment summary information */ 18351183Sbostic typedef struct segsum SEGSUM; 18451183Sbostic struct segsum { 18551850Sbostic u_long ss_sumsum; /* check sum of summary block */ 18651850Sbostic u_long ss_datasum; /* check sum of data */ 18751139Sbostic daddr_t ss_next; /* next segment */ 18851139Sbostic u_long ss_create; /* creation time stamp */ 18951139Sbostic u_long ss_nfinfo; /* number of file info structures */ 19051850Sbostic u_long ss_ninos; /* number of inodes in summary */ 19151155Sbostic /* FINFO's... */ 19251183Sbostic }; 19351139Sbostic 19451155Sbostic /* NINDIR is the number of indirects in a file system block. */ 19551155Sbostic #define NINDIR(fs) ((fs)->lfs_nindir) 19651155Sbostic 19751155Sbostic /* INOPB is the number of inodes in a secondary storage block. */ 19851155Sbostic #define INOPB(fs) ((fs)->lfs_inopb) 19951155Sbostic 20051155Sbostic #define blksize(fs) ((fs)->lfs_bsize) 20151155Sbostic #define blkoff(fs, loc) ((loc) & (fs)->lfs_bmask) 20251155Sbostic #define fsbtodb(fs, b) ((b) << (fs)->lfs_fsbtodb) 20351155Sbostic #define lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift) 20451155Sbostic #define lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift) 20551183Sbostic #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ 20651183Sbostic ((loc) >> (fs)->lfs_bshift) 20751350Sbostic 20851850Sbostic /* Read in the block with a specific inode from the ifile. */ 20951481Sbostic #define LFS_IENTRY(I, F, IN, BP) { \ 21051850Sbostic if (bread((F)->lfs_ivnode, \ 21151850Sbostic (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz, \ 21251481Sbostic (F)->lfs_bsize, NOCRED, &BP)) \ 21351481Sbostic panic("lfs: ifile read"); \ 21451850Sbostic (I) = (IFILE *)BP->b_un.b_addr + IN % (F)->lfs_ifpb; \ 21551481Sbostic } 21651481Sbostic 21751850Sbostic /* Read in the block with a specific segment usage entry from the ifile. */ 21851850Sbostic #define LFS_SEGENTRY(I, F, IN, BP) { \ 21951850Sbostic if (bread((F)->lfs_ivnode, (IN) / (F)->lfs_sepb + (F)->lfs_cleansz, \ 22051850Sbostic (F)->lfs_bsize, NOCRED, &BP)) \ 22151850Sbostic panic("lfs: ifile read"); \ 22251850Sbostic (I) = (SEGUSE *)BP->b_un.b_addr + IN % (F)->lfs_sepb; \ 22351850Sbostic } 22451850Sbostic 22551850Sbostic /* 22651850Sbostic * Structures used by lfs_bmapv and lfs_markv to communicate information 22751850Sbostic * about inodes and data blocks. 22851850Sbostic */ 22951850Sbostic typedef struct block_info { 23051850Sbostic ino_t bi_inode; /* inode # */ 23151850Sbostic off_t bi_lbn; /* logical block w/in file */ 23251850Sbostic daddr_t bi_daddr; /* disk address of block */ 23351850Sbostic time_t bi_segcreate; /* origin segment create time */ 23451850Sbostic void *bi_bp; /* data buffer */ 23551850Sbostic } BLOCK_INFO; 23651850Sbostic 23751850Sbostic typedef struct inode_info { 23851850Sbostic ino_t ii_inode; /* inode # */ 23951850Sbostic daddr_t ii_daddr; /* disk address of block */ 24051850Sbostic time_t ii_segcreate; /* origin segment create time */ 24151850Sbostic struct dinode *ii_dinode; /* data buffer */ 24251850Sbostic } INODE_INFO; 243