4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/sysmacros.h>
36 * This should not be a constant, but for ufs it is 12, not 10 like for s5.
38 #define DIRECT 12 /* Number of logical blocks before indirection */
41 nblk(fsblkcnt_t size
, ulong_t bsize
, ulong_t frsize
)
43 fsblkcnt_t tot
, count
, count1
, d_indirect
, t_indirect
, ind
;
46 if (size
== 0 || bsize
== 0)
50 * Need to keep track of indirect blocks.
53 ind
= howmany(bsize
, sizeof (daddr_t
));
54 d_indirect
= ind
+ DIRECT
; /* double indirection */
55 t_indirect
= ind
* (ind
+ 1) + DIRECT
; /* triple indirection */
57 tot
= howmany(size
, bsize
);
59 if (tot
> t_indirect
) {
60 count1
= (tot
- ind
* ind
- (DIRECT
+ 1)) / ind
;
61 count
= count1
+ count1
/ ind
+ ind
+ 3;
62 } else if (tot
> d_indirect
) {
63 count
= (tot
- (DIRECT
+ 1)) / ind
+ 2;
64 } else if (tot
> DIRECT
) {
68 frags
= (frsize
> 0) ?
69 roundup(size
, frsize
) :
73 /* Accounting for the indirect blocks, the total becomes */
77 * calculate number of 512 byte blocks, for frag or full block cases.
80 tot
*= howmany(bsize
, DEV_BSIZE
);
82 tot
= howmany(frags
, DEV_BSIZE
);