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.26 (Berkeley) 10/08/92 8 */ 9 10 #define LFS_LABELPAD 8192 /* LFS label size */ 11 #define LFS_SBPAD 8192 /* LFS superblock size */ 12 13 /* 14 * XXX 15 * This is a kluge and NEEDS to go away. 16 * 17 * Right now, ufs code handles most of the calls for directory operations 18 * such as create, mkdir, link, etc. As a result VOP_UPDATE is being 19 * called with waitfor set (since ffs does these things synchronously). 20 * Since LFS does not want to do these synchronously, we treat the last 21 * argument to lfs_update as a set of flags. If LFS_SYNC is set, then 22 * the update should be synchronous, if not, do it asynchronously. 23 * Unfortunately, this means that LFS won't work with NFS yet because 24 * NFS goes through paths that will make normal calls to ufs which will 25 * call lfs with a last argument of 1. 26 */ 27 #define LFS_SYNC 0x02 28 29 /* On-disk and in-memory checkpoint segment usage structure. */ 30 typedef struct segusage SEGUSE; 31 struct segusage { 32 u_long su_nbytes; /* number of live bytes */ 33 u_long su_lastmod; /* SEGUSE last modified timestamp */ 34 u_short su_nsums; /* number of summaries in segment */ 35 u_short su_ninos; /* number of inode blocks in seg */ 36 #define SEGUSE_ACTIVE 0x1 /* segment is currently being written */ 37 #define SEGUSE_DIRTY 0x2 /* segment has data in it */ 38 #define SEGUSE_SUPERBLOCK 0x4 /* segment contains a superblock */ 39 u_long su_flags; 40 }; 41 42 #define SEGUPB(fs) (1 << (fs)->lfs_sushift) 43 #define SEGTABSIZE_SU(fs) \ 44 (((fs)->lfs_nseg + SEGUPB(fs) - 1) >> (fs)->lfs_sushift) 45 46 /* On-disk file information. One per file with data blocks in the segment. */ 47 typedef struct finfo FINFO; 48 struct finfo { 49 u_long fi_nblocks; /* number of blocks */ 50 u_long fi_version; /* version number */ 51 u_long fi_ino; /* inode number */ 52 long fi_blocks[1]; /* array of logical block numbers */ 53 }; 54 55 /* On-disk and in-memory super block. */ 56 struct lfs { 57 #define LFS_MAGIC 0x070162 58 u_long lfs_magic; /* magic number */ 59 #define LFS_VERSION 1 60 u_long lfs_version; /* version number */ 61 62 u_long lfs_size; /* number of blocks in fs */ 63 u_long lfs_ssize; /* number of blocks per segment */ 64 u_long lfs_dsize; /* number of disk blocks in fs */ 65 u_long lfs_bsize; /* file system block size */ 66 u_long lfs_fsize; /* size of frag blocks in fs */ 67 u_long lfs_frag; /* number of frags in a block in fs */ 68 69 /* Checkpoint region. */ 70 ino_t lfs_free; /* start of the free list */ 71 u_long lfs_bfree; /* number of free disk blocks */ 72 u_long lfs_nfiles; /* number of allocated inodes */ 73 long lfs_avail; /* blocks available for writing */ 74 u_long lfs_uinodes; /* inodes in cache not yet on disk */ 75 daddr_t lfs_idaddr; /* inode file disk address */ 76 ino_t lfs_ifile; /* inode file inode number */ 77 daddr_t lfs_lastseg; /* address of last segment written */ 78 daddr_t lfs_nextseg; /* address of next segment to write */ 79 daddr_t lfs_curseg; /* current segment being written */ 80 daddr_t lfs_offset; /* offset in curseg for next partial */ 81 daddr_t lfs_lastpseg; /* address of last partial written */ 82 u_long lfs_tstamp; /* time stamp */ 83 84 /* These are configuration parameters. */ 85 u_long lfs_minfree; /* minimum percentage of free blocks */ 86 87 /* These fields can be computed from the others. */ 88 u_quad_t lfs_maxfilesize; /* maximum representable file size */ 89 u_long lfs_dbpseg; /* disk blocks per segment */ 90 u_long lfs_inopb; /* inodes per block */ 91 u_long lfs_ifpb; /* IFILE entries per block */ 92 u_long lfs_sepb; /* SEGUSE entries per block */ 93 u_long lfs_nindir; /* indirect pointers per block */ 94 u_long lfs_nseg; /* number of segments */ 95 u_long lfs_nspf; /* number of sectors per fragment */ 96 u_long lfs_cleansz; /* cleaner info size in blocks */ 97 u_long lfs_segtabsz; /* segment table size in blocks */ 98 99 u_long lfs_segmask; /* calculate offset within a segment */ 100 u_long lfs_segshift; /* fast mult/div for segments */ 101 u_long lfs_bmask; /* calc block offset from file offset */ 102 u_long lfs_bshift; /* calc block number from file offset */ 103 u_long lfs_ffmask; /* calc frag offset from file offset */ 104 u_long lfs_ffshift; /* fast mult/div for frag from file */ 105 u_long lfs_fbmask; /* calc frag offset from block offset */ 106 u_long lfs_fbshift; /* fast mult/div for frag from block */ 107 u_long lfs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ 108 u_long lfs_sushift; /* fast mult/div for segusage table */ 109 110 #define LFS_MIN_SBINTERVAL 5 /* minimum superblock segment spacing */ 111 #define LFS_MAXNUMSB 10 /* superblock disk offsets */ 112 daddr_t lfs_sboffs[LFS_MAXNUMSB]; 113 114 /* These fields are set at mount time and are meaningless on disk. */ 115 struct vnode *lfs_ivnode; /* vnode for the ifile */ 116 u_long lfs_seglock; /* single-thread the segment writer */ 117 u_long lfs_iocount; /* number of ios pending */ 118 u_long lfs_writer; /* don't allow any dirops to start */ 119 u_long lfs_dirops; /* count of active directory ops */ 120 u_long lfs_doifile; /* Write ifile blocks on next write */ 121 u_long lfs_nactive; /* Number of segments since last ckp */ 122 u_char lfs_fmod; /* super block modified flag */ 123 u_char lfs_clean; /* file system is clean flag */ 124 u_char lfs_ronly; /* mounted read-only flag */ 125 u_char lfs_flags; /* currently unused flag */ 126 u_char lfs_fsmnt[MNAMELEN]; /* name mounted on */ 127 u_char pad[3]; /* long-align */ 128 129 /* Checksum; valid on disk. */ 130 u_long lfs_cksum; /* checksum for superblock checking */ 131 }; 132 133 /* 134 * Inode 0 is the out-of-band inode number, inode 1 is the inode number for 135 * the IFILE, the root inode is 2 and the lost+found inode is 3. 136 */ 137 138 /* Fixed inode numbers. */ 139 #define LFS_UNUSED_INUM 0 /* out of band inode number */ 140 #define LFS_IFILE_INUM 1 /* IFILE inode number */ 141 #define LOSTFOUNDINO 3 /* lost+found inode number */ 142 #define LFS_FIRST_INUM 4 /* first free inode number */ 143 144 /* 145 * Used to access the first spare of the dinode which we use to store 146 * the ifile number so we can identify them 147 */ 148 #define di_inum di_spare[0] 149 150 /* Address calculations for metadata located in the inode */ 151 #define S_INDIR(fs) -NDADDR 152 #define D_INDIR(fs) (S_INDIR(fs) - NINDIR(fs) - 1) 153 #define T_INDIR(fs) (D_INDIR(fs) - NINDIR(fs) * NINDIR(fs) - 1) 154 155 /* Unassigned disk address. */ 156 #define UNASSIGNED -1 157 158 /* Unused logical block number */ 159 #define LFS_UNUSED_LBN -1 160 161 typedef struct ifile IFILE; 162 struct ifile { 163 u_long if_version; /* inode version number */ 164 #define LFS_UNUSED_DADDR 0 /* out-of-band daddr */ 165 daddr_t if_daddr; /* inode disk address */ 166 ino_t if_nextfree; /* next-unallocated inode */ 167 }; 168 169 /* 170 * Cleaner information structure. This resides in the ifile and is used 171 * to pass information between the cleaner and the kernel. 172 */ 173 typedef struct _cleanerinfo { 174 u_long clean; /* K: number of clean segments */ 175 u_long dirty; /* K: number of dirty segments */ 176 } CLEANERINFO; 177 178 #define CLEANSIZE_SU(fs) \ 179 ((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift) 180 181 /* 182 * All summary blocks are the same size, so we can always read a summary 183 * block easily from a segment. 184 */ 185 #define LFS_SUMMARY_SIZE 512 186 187 /* On-disk segment summary information */ 188 typedef struct segsum SEGSUM; 189 struct segsum { 190 u_long ss_sumsum; /* check sum of summary block */ 191 u_long ss_datasum; /* check sum of data */ 192 daddr_t ss_next; /* next segment */ 193 u_long ss_create; /* creation time stamp */ 194 u_short ss_nfinfo; /* number of file info structures */ 195 u_short ss_ninos; /* number of inodes in summary */ 196 #define SS_DIROP 0x01 /* segment begins a dirop */ 197 #define SS_CONT 0x02 /* more partials to finish this write*/ 198 u_short ss_flags; /* used for directory operations */ 199 u_short ss_pad; /* extra space */ 200 /* FINFO's and inode daddr's... */ 201 }; 202 203 /* NINDIR is the number of indirects in a file system block. */ 204 #define NINDIR(fs) ((fs)->lfs_nindir) 205 206 /* INOPB is the number of inodes in a secondary storage block. */ 207 #define INOPB(fs) ((fs)->lfs_inopb) 208 209 #define blksize(fs) ((fs)->lfs_bsize) 210 #define blkoff(fs, loc) ((loc) & (fs)->lfs_bmask) 211 #define fsbtodb(fs, b) ((b) << (fs)->lfs_fsbtodb) 212 #define dbtofsb(fs, b) ((b) >> (fs)->lfs_fsbtodb) 213 #define lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift) 214 #define lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift) 215 #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ 216 ((loc) >> (fs)->lfs_bshift) 217 218 #define datosn(fs, daddr) /* disk address to segment number */ \ 219 (((daddr) - (fs)->lfs_sboffs[0]) / fsbtodb((fs), (fs)->lfs_ssize)) 220 #define sntoda(fs, sn) /* segment number to disk address */ \ 221 ((daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) + \ 222 (fs)->lfs_sboffs[0])) 223 224 /* Read in the block with the cleaner info from the ifile. */ 225 #define LFS_CLEANERINFO(CP, F, BP) { \ 226 VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 227 if (bread((F)->lfs_ivnode, (daddr_t)0, (F)->lfs_bsize, NOCRED, &(BP))) \ 228 panic("lfs: ifile read"); \ 229 (CP) = (CLEANERINFO *)(BP)->b_un.b_addr; \ 230 } 231 232 /* Read in the block with a specific inode from the ifile. */ 233 #define LFS_IENTRY(IP, F, IN, BP) { \ 234 int _e; \ 235 VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 236 if (_e = bread((F)->lfs_ivnode, \ 237 (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz, \ 238 (F)->lfs_bsize, NOCRED, &(BP))) \ 239 panic("lfs: ifile read %d", _e); \ 240 (IP) = (IFILE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_ifpb; \ 241 } 242 243 /* Read in the block with a specific segment usage entry from the ifile. */ 244 #define LFS_SEGENTRY(SP, F, IN, BP) { \ 245 int _e; \ 246 VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ 247 if (_e = bread((F)->lfs_ivnode, \ 248 ((IN) >> (F)->lfs_sushift) + (F)->lfs_cleansz, \ 249 (F)->lfs_bsize, NOCRED, &(BP))) \ 250 panic("lfs: ifile read: %d", _e); \ 251 (SP) = (SEGUSE *)(BP)->b_un.b_addr + ((IN) & (F)->lfs_sepb - 1); \ 252 } 253 254 /* 255 * Determine if there is enough room currently available to write db 256 * disk blocks. We need enough blocks for the new blocks, the current, 257 * inode blocks, a summary block, plus potentially the ifile inode and 258 * the segment usage table, plus an ifile page. 259 */ 260 #define LFS_FITS(fs, db) \ 261 ((long)((db + ((fs)->lfs_uinodes + INOPB((fs))) / INOPB((fs)) + \ 262 fsbtodb(fs, 1) + LFS_SUMMARY_SIZE / DEV_BSIZE + (fs)->lfs_segtabsz))\ 263 < (fs)->lfs_avail) 264 265 /* Determine if a buffer belongs to the ifile */ 266 #define IS_IFILE(bp) (VTOI(bp->b_vp)->i_number == LFS_IFILE_INUM) 267 /* 268 * Structures used by lfs_bmapv and lfs_markv to communicate information 269 * about inodes and data blocks. 270 */ 271 typedef struct block_info { 272 ino_t bi_inode; /* inode # */ 273 daddr_t bi_lbn; /* logical block w/in file */ 274 daddr_t bi_daddr; /* disk address of block */ 275 time_t bi_segcreate; /* origin segment create time */ 276 int bi_version; /* file version number */ 277 void *bi_bp; /* data buffer */ 278 } BLOCK_INFO; 279 280 /* In-memory description of a segment about to be written. */ 281 struct segment { 282 struct lfs *fs; /* file system pointer */ 283 struct buf **bpp; /* pointer to buffer array */ 284 struct buf **cbpp; /* pointer to next available bp */ 285 struct buf **start_bpp; /* pointer to first bp in this set */ 286 struct buf *ibp; /* buffer pointer to inode page */ 287 struct finfo *fip; /* current fileinfo pointer */ 288 struct vnode *vp; /* vnode being gathered */ 289 void *segsum; /* segment summary info */ 290 u_long ninodes; /* number of inodes in this segment */ 291 u_long seg_bytes_left; /* bytes left in segment */ 292 u_long sum_bytes_left; /* bytes left in summary block */ 293 u_long seg_number; /* number of this segment */ 294 daddr_t *start_lbp; /* beginning lbn for this set */ 295 #define SEGM_CKP 0x01 /* doing a checkpoint */ 296 #define SEGM_CLEAN 0x02 /* cleaner call; don't sort */ 297 u_long seg_flags; /* run-time flags for this segment */ 298 }; 299 300 #define ISSPACE(F, BB, C) \ 301 (((C)->cr_uid == 0 && (F)->lfs_bfree >= (BB)) || \ 302 ((C)->cr_uid != 0 && IS_FREESPACE(F, BB))) 303 304 #define IS_FREESPACE(F, BB) \ 305 ((F)->lfs_bfree > ((F)->lfs_dsize * (F)->lfs_minfree / 100 + (BB))) 306 307 #define ISSPACE_XXX(F, BB) \ 308 ((F)->lfs_bfree >= (BB)) 309 310