This source file includes following definitions.
- ffs_bufatoff
- ffs_fragacct
- ffs_checkoverlap
- ffs_isblock
- ffs_clrblock
- ffs_setblock
- ffs_isfreeblock
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 #include <sys/param.h>
36 #include <ufs/ffs/fs.h>
37
38 #ifdef _KERNEL
39 #include <sys/systm.h>
40 #include <sys/vnode.h>
41 #include <sys/mount.h>
42 #include <sys/buf.h>
43
44 #include <ufs/ufs/quota.h>
45 #include <ufs/ufs/inode.h>
46 #include <ufs/ufs/ufsmount.h>
47 #include <ufs/ufs/ufs_extern.h>
48
49 #include <ufs/ffs/ffs_extern.h>
50
51
52
53
54
55
56 int
57 ffs_bufatoff(struct inode *ip, off_t offset, char **res, struct buf **bpp)
58 {
59 struct fs *fs;
60 struct vnode *vp;
61 struct buf *bp;
62 daddr_t lbn;
63 int bsize, error;
64
65 vp = ITOV(ip);
66 fs = ip->i_fs;
67 lbn = lblkno(fs, offset);
68 bsize = blksize(fs, ip, lbn);
69
70 *bpp = NULL;
71 if ((error = bread(vp, lbn, fs->fs_bsize, NOCRED, &bp)) != 0) {
72 brelse(bp);
73 return (error);
74 }
75 bp->b_bcount = bsize;
76 if (res)
77 *res = (char *)bp->b_data + blkoff(fs, offset);
78 *bpp = bp;
79 return (0);
80 }
81 #else
82
83 void ffs_fragacct(struct fs *, int, int32_t[], int);
84 int ffs_isfreeblock(struct fs *, unsigned char *, daddr_t);
85 int ffs_isblock(struct fs *, unsigned char *, daddr_t);
86 void ffs_clrblock(struct fs *, u_char *, daddr_t);
87 void ffs_setblock(struct fs *, unsigned char *, daddr_t);
88 __dead void panic(const char *, ...);
89 #endif
90
91
92
93
94
95 void
96 ffs_fragacct(struct fs *fs, int fragmap, int32_t fraglist[], int cnt)
97 {
98 int inblk;
99 int field, subfield;
100 int siz, pos;
101
102 inblk = (int)(fragtbl[fs->fs_frag][fragmap]) << 1;
103 fragmap <<= 1;
104 for (siz = 1; siz < fs->fs_frag; siz++) {
105 if ((inblk & (1 << (siz + (fs->fs_frag % NBBY)))) == 0)
106 continue;
107 field = around[siz];
108 subfield = inside[siz];
109 for (pos = siz; pos <= fs->fs_frag; pos++) {
110 if ((fragmap & field) == subfield) {
111 fraglist[siz] += cnt;
112 pos += siz;
113 field <<= siz;
114 subfield <<= siz;
115 }
116 field <<= 1;
117 subfield <<= 1;
118 }
119 }
120 }
121
122 #if defined(_KERNEL) && defined(DIAGNOSTIC)
123 void
124 ffs_checkoverlap(struct buf *bp, struct inode *ip)
125 {
126 daddr_t start, last;
127 struct vnode *vp;
128 struct buf *ep;
129
130 start = bp->b_blkno;
131 last = start + btodb(bp->b_bcount) - 1;
132 LIST_FOREACH(ep, &bufhead, b_list) {
133 if (ep == bp || (ep->b_flags & B_INVAL) ||
134 ep->b_vp == NULLVP)
135 continue;
136 if (VOP_BMAP(ep->b_vp, (daddr_t)0, &vp, (daddr_t)0, NULL))
137 continue;
138 if (vp != ip->i_devvp)
139 continue;
140
141 if (ep->b_bcount == 0 || ep->b_blkno > last ||
142 ep->b_blkno + btodb(ep->b_bcount) <= start)
143 continue;
144 vprint("Disk overlap", vp);
145 (void)printf("\tstart %d, end %d overlap start %d, end %ld\n",
146 start, last, ep->b_blkno,
147 ep->b_blkno + btodb(ep->b_bcount) - 1);
148 panic("Disk buffer overlap");
149 }
150 }
151 #endif
152
153
154
155
156
157
158 int
159 ffs_isblock(struct fs *fs, unsigned char *cp, daddr_t h)
160 {
161 unsigned char mask;
162
163 switch (fs->fs_frag) {
164 default:
165 case 8:
166 return (cp[h] == 0xff);
167 case 4:
168 mask = 0x0f << ((h & 0x1) << 2);
169 return ((cp[h >> 1] & mask) == mask);
170 case 2:
171 mask = 0x03 << ((h & 0x3) << 1);
172 return ((cp[h >> 2] & mask) == mask);
173 case 1:
174 mask = 0x01 << (h & 0x7);
175 return ((cp[h >> 3] & mask) == mask);
176 }
177 }
178
179
180
181
182 void
183 ffs_clrblock(struct fs *fs, u_char *cp, daddr_t h)
184 {
185
186 switch (fs->fs_frag) {
187 default:
188 case 8:
189 cp[h] = 0;
190 return;
191 case 4:
192 cp[h >> 1] &= ~(0x0f << ((h & 0x1) << 2));
193 return;
194 case 2:
195 cp[h >> 2] &= ~(0x03 << ((h & 0x3) << 1));
196 return;
197 case 1:
198 cp[h >> 3] &= ~(0x01 << (h & 0x7));
199 return;
200 }
201 }
202
203
204
205
206 void
207 ffs_setblock(struct fs *fs, unsigned char *cp, daddr_t h)
208 {
209
210 switch (fs->fs_frag) {
211 default:
212 case 8:
213 cp[h] = 0xff;
214 return;
215 case 4:
216 cp[h >> 1] |= (0x0f << ((h & 0x1) << 2));
217 return;
218 case 2:
219 cp[h >> 2] |= (0x03 << ((h & 0x3) << 1));
220 return;
221 case 1:
222 cp[h >> 3] |= (0x01 << (h & 0x7));
223 return;
224 }
225 }
226
227
228
229
230 int
231 ffs_isfreeblock(struct fs *fs, unsigned char *cp, daddr_t h)
232 {
233
234 switch (fs->fs_frag) {
235 default:
236 case 8:
237 return (cp[h] == 0);
238 case 4:
239 return ((cp[h >> 1] & (0x0f << ((h & 0x1) << 2))) == 0);
240 case 2:
241 return ((cp[h >> 2] & (0x03 << ((h & 0x3) << 1))) == 0);
242 case 1:
243 return ((cp[h >> 3] & (0x01 << (h & 0x7))) == 0);
244 }
245 }