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 | * | |
39cabb59 | 7 | * @(#)lfs.h 5.7 (Berkeley) %G% |
7168b5c1 KB |
8 | */ |
9 | ||
d5075120 KB |
10 | typedef struct buf BUF; |
11 | typedef struct dinode DINODE; | |
12 | typedef struct inode INODE; | |
13 | typedef struct mount MOUNT; | |
14 | typedef struct ucred UCRED; | |
15 | typedef struct ufsmount UFSMOUNT; | |
16 | typedef struct vnode VNODE; | |
17 | ||
b6a5a267 KB |
18 | #define LFS_LABELPAD 8192 /* LFS label size */ |
19 | #define LFS_SBPAD 8192 /* LFS superblock size */ | |
20 | #define MAXMNTLEN 512 /* XXX move from fs.h to mount.h */ | |
7168b5c1 | 21 | |
0b4d6502 | 22 | /* On-disk and in-memory checkpoint segment usage structure. */ |
d5075120 KB |
23 | typedef struct segusage SEGUSE; |
24 | struct segusage { | |
0b4d6502 | 25 | u_long su_nbytes; /* number of live bytes */ |
39cabb59 | 26 | u_long su_lastmod; /* SEGUSE last modified timestamp */ |
d5075120 | 27 | #define SEGUSE_DIRTY 0x1 /* XXX fill in comment */ |
0b4d6502 | 28 | u_long su_flags; |
d5075120 KB |
29 | }; |
30 | ||
31 | /* On-disk file information. One per file with data blocks in the segment. */ | |
32 | typedef struct finfo FINFO; | |
33 | struct finfo { | |
34 | u_long fi_nblocks; /* number of blocks */ | |
35 | u_long fi_version; /* version number */ | |
275ca4f0 | 36 | u_long fi_ino; /* inode number */ |
d5075120 KB |
37 | long fi_blocks[1]; /* array of logical block numbers */ |
38 | }; | |
39 | ||
40 | /* In-memory description of a segment about to be written */ | |
41 | typedef struct segment SEGMENT; | |
42 | struct segment { | |
0c90e94d KB |
43 | SEGMENT *nextp; /* links segments together */ |
44 | BUF **bpp; /* pointer to buffer array */ | |
45 | BUF **cbpp; /* pointer to next available bp */ | |
46 | BUF *ibp; /* buffer pointer to inode page */ | |
47 | BUF *sbp; /* segment summary buffer pointer */ | |
48 | void *segsum; /* segment Summary info */ | |
0c90e94d | 49 | u_long seg_bytes_left; /* bytes left in segment */ |
39cabb59 | 50 | u_long sum_bytes_left; /* bytes left in summary block */ |
0c90e94d KB |
51 | daddr_t saddr; /* current disk address */ |
52 | daddr_t sum_addr; /* address of current summary */ | |
53 | u_long ninodes; /* number of inodes in this segment */ | |
39cabb59 | 54 | u_long nsums; /* number of SEGSUMs in this segment */ |
0c90e94d KB |
55 | u_long seg_number; /* number of this segment */ |
56 | FINFO *fip; /* current fileinfo pointer */ | |
d5075120 | 57 | }; |
0b4d6502 KB |
58 | |
59 | /* On-disk and in-memory super block. */ | |
d5075120 KB |
60 | typedef struct lfs LFS; |
61 | struct lfs { | |
0b4d6502 | 62 | #define LFS_MAGIC 0xbedead |
7168b5c1 | 63 | u_long lfs_magic; /* magic number */ |
b6a5a267 | 64 | #define LFS_VERSION 1 |
7168b5c1 KB |
65 | u_long lfs_version; /* version number */ |
66 | ||
67 | u_long lfs_size; /* number of blocks in fs */ | |
68 | u_long lfs_ssize; /* number of blocks per segment */ | |
69 | u_long lfs_dsize; /* number of data blocks in fs */ | |
70 | u_long lfs_bsize; /* size of basic blocks in fs */ | |
71 | u_long lfs_fsize; /* size of frag blocks in fs */ | |
72 | u_long lfs_frag; /* number of frags in a block in fs */ | |
7168b5c1 KB |
73 | |
74 | /* Checkpoint region. */ | |
75 | ino_t lfs_free; /* start of the free list */ | |
0b4d6502 KB |
76 | u_long lfs_bfree; /* number of free blocks */ |
77 | u_long lfs_nfiles; /* number of allocated inodes */ | |
7168b5c1 KB |
78 | daddr_t lfs_idaddr; /* inode file disk address */ |
79 | ino_t lfs_ifile; /* inode file inode number */ | |
0c90e94d KB |
80 | daddr_t lfs_lastseg; /* address of last segment written */ |
81 | daddr_t lfs_nextseg; /* address of next segment to write */ | |
7168b5c1 KB |
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_long lfs_inopb; /* inodes per block */ | |
89 | u_long lfs_ifpb; /* IFILE entries per block */ | |
90 | u_long lfs_nindir; /* indirect pointers per block */ | |
91 | u_long lfs_nseg; /* number of segments */ | |
92 | u_long lfs_nspf; /* number of sectors per fragment */ | |
93 | u_long lfs_segtabsz; /* segment table size in blocks */ | |
94 | ||
95 | u_long lfs_segmask; /* calculate offset within a segment */ | |
96 | u_long lfs_segshift; /* fast mult/div for segments */ | |
97 | u_long lfs_bmask; /* calc block offset from file offset */ | |
98 | u_long lfs_bshift; /* calc block number from file offset */ | |
99 | u_long lfs_ffmask; /* calc frag offset from file offset */ | |
100 | u_long lfs_ffshift; /* fast mult/div for frag from file */ | |
101 | u_long lfs_fbmask; /* calc frag offset from block offset */ | |
102 | u_long lfs_fbshift; /* fast mult/div for frag from block */ | |
103 | u_long lfs_fsbtodb; /* fsbtodb and dbtofsb shift constant */ | |
104 | ||
0b4d6502 KB |
105 | #define LFS_MIN_SBINTERVAL 5 /* minimum superblock segment spacing */ |
106 | #define LFS_MAXNUMSB 10 /* superblock disk offsets */ | |
107 | daddr_t lfs_sboffs[LFS_MAXNUMSB]; | |
108 | ||
109 | /* These fields are set at mount time and are meaningless on disk. */ | |
d5075120 | 110 | VNODE *lfs_ivnode; /* vnode for the ifile */ |
0b4d6502 | 111 | SEGUSE *lfs_segtab; /* in-memory segment usage table */ |
d5075120 | 112 | SEGMENT *lfs_seglist; /* list of segments being written */ |
0c90e94d | 113 | u_long lfs_iocount; /* number of ios pending */ |
0b4d6502 KB |
114 | u_char lfs_fmod; /* super block modified flag */ |
115 | u_char lfs_clean; /* file system is clean flag */ | |
116 | u_char lfs_ronly; /* mounted read-only flag */ | |
117 | u_char lfs_flags; /* currently unused flag */ | |
118 | u_char lfs_fsmnt[MAXMNTLEN]; /* name mounted on */ | |
119 | u_char pad[3]; /* long-align */ | |
120 | ||
121 | /* Checksum; valid on disk. */ | |
122 | u_long lfs_cksum; /* checksum for superblock checking */ | |
d5075120 | 123 | }; |
7168b5c1 | 124 | |
0b4d6502 KB |
125 | /* |
126 | * The root inode is the root of the file system. Inode 0 is the out-of-band | |
127 | * inode, and inode 1 is the inode number for the ifile. Thus the root inode | |
128 | * is 2. | |
129 | */ | |
130 | #define ROOTINO ((ino_t)2) | |
131 | #define LOSTFOUNDINO ((ino_t)3) | |
7168b5c1 | 132 | |
b6a5a267 | 133 | /* Fixed inode numbers. */ |
0c90e94d KB |
134 | #define LFS_UNUSED_INUM 0 /* out of band inode number */ |
135 | #define LFS_IFILE_INUM 1 /* inode number of the ifile */ | |
136 | /* first free inode number */ | |
0b4d6502 | 137 | #define LFS_FIRST_INUM (LOSTFOUNDINO + 1) |
b6a5a267 | 138 | |
0b4d6502 | 139 | /* |
b6a5a267 KB |
140 | * Used to access the first spare of the dinode which we use to store |
141 | * the ifile number so we can identify them | |
142 | */ | |
143 | #define di_inum di_spare[0] | |
7168b5c1 | 144 | |
39cabb59 | 145 | /* Logical block numbers of indirect blocks. */ |
d5075120 KB |
146 | #define S_INDIR -1 |
147 | #define D_INDIR -2 | |
148 | #define T_INDIR -3 | |
149 | ||
39cabb59 KB |
150 | /* Unassigned disk address. */ |
151 | #define UNASSIGNED -1 | |
152 | ||
d5075120 KB |
153 | typedef struct ifile IFILE; |
154 | struct ifile { | |
7168b5c1 | 155 | u_long if_version; /* inode version number */ |
0b4d6502 | 156 | #define LFS_UNUSED_DADDR 0 /* out-of-band daddr */ |
7168b5c1 KB |
157 | daddr_t if_daddr; /* inode disk address */ |
158 | union { | |
159 | ino_t nextfree; /* next-unallocated inode */ | |
160 | time_t st_atime; /* access time */ | |
161 | } __ifile_u; | |
b6a5a267 KB |
162 | #define if_st_atime __ifile_u.st_atime |
163 | #define if_nextfree __ifile_u.nextfree | |
d5075120 | 164 | }; |
7168b5c1 KB |
165 | |
166 | /* Segment table size, in blocks. */ | |
167 | #define SEGTABSIZE(fs) \ | |
0b4d6502 KB |
168 | (((fs)->fs_nseg * sizeof(SEGUSE) + \ |
169 | ((fs)->fs_bsize - 1)) >> (fs)->fs_bshift) | |
7168b5c1 | 170 | |
b6a5a267 | 171 | #define SEGTABSIZE_SU(fs) \ |
0b4d6502 | 172 | (((fs)->lfs_nseg * sizeof(SEGUSE) + \ |
b6a5a267 KB |
173 | ((fs)->lfs_bsize - 1)) >> (fs)->lfs_bshift) |
174 | ||
b6a5a267 KB |
175 | /* |
176 | * All summary blocks are the same size, so we can always read a summary | |
0c90e94d | 177 | * block easily from a segment. |
b6a5a267 KB |
178 | */ |
179 | #define LFS_SUMMARY_SIZE 512 | |
180 | ||
7168b5c1 | 181 | /* On-disk segment summary information */ |
d5075120 KB |
182 | typedef struct segsum SEGSUM; |
183 | struct segsum { | |
0b4d6502 | 184 | u_long ss_cksum; /* check sum */ |
7168b5c1 KB |
185 | daddr_t ss_next; /* next segment */ |
186 | daddr_t ss_prev; /* next segment */ | |
187 | daddr_t ss_nextsum; /* next summary block */ | |
188 | u_long ss_create; /* creation time stamp */ | |
189 | u_long ss_nfinfo; /* number of file info structures */ | |
0b4d6502 KB |
190 | u_long ss_ninos; /* number of inode blocks */ |
191 | /* FINFO's... */ | |
d5075120 | 192 | }; |
7168b5c1 | 193 | |
0b4d6502 KB |
194 | /* NINDIR is the number of indirects in a file system block. */ |
195 | #define NINDIR(fs) ((fs)->lfs_nindir) | |
196 | ||
197 | /* INOPB is the number of inodes in a secondary storage block. */ | |
198 | #define INOPB(fs) ((fs)->lfs_inopb) | |
199 | ||
200 | /* IFPB -- IFILE's per block */ | |
201 | #define IFPB(fs) ((fs)->lfs_ifpb) | |
202 | ||
203 | #define blksize(fs) ((fs)->lfs_bsize) | |
204 | #define blkoff(fs, loc) ((loc) & (fs)->lfs_bmask) | |
205 | #define fsbtodb(fs, b) ((b) << (fs)->lfs_fsbtodb) | |
206 | #define lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift) | |
207 | #define lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift) | |
d5075120 KB |
208 | #define numfrags(fs, loc) /* calculates (loc / fs->fs_fsize) */ \ |
209 | ((loc) >> (fs)->lfs_bshift) | |
39cabb59 KB |
210 | |
211 | #define datosn(fs, daddr) /* disk address to segment number */ \ | |
212 | (((daddr) - (fs)->lfs_sboffs[0]) / fsbtodb((fs), (fs)->lfs_ssize)) | |
213 | #define sntoda(fs, sn) /* segment number to disk address */ \ | |
214 | ((daddr_t)((sn) * ((fs)->lfs_ssize << (fs)->lfs_fsbtodb) + \ | |
215 | (fs)->lfs_sboffs[0])) |