1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* Phong Vo <kpv@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A/*
1N/A * aux function for <ls.h> iblocks() macro
1N/A *
1N/A * return number of blocks, including indirect block count
1N/A * given stat info
1N/A *
1N/A * mail gsf@research.att.com when you figure out the stat.st_blocks units
1N/A * until then we assume LS_BLOCKSIZE (512)
1N/A */
1N/A
1N/A#include <ast.h>
1N/A#if _AIX /* XXX */
1N/A#undef major
1N/A#undef minor
1N/A#undef makedev
1N/A#endif
1N/A#include <ast_param.h>
1N/A#include <ls.h>
1N/A
1N/A#if !_mem_st_blocks_stat
1N/A
1N/A#ifndef B_DIRECT
1N/A#define B_DIRECT 10
1N/A#endif
1N/A
1N/A#ifdef BITFS
1N/A
1N/A#define B_SIZE BSIZE(st->st_dev)
1N/A#define B_INDIRECT NINDIR(st->st_dev)
1N/A
1N/A#else
1N/A
1N/A#ifdef BSIZE
1N/A#define B_SIZE BSIZE
1N/A#else
1N/A#define B_SIZE 1024
1N/A#endif
1N/A
1N/A#ifdef NINDIR
1N/A#define B_INDIRECT NINDIR
1N/A#else
1N/A#define B_INDIRECT 128
1N/A#endif
1N/A
1N/A#endif
1N/A
1N/A#endif
1N/A
1N/Aoff_t
1N/A_iblocks(register struct stat* st)
1N/A{
1N/A#if _mem_st_blocks_stat
1N/A
1N/A return (st->st_blocks <= 0 || st->st_size <= 0) ? 0 : st->st_blocks;
1N/A
1N/A#else
1N/A unsigned long b;
1N/A unsigned long t;
1N/A
1N/A t = b = (st->st_size + B_SIZE - 1) / B_SIZE;
1N/A if ((b -= B_DIRECT) > 0)
1N/A {
1N/A t += (b - 1) / B_INDIRECT + 1;
1N/A if ((b -= B_INDIRECT) > 0)
1N/A {
1N/A t += (b - 1) / (B_INDIRECT * B_INDIRECT) + 1;
1N/A if (b > B_INDIRECT * B_INDIRECT)
1N/A t++;
1N/A }
1N/A }
1N/A return t * B_SIZE / LS_BLOCKSIZE;
1N/A#endif
1N/A}