]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
ff6e181a A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
1c79356b | 12 | * |
ff6e181a A |
13 | * The Original Code and all software distributed under the License are |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
ff6e181a A |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
1c79356b A |
20 | * |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
24 | /* | |
25 | * Copyright (c) 1982, 1986, 1989, 1993 | |
26 | * The Regents of the University of California. All rights reserved. | |
27 | * | |
28 | * Redistribution and use in source and binary forms, with or without | |
29 | * modification, are permitted provided that the following conditions | |
30 | * are met: | |
31 | * 1. Redistributions of source code must retain the above copyright | |
32 | * notice, this list of conditions and the following disclaimer. | |
33 | * 2. Redistributions in binary form must reproduce the above copyright | |
34 | * notice, this list of conditions and the following disclaimer in the | |
35 | * documentation and/or other materials provided with the distribution. | |
36 | * 3. All advertising materials mentioning features or use of this software | |
37 | * must display the following acknowledgement: | |
38 | * This product includes software developed by the University of | |
39 | * California, Berkeley and its contributors. | |
40 | * 4. Neither the name of the University nor the names of its contributors | |
41 | * may be used to endorse or promote products derived from this software | |
42 | * without specific prior written permission. | |
43 | * | |
44 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
45 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
46 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
47 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
48 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
49 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
50 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
51 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
52 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
53 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
54 | * SUCH DAMAGE. | |
55 | * | |
56 | * @(#)ffs_subr.c 8.5 (Berkeley) 3/21/95 | |
57 | */ | |
58 | ||
59 | #include <rev_endian_fs.h> | |
60 | #include <sys/param.h> | |
61 | #if REV_ENDIAN_FS | |
91447636 | 62 | #include <sys/mount_internal.h> |
1c79356b A |
63 | #endif /* REV_ENDIAN_FS */ |
64 | ||
65 | #ifndef KERNEL | |
66 | #include <ufs/ufs/dinode.h> | |
67 | #include <ufs/ffs/fs.h> | |
68 | #else | |
69 | ||
70 | #include <sys/systm.h> | |
91447636 | 71 | #include <sys/vnode_internal.h> |
1c79356b | 72 | #include <sys/buf.h> |
9bccf70c | 73 | #include <sys/quota.h> |
1c79356b A |
74 | #include <ufs/ufs/quota.h> |
75 | #include <ufs/ufs/inode.h> | |
76 | #include <ufs/ffs/fs.h> | |
77 | #include <ufs/ffs/ffs_extern.h> | |
78 | #if REV_ENDIAN_FS | |
79 | #include <ufs/ufs/ufs_byte_order.h> | |
80 | #include <architecture/byte_order.h> | |
81 | #endif /* REV_ENDIAN_FS */ | |
82 | ||
83 | /* | |
84 | * Return buffer with the contents of block "offset" from the beginning of | |
85 | * directory "ip". If "res" is non-zero, fill it in with a pointer to the | |
86 | * remaining space in the directory. | |
87 | */ | |
91447636 | 88 | __private_extern__ |
1c79356b | 89 | int |
91447636 | 90 | ffs_blkatoff(vnode_t vp, off_t offset, char **res, buf_t *bpp) |
1c79356b A |
91 | { |
92 | struct inode *ip; | |
93 | register struct fs *fs; | |
94 | struct buf *bp; | |
95 | ufs_daddr_t lbn; | |
96 | int bsize, error; | |
97 | #if REV_ENDIAN_FS | |
91447636 | 98 | struct mount *mp = vnode_mount(vp); |
1c79356b A |
99 | int rev_endian=(mp->mnt_flag & MNT_REVEND); |
100 | #endif /* REV_ENDIAN_FS */ | |
101 | ||
91447636 | 102 | ip = VTOI(vp); |
1c79356b | 103 | fs = ip->i_fs; |
91447636 | 104 | lbn = lblkno(fs, offset); |
1c79356b A |
105 | bsize = blksize(fs, ip, lbn); |
106 | ||
91447636 A |
107 | *bpp = NULL; |
108 | if (error = (int)buf_bread(vp, (daddr64_t)((unsigned)lbn), bsize, NOCRED, &bp)) { | |
109 | buf_brelse(bp); | |
1c79356b A |
110 | return (error); |
111 | } | |
112 | #if REV_ENDIAN_FS | |
113 | if (rev_endian) | |
91447636 | 114 | byte_swap_dir_block_in((char *)buf_dataptr(bp), buf_count(bp)); |
1c79356b A |
115 | #endif /* REV_ENDIAN_FS */ |
116 | ||
91447636 A |
117 | if (res) |
118 | *res = (char *)buf_dataptr(bp) + blkoff(fs, offset); | |
119 | *bpp = bp; | |
1c79356b A |
120 | return (0); |
121 | } | |
122 | #endif | |
123 | ||
124 | /* | |
125 | * Update the frsum fields to reflect addition or deletion | |
126 | * of some frags. | |
127 | */ | |
128 | void | |
129 | ffs_fragacct(fs, fragmap, fraglist, cnt) | |
130 | struct fs *fs; | |
131 | int fragmap; | |
132 | int32_t fraglist[]; | |
133 | int cnt; | |
134 | { | |
135 | int inblk; | |
136 | register int field, subfield; | |
137 | register int siz, pos; | |
138 | ||
139 | inblk = (int)(fragtbl[fs->fs_frag][fragmap]) << 1; | |
140 | fragmap <<= 1; | |
141 | for (siz = 1; siz < fs->fs_frag; siz++) { | |
142 | if ((inblk & (1 << (siz + (fs->fs_frag % NBBY)))) == 0) | |
143 | continue; | |
144 | field = around[siz]; | |
145 | subfield = inside[siz]; | |
146 | for (pos = siz; pos <= fs->fs_frag; pos++) { | |
147 | if ((fragmap & field) == subfield) { | |
148 | fraglist[siz] += cnt; | |
149 | pos += siz; | |
150 | field <<= siz; | |
151 | subfield <<= siz; | |
152 | } | |
153 | field <<= 1; | |
154 | subfield <<= 1; | |
155 | } | |
156 | } | |
157 | } | |
158 | ||
1c79356b A |
159 | /* |
160 | * block operations | |
161 | * | |
162 | * check if a block is available | |
163 | */ | |
164 | int | |
165 | ffs_isblock(fs, cp, h) | |
166 | struct fs *fs; | |
167 | unsigned char *cp; | |
168 | ufs_daddr_t h; | |
169 | { | |
170 | unsigned char mask; | |
171 | ||
172 | switch ((int)fs->fs_frag) { | |
173 | case 8: | |
174 | return (cp[h] == 0xff); | |
175 | case 4: | |
176 | mask = 0x0f << ((h & 0x1) << 2); | |
177 | return ((cp[h >> 1] & mask) == mask); | |
178 | case 2: | |
179 | mask = 0x03 << ((h & 0x3) << 1); | |
180 | return ((cp[h >> 2] & mask) == mask); | |
181 | case 1: | |
182 | mask = 0x01 << (h & 0x7); | |
183 | return ((cp[h >> 3] & mask) == mask); | |
184 | default: | |
185 | panic("ffs_isblock"); | |
186 | } | |
91447636 A |
187 | /* NOTREACHED */ |
188 | return 0; | |
1c79356b A |
189 | } |
190 | ||
191 | /* | |
192 | * take a block out of the map | |
193 | */ | |
194 | void | |
195 | ffs_clrblock(fs, cp, h) | |
196 | struct fs *fs; | |
197 | u_char *cp; | |
198 | ufs_daddr_t h; | |
199 | { | |
200 | ||
201 | switch ((int)fs->fs_frag) { | |
202 | case 8: | |
203 | cp[h] = 0; | |
204 | return; | |
205 | case 4: | |
206 | cp[h >> 1] &= ~(0x0f << ((h & 0x1) << 2)); | |
207 | return; | |
208 | case 2: | |
209 | cp[h >> 2] &= ~(0x03 << ((h & 0x3) << 1)); | |
210 | return; | |
211 | case 1: | |
212 | cp[h >> 3] &= ~(0x01 << (h & 0x7)); | |
213 | return; | |
214 | default: | |
215 | panic("ffs_clrblock"); | |
216 | } | |
217 | } | |
218 | ||
219 | /* | |
220 | * put a block into the map | |
221 | */ | |
222 | void | |
223 | ffs_setblock(fs, cp, h) | |
224 | struct fs *fs; | |
225 | unsigned char *cp; | |
226 | ufs_daddr_t h; | |
227 | { | |
228 | ||
229 | switch ((int)fs->fs_frag) { | |
230 | ||
231 | case 8: | |
232 | cp[h] = 0xff; | |
233 | return; | |
234 | case 4: | |
235 | cp[h >> 1] |= (0x0f << ((h & 0x1) << 2)); | |
236 | return; | |
237 | case 2: | |
238 | cp[h >> 2] |= (0x03 << ((h & 0x3) << 1)); | |
239 | return; | |
240 | case 1: | |
241 | cp[h >> 3] |= (0x01 << (h & 0x7)); | |
242 | return; | |
243 | default: | |
244 | panic("ffs_setblock"); | |
245 | } | |
246 | } |