1 /***********************************************************************
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 *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
24 * aux function for <ls.h> iblocks() macro
26 * return number of blocks, including indirect block count
29 * mail gsf@research.att.com when you figure out the stat.st_blocks units
30 * until then we assume LS_BLOCKSIZE (512)
39 #include <ast_param.h>
42 #if !_mem_st_blocks_stat
50 #define B_SIZE BSIZE(st->st_dev)
51 #define B_INDIRECT NINDIR(st->st_dev)
62 #define B_INDIRECT NINDIR
64 #define B_INDIRECT 128
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
;
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
)
93 return t
* B_SIZE
/ LS_BLOCKSIZE
;