Commit | Line | Data |
---|---|---|
f97378c7 | 1 | /*- |
88f72820 KB |
2 | * Copyright (c) 1992, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
f97378c7 | 4 | * |
ad787160 C |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * 3. All advertising materials mentioning features or use of this software | |
14 | * must display the following acknowledgement: | |
15 | * This product includes software developed by the University of | |
16 | * California, Berkeley and its contributors. | |
17 | * 4. Neither the name of the University nor the names of its contributors | |
18 | * may be used to endorse or promote products derived from this software | |
19 | * without specific prior written permission. | |
f97378c7 | 20 | * |
ad787160 C |
21 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND |
22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
25 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
26 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
27 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
28 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
29 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
30 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
31 | * SUCH DAMAGE. | |
32 | * | |
33 | * @(#)clean.h 8.1 (Berkeley) 6/4/93 | |
f97378c7 KB |
34 | */ |
35 | ||
8cfd96bf KB |
36 | /* |
37 | * The LFS user-level library will be used when writing cleaners and | |
f97378c7 KB |
38 | * checkers for LFS file systems. It will have facilities for finding |
39 | * and parsing LFS segments. | |
8cfd96bf KB |
40 | */ |
41 | ||
8d18badf KB |
42 | #define DUMP_SUM_HEADER 0x0001 |
43 | #define DUMP_INODE_ADDRS 0x0002 | |
44 | #define DUMP_FINFOS 0x0004 | |
45 | #define DUMP_ALL 0xFFFF | |
46 | ||
8cfd96bf KB |
47 | #define IFILE_NAME "ifile" |
48 | ||
8d18badf KB |
49 | /* |
50 | * Cleaner parameters | |
51 | * BUSY_LIM: lower bound of the number of segments currently available | |
52 | * as a percentage of the total number of free segments possibly | |
53 | * available. | |
54 | * IDLE_LIM: Same as BUSY_LIM but used when the system is idle. | |
55 | * MIN_SEGS: Minimum number of segments you should always have. | |
56 | * I have no idea what this should be, but it should probably | |
57 | * be a function of lfsp. | |
58 | * NUM_TO_CLEAN: Number of segments to clean at once. Again, this | |
59 | * should probably be based on the file system size and how | |
60 | * full or empty the segments being cleaned are. | |
61 | */ | |
62 | ||
63 | #define BUSY_LIM 0.50 | |
64 | #define IDLE_LIM 0.90 | |
f97378c7 KB |
65 | |
66 | #define MIN_SEGS(lfsp) (3) | |
934bd4a3 | 67 | #define NUM_TO_CLEAN(fsp) (1) |
8d18badf KB |
68 | |
69 | #define MAXLOADS 3 | |
f97378c7 KB |
70 | #define ONE_MIN 0 |
71 | #define FIVE_MIN 1 | |
72 | #define FIFTEEN_MIN 2 | |
8d18badf | 73 | |
8cfd96bf KB |
74 | typedef struct fs_info { |
75 | struct statfs *fi_statfsp; /* fsstat info from getfsstat */ | |
8d18badf KB |
76 | struct lfs fi_lfs; /* superblock */ |
77 | CLEANERINFO *fi_cip; /* Cleaner info from ifile */ | |
8cfd96bf KB |
78 | SEGUSE *fi_segusep; /* segment usage table (from ifile) */ |
79 | IFILE *fi_ifilep; /* ifile table (from ifile) */ | |
80 | u_long fi_daddr_shift; /* shift to get byte offset of daddr */ | |
81 | u_long fi_ifile_count; /* # entries in the ifile table */ | |
8d18badf | 82 | off_t fi_ifile_length; /* length of the ifile */ |
8cfd96bf KB |
83 | } FS_INFO; |
84 | ||
8cfd96bf KB |
85 | /* |
86 | * XXX: size (in bytes) of a segment | |
87 | * should lfs_bsize be fsbtodb(fs,1), blksize(fs), or lfs_dsize? | |
88 | */ | |
8d18badf | 89 | #define seg_size(fs) ((fs)->lfs_ssize << (fs)->lfs_bshift) |
8cfd96bf KB |
90 | |
91 | /* daddr -> byte offset */ | |
8d18badf KB |
92 | #define datobyte(fs, da) ((da) << (fs)->fi_daddr_shift) |
93 | #define bytetoda(fs, byte) ((byte) >> (fs)->fi_daddr_shift) | |
94 | ||
95 | #define CLEANSIZE(fsp) (fsp->fi_lfs.lfs_cleansz << fsp->fi_lfs.lfs_bshift) | |
96 | #define SEGTABSIZE(fsp) (fsp->fi_lfs.lfs_segtabsz << fsp->fi_lfs.lfs_bshift) | |
97 | ||
98 | #define IFILE_ENTRY(fs, if, i) \ | |
99 | ((IFILE *)((caddr_t)(if) + ((i) / (fs)->lfs_ifpb << (fs)->lfs_bshift)) \ | |
100 | + (i) % (fs)->lfs_ifpb) | |
101 | ||
102 | #define SEGUSE_ENTRY(fs, su, i) \ | |
103 | ((SEGUSE *)((caddr_t)(su) + (fs)->lfs_bsize * ((i) / (fs)->lfs_sepb)) +\ | |
104 | (i) % (fs)->lfs_sepb) | |
105 | ||
106 | __BEGIN_DECLS | |
107 | int dump_summary __P((struct lfs *, SEGSUM *, u_long, daddr_t **)); | |
108 | void err __P((const int, const char *, ...)); | |
d59d68b6 | 109 | int fs_getmntinfo __P((struct statfs **, char *, int)); |
8d18badf | 110 | int get __P((int, off_t, void *, size_t)); |
d59d68b6 | 111 | FS_INFO *get_fs_info __P((struct statfs *, int)); |
8b56bcc8 | 112 | int lfs_segmapv __P((FS_INFO *, int, caddr_t, BLOCK_INFO **, int *)); |
3f223803 MS |
113 | int mmap_segment __P((FS_INFO *, int, caddr_t *, int)); |
114 | void munmap_segment __P((FS_INFO *, caddr_t, int)); | |
d59d68b6 | 115 | void reread_fs_info __P((FS_INFO *, int)); |
8d18badf KB |
116 | void toss __P((void *, int *, size_t, |
117 | int (*)(const void *, const void *, const void *), void *)); | |
8cfd96bf KB |
118 | |
119 | /* | |
8d18badf KB |
120 | * USEFUL DEBUGGING FUNCTIONS: |
121 | */ | |
122 | #ifdef VERBOSE | |
123 | #define PRINT_FINFO(fp, ip) { \ | |
124 | (void)printf(" %s %s%d version %d nblocks %d\n", \ | |
125 | (ip)->if_version > (fp)->fi_version ? "TOSSING" : "KEEPING", \ | |
126 | "FINFO for inode: ", (fp)->fi_ino, \ | |
127 | (fp)->fi_version, (fp)->fi_nblocks); \ | |
128 | fflush(stdout); \ | |
129 | } | |
130 | ||
ccc08959 | 131 | #define PRINT_INODE(b, bip) { \ |
8d18badf | 132 | (void) printf("\t%s inode: %d daddr: 0x%lx create: %s\n", \ |
8b56bcc8 KB |
133 | b ? "KEEPING" : "TOSSING", (bip)->bi_inode, (bip)->bi_daddr, \ |
134 | ctime((time_t *)&(bip)->bi_segcreate)); \ | |
8d18badf KB |
135 | fflush(stdout); \ |
136 | } | |
137 | ||
138 | #define PRINT_BINFO(bip) { \ | |
139 | (void)printf("\tinode: %d lbn: %d daddr: 0x%lx create: %s\n", \ | |
140 | (bip)->bi_inode, (bip)->bi_lbn, (bip)->bi_daddr, \ | |
141 | ctime((time_t *)&(bip)->bi_segcreate)); \ | |
142 | fflush(stdout); \ | |
143 | } | |
144 | ||
145 | #define PRINT_SEGUSE(sup, n) { \ | |
146 | (void)printf("Segment %d nbytes=%lu\tflags=%c%c%c ninos=%d nsums=%d lastmod: %s\n", \ | |
147 | n, (sup)->su_nbytes, \ | |
148 | (sup)->su_flags & SEGUSE_DIRTY ? 'D' : 'C', \ | |
149 | (sup)->su_flags & SEGUSE_ACTIVE ? 'A' : ' ', \ | |
150 | (sup)->su_flags & SEGUSE_SUPERBLOCK ? 'S' : ' ', \ | |
151 | (sup)->su_ninos, (sup)->su_nsums, \ | |
152 | ctime((time_t *)&(sup)->su_lastmod)); \ | |
153 | fflush(stdout); \ | |
154 | } | |
155 | ||
156 | void dump_super __P((struct lfs *)); | |
157 | void dump_cleaner_info __P((void *)); | |
158 | void print_SEGSUM __P(( struct lfs *, SEGSUM *)); | |
159 | void print_CLEANERINFO __P((CLEANERINFO *)); | |
160 | #else | |
161 | #define PRINT_FINFO(fp, ip) | |
ccc08959 | 162 | #define PRINT_INODE(b, bip) |
8d18badf KB |
163 | #define PRINT_BINFO(bip) |
164 | #define PRINT_SEGUSE(sup, n) | |
165 | #define dump_cleaner_info(cip) | |
166 | #define dump_super(lfsp) | |
167 | #endif | |
8d18badf | 168 | __END_DECLS |