151139Sbostic /*- 251139Sbostic * Copyright (c) 1991 The Regents of the University of California. 351139Sbostic * All rights reserved. 451139Sbostic * 551139Sbostic * %sccs.include.redist.c% 651139Sbostic * 7*51539Sbostic * @(#)lfs.h 7.2 (Berkeley) 11/05/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 */ 2751183Sbostic #define SEGUSE_DIRTY 0x1 /* XXX fill in comment */ 2851155Sbostic u_long su_flags; 2951183Sbostic }; 3051155Sbostic 3151183Sbostic /* On-disk file information. One per file with data blocks in the segment. */ 3251183Sbostic typedef struct finfo FINFO; 3351183Sbostic struct finfo { 3451183Sbostic u_long fi_nblocks; /* number of blocks */ 3551183Sbostic u_long fi_version; /* version number */ 3651215Sbostic u_long fi_ino; /* inode number */ 3751183Sbostic long fi_blocks[1]; /* array of logical block numbers */ 3851183Sbostic }; 3951183Sbostic 4051183Sbostic /* In-memory description of a segment about to be written */ 4151183Sbostic typedef struct segment SEGMENT; 4251183Sbostic struct segment { 4351303Sbostic SEGMENT *nextp; /* links segments together */ 4451303Sbostic BUF **bpp; /* pointer to buffer array */ 4551303Sbostic BUF **cbpp; /* pointer to next available bp */ 4651303Sbostic BUF *ibp; /* buffer pointer to inode page */ 4751303Sbostic BUF *sbp; /* segment summary buffer pointer */ 4851303Sbostic void *segsum; /* segment Summary info */ 4951303Sbostic u_long seg_bytes_left; /* bytes left in segment */ 5051350Sbostic u_long sum_bytes_left; /* bytes left in summary block */ 5151303Sbostic daddr_t saddr; /* current disk address */ 5251303Sbostic daddr_t sum_addr; /* address of current summary */ 5351303Sbostic u_long ninodes; /* number of inodes in this segment */ 5451350Sbostic u_long nsums; /* number of SEGSUMs in this segment */ 5551303Sbostic u_long seg_number; /* number of this segment */ 5651303Sbostic FINFO *fip; /* current fileinfo pointer */ 5751183Sbostic }; 5851183Sbostic 5951155Sbostic /* On-disk and in-memory super block. */ 6051183Sbostic struct lfs { 6151155Sbostic #define LFS_MAGIC 0xbedead 6251139Sbostic u_long lfs_magic; /* magic number */ 6351140Sbostic #define LFS_VERSION 1 6451139Sbostic u_long lfs_version; /* version number */ 6551139Sbostic 6651139Sbostic u_long lfs_size; /* number of blocks in fs */ 6751139Sbostic u_long lfs_ssize; /* number of blocks per segment */ 6851139Sbostic u_long lfs_dsize; /* number of data blocks in fs */ 6951139Sbostic u_long lfs_bsize; /* size of basic blocks in fs */ 7051139Sbostic u_long lfs_fsize; /* size of frag blocks in fs */ 7151139Sbostic u_long lfs_frag; /* number of frags in a block in fs */ 7251139Sbostic 7351139Sbostic /* Checkpoint region. */ 7451139Sbostic ino_t lfs_free; /* start of the free list */ 7551155Sbostic u_long lfs_bfree; /* number of free blocks */ 7651155Sbostic u_long lfs_nfiles; /* number of allocated inodes */ 7751139Sbostic daddr_t lfs_idaddr; /* inode file disk address */ 7851139Sbostic ino_t lfs_ifile; /* inode file inode number */ 7951303Sbostic daddr_t lfs_lastseg; /* address of last segment written */ 8051303Sbostic daddr_t lfs_nextseg; /* address of next segment to write */ 8151139Sbostic u_long lfs_tstamp; /* time stamp */ 8251139Sbostic 8351139Sbostic /* These are configuration parameters. */ 8451139Sbostic u_long lfs_minfree; /* minimum percentage of free blocks */ 8551139Sbostic 8651139Sbostic /* These fields can be computed from the others. */ 8751139Sbostic u_long lfs_inopb; /* inodes per block */ 8851139Sbostic u_long lfs_ifpb; /* IFILE entries per block */ 8951139Sbostic u_long lfs_nindir; /* indirect pointers per block */ 9051139Sbostic u_long lfs_nseg; /* number of segments */ 9151139Sbostic u_long lfs_nspf; /* number of sectors per fragment */ 9251139Sbostic u_long lfs_segtabsz; /* segment table size in blocks */ 9351139Sbostic 9451139Sbostic u_long lfs_segmask; /* calculate offset within a segment */ 9551139Sbostic u_long lfs_segshift; /* fast mult/div for segments */ 9651139Sbostic u_long lfs_bmask; /* calc block offset from file offset */ 9751139Sbostic u_long lfs_bshift; /* calc block number from file offset */ 9851139Sbostic u_long lfs_ffmask; /* calc frag offset from file offset */ 9951139Sbostic u_long lfs_ffshift; /* fast mult/div for frag from file */ 10051139Sbostic u_long lfs_fbmask; /* calc frag offset from block offset */ 10151139Sbostic u_long lfs_fbshift; /* fast mult/div for frag from block */ 10251139Sbostic u_long lfs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 10351139Sbostic 10451155Sbostic #define LFS_MIN_SBINTERVAL 5 /* minimum superblock segment spacing */ 10551155Sbostic #define LFS_MAXNUMSB 10 /* superblock disk offsets */ 10651155Sbostic daddr_t lfs_sboffs[LFS_MAXNUMSB]; 10751139Sbostic 10851155Sbostic /* These fields are set at mount time and are meaningless on disk. */ 10951183Sbostic VNODE *lfs_ivnode; /* vnode for the ifile */ 11051155Sbostic SEGUSE *lfs_segtab; /* in-memory segment usage table */ 11151183Sbostic SEGMENT *lfs_seglist; /* list of segments being written */ 11251303Sbostic u_long lfs_iocount; /* number of ios pending */ 11351155Sbostic u_char lfs_fmod; /* super block modified flag */ 11451155Sbostic u_char lfs_clean; /* file system is clean flag */ 11551155Sbostic u_char lfs_ronly; /* mounted read-only flag */ 11651155Sbostic u_char lfs_flags; /* currently unused flag */ 11751155Sbostic u_char lfs_fsmnt[MAXMNTLEN]; /* name mounted on */ 11851155Sbostic u_char pad[3]; /* long-align */ 11951139Sbostic 12051155Sbostic /* Checksum; valid on disk. */ 12151155Sbostic u_long lfs_cksum; /* checksum for superblock checking */ 12251183Sbostic }; 12351139Sbostic 12451155Sbostic /* 125*51539Sbostic * Inode 0 is the out-of-band inode, and inode 1 is the inode number for the 126*51539Sbostic * ifile. Thus the root inode is 2, and the lost+found inode is 3. 12751155Sbostic */ 12851155Sbostic #define LOSTFOUNDINO ((ino_t)3) 12951139Sbostic 13051140Sbostic /* Fixed inode numbers. */ 13151303Sbostic #define LFS_UNUSED_INUM 0 /* out of band inode number */ 13251303Sbostic #define LFS_IFILE_INUM 1 /* inode number of the ifile */ 13351303Sbostic /* first free inode number */ 13451155Sbostic #define LFS_FIRST_INUM (LOSTFOUNDINO + 1) 13551139Sbostic 13651155Sbostic /* 13751140Sbostic * Used to access the first spare of the dinode which we use to store 13851140Sbostic * the ifile number so we can identify them 13951140Sbostic */ 14051140Sbostic #define di_inum di_spare[0] 14151140Sbostic 14251350Sbostic /* Logical block numbers of indirect blocks. */ 14351183Sbostic #define S_INDIR -1 14451183Sbostic #define D_INDIR -2 14551183Sbostic #define T_INDIR -3 14651183Sbostic 14751350Sbostic /* Unassigned disk address. */ 14851350Sbostic #define UNASSIGNED -1 14951350Sbostic 15051183Sbostic typedef struct ifile IFILE; 15151183Sbostic struct ifile { 15251139Sbostic u_long if_version; /* inode version number */ 15351155Sbostic #define LFS_UNUSED_DADDR 0 /* out-of-band daddr */ 15451139Sbostic daddr_t if_daddr; /* inode disk address */ 15551139Sbostic union { 15651139Sbostic ino_t nextfree; /* next-unallocated inode */ 15751139Sbostic time_t st_atime; /* access time */ 15851139Sbostic } __ifile_u; 15951140Sbostic #define if_st_atime __ifile_u.st_atime 16051140Sbostic #define if_nextfree __ifile_u.nextfree 16151183Sbostic }; 16251139Sbostic 16351139Sbostic /* Segment table size, in blocks. */ 16451139Sbostic #define SEGTABSIZE(fs) \ 16551155Sbostic (((fs)->fs_nseg * sizeof(SEGUSE) + \ 16651155Sbostic ((fs)->fs_bsize - 1)) >> (fs)->fs_bshift) 16751139Sbostic 16851140Sbostic #define SEGTABSIZE_SU(fs) \ 16951155Sbostic (((fs)->lfs_nseg * sizeof(SEGUSE) + \ 17051140Sbostic ((fs)->lfs_bsize - 1)) >> (fs)->lfs_bshift) 17151140Sbostic 17251140Sbostic /* 17351140Sbostic * All summary blocks are the same size, so we can always read a summary 17451303Sbostic * block easily from a segment. 17551140Sbostic */ 17651140Sbostic #define LFS_SUMMARY_SIZE 512 17751140Sbostic 17851139Sbostic /* On-disk segment summary information */ 17951183Sbostic typedef struct segsum SEGSUM; 18051183Sbostic struct segsum { 18151155Sbostic u_long ss_cksum; /* check sum */ 18251139Sbostic daddr_t ss_next; /* next segment */ 18351139Sbostic daddr_t ss_prev; /* next segment */ 18451139Sbostic daddr_t ss_nextsum; /* next summary block */ 18551139Sbostic u_long ss_create; /* creation time stamp */ 18651139Sbostic u_long ss_nfinfo; /* number of file info structures */ 18751155Sbostic u_long ss_ninos; /* number of inode blocks */ 18851155Sbostic /* FINFO's... */ 18951183Sbostic }; 19051139Sbostic 19151155Sbostic /* NINDIR is the number of indirects in a file system block. */ 19251155Sbostic #define NINDIR(fs) ((fs)->lfs_nindir) 19351155Sbostic 19451155Sbostic /* INOPB is the number of inodes in a secondary storage block. */ 19551155Sbostic #define INOPB(fs) ((fs)->lfs_inopb) 19651155Sbostic 19751155Sbostic /* IFPB -- IFILE's per block */ 19851155Sbostic #define IFPB(fs) ((fs)->lfs_ifpb) 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 20851350Sbostic #define datosn(fs, daddr) /* disk address to segment number */ \ 20951350Sbostic (((daddr) - (fs)->lfs_sboffs[0]) / fsbtodb((fs), (fs)->lfs_ssize)) 21051350Sbostic #define sntoda(fs, sn) /* segment number to disk address */ \ 21151350Sbostic ((daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) + \ 21251350Sbostic (fs)->lfs_sboffs[0])) 21351481Sbostic 21451481Sbostic /* Read in the block containing a specific inode from the ifile. */ 21551481Sbostic #define LFS_IENTRY(I, F, IN, BP) { \ 21651481Sbostic if (bread((F)->lfs_ivnode, (IN) / IFPB(F) + (F)->lfs_segtabsz, \ 21751481Sbostic (F)->lfs_bsize, NOCRED, &BP)) \ 21851481Sbostic panic("lfs: ifile read"); \ 21951481Sbostic (I) = (IFILE *)BP->b_un.b_addr + IN % IFPB(F); \ 22051481Sbostic } 22151481Sbostic 222