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