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 | * | |
81b659ea | 7 | * @(#)lfs.h 7.13 (Berkeley) %G% |
7168b5c1 KB |
8 | */ |
9 | ||
b6a5a267 KB |
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 */ | |
7168b5c1 | 13 | |
0b4d6502 | 14 | /* On-disk and in-memory checkpoint segment usage structure. */ |
d5075120 KB |
15 | typedef struct segusage SEGUSE; |
16 | struct segusage { | |
0b4d6502 | 17 | u_long su_nbytes; /* number of live bytes */ |
39cabb59 | 18 | u_long su_lastmod; /* SEGUSE last modified timestamp */ |
6ee32ac0 KB |
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 */ | |
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 */ |
7168b5c1 KB |
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. */ | |
0c67132e | 68 | u_long lfs_dbpseg; /* disk blocks per segment */ |
7168b5c1 KB |
69 | u_long lfs_inopb; /* inodes per block */ |
70 | u_long lfs_ifpb; /* IFILE entries per block */ | |
0c67132e | 71 | u_long lfs_sepb; /* SEGUSE entries per block */ |
7168b5c1 KB |
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 */ | |
0c67132e | 75 | u_long lfs_cleansz; /* cleaner info size in blocks */ |
7168b5c1 KB |
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 | ||
0b4d6502 KB |
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. */ | |
61a9b5a2 | 93 | struct vnode *lfs_ivnode; /* vnode for the ifile */ |
0b4d6502 | 94 | SEGUSE *lfs_segtab; /* in-memory segment usage table */ |
0c67132e KB |
95 | /* XXX NOT USED */ |
96 | void *XXXlfs_seglist; /* list of segments being written */ | |
0c90e94d | 97 | u_long lfs_iocount; /* number of ios pending */ |
0b4d6502 KB |
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 */ | |
d5075120 | 107 | }; |
7168b5c1 | 108 | |
0b4d6502 | 109 | /* |
0d70dc17 KB |
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. | |
0b4d6502 | 112 | */ |
7168b5c1 | 113 | |
b6a5a267 | 114 | /* Fixed inode numbers. */ |
0c90e94d | 115 | #define LFS_UNUSED_INUM 0 /* out of band inode number */ |
0d70dc17 KB |
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 */ | |
b6a5a267 | 119 | |
0b4d6502 | 120 | /* |
b6a5a267 KB |
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] | |
7168b5c1 | 125 | |
0c67132e KB |
126 | /* Address calculations for metadata located in the inode */ |
127 | #define S_INDIR(fs) -NDADDR | |
5c4e1af0 CS |
128 | #define D_INDIR(fs) (S_INDIR(fs) - NINDIR(fs) - 1) |
129 | #define T_INDIR(fs) (D_INDIR(fs) - NINDIR(fs) * NINDIR(fs) - 1) | |
0c67132e KB |
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; | |
d5075120 | 136 | |
39cabb59 KB |
137 | /* Unassigned disk address. */ |
138 | #define UNASSIGNED -1 | |
139 | ||
d5075120 KB |
140 | typedef struct ifile IFILE; |
141 | struct ifile { | |
7168b5c1 | 142 | u_long if_version; /* inode version number */ |
0b4d6502 | 143 | #define LFS_UNUSED_DADDR 0 /* out-of-band daddr */ |
7168b5c1 | 144 | daddr_t if_daddr; /* inode disk address */ |
0d70dc17 | 145 | ino_t if_nextfree; /* next-unallocated inode */ |
d5075120 | 146 | }; |
7168b5c1 | 147 | |
0c67132e KB |
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 */ | |
0c67132e | 155 | } CLEANERINFO; |
7168b5c1 | 156 | |
0c67132e KB |
157 | #define CLEANSIZE_SU(fs) \ |
158 | ((sizeof(CLEANERINFO) + (fs)->lfs_bsize - 1) >> (fs)->lfs_bshift) | |
b6a5a267 | 159 | |
b6a5a267 KB |
160 | /* |
161 | * All summary blocks are the same size, so we can always read a summary | |
0c90e94d | 162 | * block easily from a segment. |
b6a5a267 KB |
163 | */ |
164 | #define LFS_SUMMARY_SIZE 512 | |
165 | ||
7168b5c1 | 166 | /* On-disk segment summary information */ |
d5075120 KB |
167 | typedef struct segsum SEGSUM; |
168 | struct segsum { | |
0c67132e KB |
169 | u_long ss_sumsum; /* check sum of summary block */ |
170 | u_long ss_datasum; /* check sum of data */ | |
7168b5c1 | 171 | daddr_t ss_next; /* next segment */ |
7168b5c1 KB |
172 | u_long ss_create; /* creation time stamp */ |
173 | u_long ss_nfinfo; /* number of file info structures */ | |
0c67132e | 174 | u_long ss_ninos; /* number of inodes in summary */ |
d3b72332 | 175 | /* FINFO's and inode daddr's... */ |
d5075120 | 176 | }; |
7168b5c1 | 177 | |
0b4d6502 KB |
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 | ||
0b4d6502 KB |
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) | |
d5075120 KB |
189 | #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ |
190 | ((loc) >> (fs)->lfs_bshift) | |
39cabb59 | 191 | |
0d70dc17 KB |
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 | ||
59526076 KB |
198 | /* Read in the block with the cleaner info from the ifile. */ |
199 | #define LFS_CLEANERINFO(CP, F, BP) { \ | |
0d70dc17 | 200 | VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ |
5ec8c51e | 201 | if (bread((F)->lfs_ivnode, (daddr_t)0, (F)->lfs_bsize, NOCRED, &(BP))) \ |
59526076 | 202 | panic("lfs: ifile read"); \ |
5ec8c51e | 203 | (CP) = (CLEANERINFO *)(BP)->b_un.b_addr; \ |
59526076 KB |
204 | } |
205 | ||
0c67132e | 206 | /* Read in the block with a specific inode from the ifile. */ |
59526076 | 207 | #define LFS_IENTRY(IP, F, IN, BP) { \ |
5ec8c51e | 208 | VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ |
0c67132e KB |
209 | if (bread((F)->lfs_ivnode, \ |
210 | (IN) / (F)->lfs_ifpb + (F)->lfs_cleansz + (F)->lfs_segtabsz, \ | |
5ec8c51e | 211 | (F)->lfs_bsize, NOCRED, &(BP))) \ |
a9322048 | 212 | panic("lfs: ifile read"); \ |
5ec8c51e | 213 | (IP) = (IFILE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_ifpb; \ |
a9322048 KB |
214 | } |
215 | ||
0c67132e | 216 | /* Read in the block with a specific segment usage entry from the ifile. */ |
59526076 | 217 | #define LFS_SEGENTRY(SP, F, IN, BP) { \ |
5ec8c51e | 218 | VTOI((F)->lfs_ivnode)->i_flag |= IACC; \ |
0c67132e | 219 | if (bread((F)->lfs_ivnode, (IN) / (F)->lfs_sepb + (F)->lfs_cleansz, \ |
5ec8c51e | 220 | (F)->lfs_bsize, NOCRED, &(BP))) \ |
0c67132e | 221 | panic("lfs: ifile read"); \ |
5ec8c51e | 222 | (SP) = (SEGUSE *)(BP)->b_un.b_addr + (IN) % (F)->lfs_sepb; \ |
0c67132e KB |
223 | } |
224 | ||
0d70dc17 KB |
225 | /* Write a block and update the inode change times. */ |
226 | #define LFS_UBWRITE(BP) { \ | |
9c954627 | 227 | USES_VOP_BWRITE; \ |
0d70dc17 | 228 | VTOI((BP)->b_vp)->i_flag |= ICHG | IUPD; \ |
9c954627 | 229 | VOP_BWRITE(BP); \ |
5ec8c51e KB |
230 | } |
231 | ||
0c67132e KB |
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; |