diff options
author | Igor Pashev <pashev.igor@gmail.com> | 2012-06-24 22:28:35 +0000 |
---|---|---|
committer | Igor Pashev <pashev.igor@gmail.com> | 2012-06-24 22:28:35 +0000 |
commit | 3950ffe2a485479f6561c27364d3d7df5a21d124 (patch) | |
tree | 468c6e14449d1b1e279222ec32f676b0311917d2 /src/lib/libast/port/iblocks.c | |
download | ksh-upstream.tar.gz |
Imported Upstream version 93u+upstream
Diffstat (limited to 'src/lib/libast/port/iblocks.c')
-rw-r--r-- | src/lib/libast/port/iblocks.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/lib/libast/port/iblocks.c b/src/lib/libast/port/iblocks.c new file mode 100644 index 0000000..a768b84 --- /dev/null +++ b/src/lib/libast/port/iblocks.c @@ -0,0 +1,95 @@ +/*********************************************************************** +* * +* This software is part of the ast package * +* Copyright (c) 1985-2011 AT&T Intellectual Property * +* and is licensed under the * +* Eclipse Public License, Version 1.0 * +* by AT&T Intellectual Property * +* * +* A copy of the License is available at * +* http://www.eclipse.org/org/documents/epl-v10.html * +* (with md5 checksum b35adb5213ca9657e911e9befb180842) * +* * +* 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 +} |