Commit | Line | Data |
---|---|---|
39d536e6 | 1 | /* ffs_subr.c 4.2 82/10/21 */ |
764e2379 BJ |
2 | |
3 | #ifdef KERNEL | |
4 | #include "../h/param.h" | |
5 | #include "../h/fs.h" | |
6 | #else | |
7 | #include <sys/param.h> | |
8 | #include <sys/fs.h> | |
9 | #endif | |
10 | ||
11 | extern int around[9]; | |
12 | extern int inside[9]; | |
13 | extern u_char *fragtbl[]; | |
14 | ||
15 | /* | |
16 | * Update the frsum fields to reflect addition or deletion | |
17 | * of some frags. | |
18 | */ | |
19 | fragacct(fs, fragmap, fraglist, cnt) | |
20 | struct fs *fs; | |
21 | int fragmap; | |
22 | long fraglist[]; | |
23 | int cnt; | |
24 | { | |
25 | int inblk; | |
26 | register int field, subfield; | |
27 | register int siz, pos; | |
28 | ||
29 | inblk = (int)(fragtbl[fs->fs_frag][fragmap]) << 1; | |
30 | fragmap <<= 1; | |
31 | for (siz = 1; siz < fs->fs_frag; siz++) { | |
32 | if ((inblk & (1 << (siz + (fs->fs_frag % NBBY)))) == 0) | |
33 | continue; | |
34 | field = around[siz]; | |
35 | subfield = inside[siz]; | |
36 | for (pos = siz; pos <= fs->fs_frag; pos++) { | |
37 | if ((fragmap & field) == subfield) { | |
38 | fraglist[siz] += cnt; | |
39 | pos += siz; | |
40 | field <<= siz; | |
41 | subfield <<= siz; | |
42 | } | |
43 | field <<= 1; | |
44 | subfield <<= 1; | |
45 | } | |
46 | } | |
47 | } | |
48 | ||
49 | #ifdef KERNEL | |
50 | /* | |
51 | * Check that a specified block number is in range. | |
52 | */ | |
53 | badblock(fs, bn) | |
54 | register struct fs *fs; | |
55 | daddr_t bn; | |
56 | { | |
57 | ||
58 | if ((unsigned)bn >= fs->fs_size) { | |
59 | printf("bad block %d, ", bn); | |
60 | fserr(fs, "bad block"); | |
61 | return (1); | |
62 | } | |
63 | return (0); | |
64 | } | |
65 | #endif | |
66 | ||
67 | /* | |
68 | * block operations | |
69 | * | |
70 | * check if a block is available | |
71 | */ | |
72 | isblock(fs, cp, h) | |
73 | struct fs *fs; | |
74 | unsigned char *cp; | |
75 | daddr_t h; | |
76 | { | |
77 | unsigned char mask; | |
78 | ||
79 | switch (fs->fs_frag) { | |
80 | case 8: | |
81 | return (cp[h] == 0xff); | |
82 | case 4: | |
83 | mask = 0x0f << ((h & 0x1) << 2); | |
84 | return ((cp[h >> 1] & mask) == mask); | |
85 | case 2: | |
86 | mask = 0x03 << ((h & 0x3) << 1); | |
87 | return ((cp[h >> 2] & mask) == mask); | |
88 | case 1: | |
89 | mask = 0x01 << (h & 0x7); | |
90 | return ((cp[h >> 3] & mask) == mask); | |
91 | default: | |
92 | panic("isblock"); | |
93 | return (NULL); | |
94 | } | |
95 | } | |
96 | ||
97 | /* | |
98 | * take a block out of the map | |
99 | */ | |
100 | clrblock(fs, cp, h) | |
101 | struct fs *fs; | |
39d536e6 | 102 | u_char *cp; |
764e2379 BJ |
103 | daddr_t h; |
104 | { | |
105 | ||
106 | switch ((fs)->fs_frag) { | |
107 | case 8: | |
108 | cp[h] = 0; | |
109 | return; | |
110 | case 4: | |
111 | cp[h >> 1] &= ~(0x0f << ((h & 0x1) << 2)); | |
112 | return; | |
113 | case 2: | |
114 | cp[h >> 2] &= ~(0x03 << ((h & 0x3) << 1)); | |
115 | return; | |
116 | case 1: | |
117 | cp[h >> 3] &= ~(0x01 << (h & 0x7)); | |
118 | return; | |
119 | default: | |
120 | panic("clrblock"); | |
121 | } | |
122 | } | |
123 | ||
124 | /* | |
125 | * put a block into the map | |
126 | */ | |
127 | setblock(fs, cp, h) | |
128 | struct fs *fs; | |
129 | unsigned char *cp; | |
130 | daddr_t h; | |
131 | { | |
132 | ||
133 | switch (fs->fs_frag) { | |
134 | ||
135 | case 8: | |
136 | cp[h] = 0xff; | |
137 | return; | |
138 | case 4: | |
139 | cp[h >> 1] |= (0x0f << ((h & 0x1) << 2)); | |
140 | return; | |
141 | case 2: | |
142 | cp[h >> 2] |= (0x03 << ((h & 0x3) << 1)); | |
143 | return; | |
144 | case 1: | |
145 | cp[h >> 3] |= (0x01 << (h & 0x7)); | |
146 | return; | |
147 | default: | |
148 | panic("setblock"); | |
149 | } | |
150 | } |