]>
git.saurik.com Git - apple/xnu.git/blob - bsd/ufs/ffs/ffs_subr.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
25 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
27 * Copyright (c) 1982, 1986, 1989, 1993
28 * The Regents of the University of California. All rights reserved.
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * @(#)ffs_subr.c 8.5 (Berkeley) 3/21/95
61 #include <rev_endian_fs.h>
62 #include <sys/param.h>
64 #include <sys/mount.h>
65 #endif /* REV_ENDIAN_FS */
68 #include <ufs/ufs/dinode.h>
69 #include <ufs/ffs/fs.h>
72 #include <sys/systm.h>
73 #include <sys/vnode.h>
75 #include <sys/quota.h>
76 #include <ufs/ufs/quota.h>
77 #include <ufs/ufs/inode.h>
78 #include <ufs/ffs/fs.h>
79 #include <ufs/ffs/ffs_extern.h>
81 #include <ufs/ufs/ufs_byte_order.h>
82 #include <architecture/byte_order.h>
83 #endif /* REV_ENDIAN_FS */
86 * Return buffer with the contents of block "offset" from the beginning of
87 * directory "ip". If "res" is non-zero, fill it in with a pointer to the
88 * remaining space in the directory.
92 struct vop_blkatoff_args
/* {
100 register struct fs
*fs
;
105 struct mount
*mp
=(ap
->a_vp
)->v_mount
;
106 int rev_endian
=(mp
->mnt_flag
& MNT_REVEND
);
107 #endif /* REV_ENDIAN_FS */
111 lbn
= lblkno(fs
, ap
->a_offset
);
112 bsize
= blksize(fs
, ip
, lbn
);
115 if (error
= bread(ap
->a_vp
, lbn
, bsize
, NOCRED
, &bp
)) {
121 byte_swap_dir_block_in(bp
->b_data
, bp
->b_bcount
);
122 #endif /* REV_ENDIAN_FS */
125 *ap
->a_res
= (char *)bp
->b_data
+ blkoff(fs
, ap
->a_offset
);
132 * Update the frsum fields to reflect addition or deletion
136 ffs_fragacct(fs
, fragmap
, fraglist
, cnt
)
143 register int field
, subfield
;
144 register int siz
, pos
;
146 inblk
= (int)(fragtbl
[fs
->fs_frag
][fragmap
]) << 1;
148 for (siz
= 1; siz
< fs
->fs_frag
; siz
++) {
149 if ((inblk
& (1 << (siz
+ (fs
->fs_frag
% NBBY
)))) == 0)
152 subfield
= inside
[siz
];
153 for (pos
= siz
; pos
<= fs
->fs_frag
; pos
++) {
154 if ((fragmap
& field
) == subfield
) {
155 fraglist
[siz
] += cnt
;
166 #if defined(KERNEL) && DIAGNOSTIC
168 ffs_checkoverlap(bp
, ip
)
172 register struct buf
*ebp
, *ep
;
173 register ufs_daddr_t start
, last
;
182 VOP_DEVBLOCKSIZE(ip
->i_devvp
,&devBlockSize
);
183 last
= start
+ btodb(bp
->b_bcount
, devBlockSize
) - 1;
185 last
= start
+ btodb(bp
->b_bcount
) - 1;
187 for (ep
= buf
; ep
< ebp
; ep
++) {
188 if (ep
== bp
|| (ep
->b_flags
& B_INVAL
) ||
191 if (VOP_BMAP(ep
->b_vp
, (ufs_daddr_t
)0, &vp
, (ufs_daddr_t
)0,
194 if (vp
!= ip
->i_devvp
)
196 /* look for overlap */
198 if (ep
->b_bcount
== 0 || ep
->b_blkno
> last
||
199 ep
->b_blkno
+ btodb(ep
->b_bcount
, devBlockSize
) <= start
)
201 vprint("Disk overlap", vp
);
202 (void)printf("\tstart %d, end %d overlap start %d, end %d\n",
203 start
, last
, ep
->b_blkno
,
204 ep
->b_blkno
+ btodb(ep
->b_bcount
, devBlockSize
) - 1);
206 if (ep
->b_bcount
== 0 || ep
->b_blkno
> last
||
207 ep
->b_blkno
+ btodb(ep
->b_bcount
) <= start
)
209 vprint("Disk overlap", vp
);
210 (void)printf("\tstart %d, end %d overlap start %d, end %d\n",
211 start
, last
, ep
->b_blkno
,
212 ep
->b_blkno
+ btodb(ep
->b_bcount
) - 1);
214 panic("Disk buffer overlap");
217 #endif /* DIAGNOSTIC */
222 * check if a block is available
225 ffs_isblock(fs
, cp
, h
)
232 switch ((int)fs
->fs_frag
) {
234 return (cp
[h
] == 0xff);
236 mask
= 0x0f << ((h
& 0x1) << 2);
237 return ((cp
[h
>> 1] & mask
) == mask
);
239 mask
= 0x03 << ((h
& 0x3) << 1);
240 return ((cp
[h
>> 2] & mask
) == mask
);
242 mask
= 0x01 << (h
& 0x7);
243 return ((cp
[h
>> 3] & mask
) == mask
);
245 panic("ffs_isblock");
250 * take a block out of the map
253 ffs_clrblock(fs
, cp
, h
)
259 switch ((int)fs
->fs_frag
) {
264 cp
[h
>> 1] &= ~(0x0f << ((h
& 0x1) << 2));
267 cp
[h
>> 2] &= ~(0x03 << ((h
& 0x3) << 1));
270 cp
[h
>> 3] &= ~(0x01 << (h
& 0x7));
273 panic("ffs_clrblock");
278 * put a block into the map
281 ffs_setblock(fs
, cp
, h
)
287 switch ((int)fs
->fs_frag
) {
293 cp
[h
>> 1] |= (0x0f << ((h
& 0x1) << 2));
296 cp
[h
>> 2] |= (0x03 << ((h
& 0x3) << 1));
299 cp
[h
>> 3] |= (0x01 << (h
& 0x7));
302 panic("ffs_setblock");