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