dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libast / common / port / iblocks.c
blob07cea73b86d1a287e6eb2164c651ede735cd7f9e
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
24 * aux function for <ls.h> iblocks() macro
26 * return number of blocks, including indirect block count
27 * given stat info
29 * mail gsf@research.att.com when you figure out the stat.st_blocks units
30 * until then we assume LS_BLOCKSIZE (512)
33 #include <ast.h>
34 #if _AIX /* XXX */
35 #undef major
36 #undef minor
37 #undef makedev
38 #endif
39 #include <ast_param.h>
40 #include <ls.h>
42 #if !_mem_st_blocks_stat
44 #ifndef B_DIRECT
45 #define B_DIRECT 10
46 #endif
48 #ifdef BITFS
50 #define B_SIZE BSIZE(st->st_dev)
51 #define B_INDIRECT NINDIR(st->st_dev)
53 #else
55 #ifdef BSIZE
56 #define B_SIZE BSIZE
57 #else
58 #define B_SIZE 1024
59 #endif
61 #ifdef NINDIR
62 #define B_INDIRECT NINDIR
63 #else
64 #define B_INDIRECT 128
65 #endif
67 #endif
69 #endif
71 off_t
72 _iblocks(register struct stat* st)
74 #if _mem_st_blocks_stat
76 return (st->st_blocks <= 0 || st->st_size <= 0) ? 0 : st->st_blocks;
78 #else
79 unsigned long b;
80 unsigned long t;
82 t = b = (st->st_size + B_SIZE - 1) / B_SIZE;
83 if ((b -= B_DIRECT) > 0)
85 t += (b - 1) / B_INDIRECT + 1;
86 if ((b -= B_INDIRECT) > 0)
88 t += (b - 1) / (B_INDIRECT * B_INDIRECT) + 1;
89 if (b > B_INDIRECT * B_INDIRECT)
90 t++;
93 return t * B_SIZE / LS_BLOCKSIZE;
94 #endif