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