1 /*- 2 * Copyright (c) 1991 The Regents of the University of California. 3 * All rights reserved. 4 * 5 * %sccs.include.redist.c% 6 * 7 * @(#)lfs.h 7.13 (Berkeley) 05/14/92 8 */ 9 10 #define LFS_LABELPAD 8192 /* LFS label size */ 11 #define LFS_SBPAD 8192 /* LFS superblock size */ 12 #define MAXMNTLEN 512 /* XXX move from fs.h to mount.h */ 13 14 /* On-disk and in-memory checkpoint segment usage structure. */ 15 typedef struct segusage SEGUSE; 16 struct segusage { 17 u_long su_nbytes; /* number of live bytes */ 18 u_long su_lastmod; /* SEGUSE last modified timestamp */ 19 #define SEGUSE_ACTIVE 0x1 /* segment is currently being written */ 20 #define SEGUSE_DIRTY 0x2 /* segment has data in it */ 21 #define SEGUSE_SUPERBLOCK 0x4 /* segment contains a superblock */ 22 u_long su_flags; 23 }; 24 25 #define SEGTABSIZE_SU(fs) \ 26 (((fs)->lfs_nseg * sizeof(SEGUSE) + \ 27 ((fs)->lfs_bsize - 1)) >> (fs)->lfs_bshift) 28 29 /* On-disk file information. One per file with data blocks in the segment. */ 30 typedef struct finfo FINFO; 31 struct finfo { 32 u_long fi_nblocks; /* number of blocks */ 33 u_long fi_version; /* version number */ 34 u_long fi_ino; /* inode number */ 35 long fi_blocks[1]; /* array of logical block numbers */ 36 }; 37 38 /* On-disk and in-memory super block. */ 39 struct lfs { 40 #define LFS_MAGIC 0x070162 41 u_long lfs_magic; /* magic number */ 42 #define LFS_VERSION 1 43 u_long lfs_version; /* version number */ 44 45 u_long lfs_size; /* number of blocks in fs */ 46 u_long lfs_ssize; /* number of blocks per segment */ 47 u_long lfs_dsize; /* number of data blocks in fs */ 48 u_long lfs_bsize; /* size of basic blocks in fs */ 49 u_long lfs_fsize; /* size of frag blocks in fs */ 50 u_long lfs_frag; /* number of frags in a block in fs */ 51 52 /* Checkpoint region. */ 53 ino_t lfs_free; /* start of the free list */ 54 u_long lfs_bfree; /* number of free blocks */ 55 u_long lfs_nfiles; /* number of allocated inodes */ 56 daddr_t lfs_idaddr; /* inode file disk address */ 57 ino_t lfs_ifile; /* inode file inode number */ 58 daddr_t lfs_lastseg; /* address of last segment written */ 59 daddr_t lfs_nextseg; /* address of next segment to write */ 60 daddr_t lfs_curseg; /* current segment being written */ 61 daddr_t lfs_offset; /* offset in curseg for next partial */ 62 u_long lfs_tstamp; /* time stamp */ 63 64 /* These are configuration parameters. */ 65 u_long lfs_minfree; /* minimum percentage of free blocks */ 66 67 /* These fields can be computed from the others. */ 68 u_long lfs_dbpseg; /* disk blocks per segment */ 69 u_long lfs_inopb; /* inodes per block */ 70 u_long lfs_ifpb; /* IFILE entries per block */ 71 u_long lfs_sepb; /* SEGUSE entries per block */ 72 u_long lfs_nindir; /* indirect pointers per block */ 73 u_long lfs_nseg; /* number of segments */ 74 u_long lfs_nspf; /* number of sectors per fragment */ 75 u_long lfs_cleansz; /* cleaner info size in blocks */ 76 u_long lfs_segtabsz; /* segment table size in blocks */ 77 78 u_long lfs_segmask; /* calculate offset within a segment */ 79 u_long lfs_segshift; /* fast mult/div for segments */ 80 u_long lfs_bmask; /* calc block offset from file offset */ 81 u_long lfs_bshift; /* calc block number from file offset */ 82 u_long lfs_ffmask; /* calc frag offset from file offset */ 83 u_long lfs_ffshift; /* fast mult/div for frag from file */ 84 u_long lfs_fbmask; /* calc frag offset from block offset */ 85 u_long lfs_fbshift; /* fast mult/div for frag from block */ 86 u_long lfs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 87 88 #define LFS_MIN_SBINTERVAL 5 /* minimum superblock segment spacing */ 89 #define LFS_MAXNUMSB 10 /* superblock disk offsets */ 90 daddr_t lfs_sboffs[LFS_MAXNUMSB]; 91 92 /* These fields are set at mount time and are meaningless on disk. */ 93 struct vnode *lfs_ivnode; /* vnode for the ifile */ 94 SEGUSE *lfs_segtab; /* in-memory segment usage table */ 95 /* XXX NOT USED */ 96 void *XXXlfs_seglist; /* list of segments being written */ 97 u_long lfs_iocount; /* number of ios pending */ 98 u_char lfs_fmod; /* super block modified flag */ 99 u_char lfs_clean; /* file system is clean flag */ 100 u_char lfs_ronly; /* mounted read-only flag */ 101 u_char lfs_flags; /* currently unused flag */ 102 u_char lfs_fsmnt[MAXMNTLEN]; /* name mounted on */ 103 u_char pad[3]; /* long-align */ 104 105 /* Checksum; valid on disk. */ 106 u_long lfs_cksum; /* checksum for superblock checking */ 107 }; 108 109 /* 110 * Inode 0 is the out-of-band inode number, inode 1 is the inode number for 111 * the IFILE, the root inode is 2 and the lost+found inode is 3. 112 */ 113 114 /* Fixed inode numbers. */ 115 #define LFS_UNUSED_INUM 0 /* out of band inode number */ 116 #define LFS_IFILE_INUM 1 /* IFILE inode number */ 117 #define LOSTFOUNDINO 3 /* lost+found inode number */ 118 #define LFS_FIRST_INUM 4 /* first free inode number */ 119 120 /* 121 * Used to access the first spare of the dinode which we use to store 122 * the ifile number so we can identify them 123 */ 124 #define di_inum di_spare[0] 125 126 /* Address calculations for metadata located in the inode */ 127 #define S_INDIR(fs) -NDADDR 128 #define D_INDIR(fs) (S_INDIR(fs) - NINDIR(fs) - 1) 129 #define T_INDIR(fs) (D_INDIR(fs) - NINDIR(fs) * NINDIR(fs) - 1) 130 131 /* Structure used to pass around logical block paths. */ 132 typedef struct _indir { 133 long in_lbn; /* logical block number */ 134 int in_off; /* offset in buffer */ 135 } INDIR; 136 137 /* Unassigned disk address. */ 138 #define UNASSIGNED -1 139 140 typedef struct ifile IFILE; 141 struct ifile { 142 u_long if_version; /* inode version number */ 143 #define LFS_UNUSED_DADDR 0 /* out-of-band daddr */ 144 daddr_t if_daddr; /* inode disk address */ 145 ino_t if_nextfree; /* next-unallocated inode */ 146 }; 147 148 /* 149 * Cleaner information structure. This resides in the ifile and is used 150 * to pass information between the cleaner and the kernel. 151 */ 152 typedef struct _cleanerinfo { 153 u_long clean; /* K: number of clean segments */ 154 u_long dirty; /* K: number of dirty segments */ 155 } CLEANERINFO; 156 157 #define CLEANSIZE_SU(fs) \ 158 ((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift) 159 160 /* 161 * All summary blocks are the same size, so we can always read a summary 162 * block easily from a segment. 163 */ 164 #define LFS_SUMMARY_SIZE 512 165 166 /* On-disk segment summary information */ 167 typedef struct segsum SEGSUM; 168 struct segsum { 169 u_long ss_sumsum; /* check sum of summary block */ 170 u_long ss_datasum; /* check sum of data */ 171 daddr_t ss_next; /* next segment */ 172 u_long ss_create; /* creation time stamp */ 173 u_long ss_nfinfo; /* number of file info structures */ 174 u_long ss_ninos; /* number of inodes in summary */ 175 /* FINFO's and inode daddr's... */ 176 }; 177 178 /* NINDIR is the number of indirects in a file system block. */ 179 #define NINDIR(fs) ((fs)->lfs_nindir) 180 181 /* INOPB is the number of inodes in a secondary storage block. */ 182 #define INOPB(fs) ((fs)->lfs_inopb) 183 184 #define blksize(fs) ((fs)->lfs_bsize) 185 #define blkoff(fs, loc) ((loc) & (fs)->lfs_bmask) 186 #define fsbtodb(fs, b) ((b) << (fs)->lfs_fsbtodb) 187 #define lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift) 188 #define lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift) 189 #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ 190 ((loc) >> (fs)->lfs_bshift) 191 192 #define datosn(fs, daddr) /* disk address to segment number */ \ 193 (((daddr) - (fs)->lfs_sboffs[0]) / fsbtodb((fs), (fs)->lfs_ssize)) 194 #define sntoda(fs, sn) /* segment number to disk address */ \ 195 ((daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) + \ 196 (fs)->lfs_sboffs[0])) 197 198 /* Read in the block with the cleaner info from the ifile. */ 199 #define LFS_CLEANERINFO(CP, F, BP) { \ 200 VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 201 if (bread((F)->lfs_ivnode, (daddr_t)0, (F)->lfs_bsize, NOCRED, &(BP))) \ 202 panic("lfs: ifile read"); \ 203 (CP) = (CLEANERINFO *)(BP)->b_un.b_addr; \ 204 } 205 206 /* Read in the block with a specific inode from the ifile. */ 207 #define LFS_IENTRY(IP, F, IN, BP) { \ 208 VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 209 if (bread((F)->lfs_ivnode, \ 210 (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz, \ 211 (F)->lfs_bsize, NOCRED, &(BP))) \ 212 panic("lfs: ifile read"); \ 213 (IP) = (IFILE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_ifpb; \ 214 } 215 216 /* Read in the block with a specific segment usage entry from the ifile. */ 217 #define LFS_SEGENTRY(SP, F, IN, BP) { \ 218 VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 219 if (bread((F)->lfs_ivnode, (IN) / (F)->lfs_sepb + (F)->lfs_cleansz, \ 220 (F)->lfs_bsize, NOCRED, &(BP))) \ 221 panic("lfs: ifile read"); \ 222 (SP) = (SEGUSE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_sepb; \ 223 } 224 225 /* Write a block and update the inode change times. */ 226 #define LFS_UBWRITE(BP) { \ 227 USES_VOP_BWRITE; \ 228 VTOI((BP)->b_vp)->i_flag |= ICHG | IUPD; \ 229 VOP_BWRITE(BP); \ 230 } 231 232 /* 233 * Structures used by lfs_bmapv and lfs_markv to communicate information 234 * about inodes and data blocks. 235 */ 236 typedef struct block_info { 237 ino_t bi_inode; /* inode # */ 238 off_t bi_lbn; /* logical block w/in file */ 239 daddr_t bi_daddr; /* disk address of block */ 240 time_t bi_segcreate; /* origin segment create time */ 241 void *bi_bp; /* data buffer */ 242 } BLOCK_INFO; 243 244 typedef struct inode_info { 245 ino_t ii_inode; /* inode # */ 246 daddr_t ii_daddr; /* disk address of block */ 247 time_t ii_segcreate; /* origin segment create time */ 248 struct dinode *ii_dinode; /* data buffer */ 249 } INODE_INFO; 250