1 /* Convert file size to number of blocks on System V-like machines.
3 Copyright (C) 1990, 1997, 1998, 1999, 2004 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 /* Written by Brian L. Matthews, blm@6sceng.UUCP. */
25 #include <sys/types.h>
28 # include <sys/param.h>
31 #if !HAVE_STRUCT_STAT_ST_BLOCKS && !defined _POSIX_SOURCE && defined BSIZE
39 # if defined (__DJGPP__)
40 typedef long daddr_t; /* for disk address */
43 /* Some SysV's, like Irix, seem to lack this. Hope it's correct. */
44 /* Number of inode pointers per indirect block. */
45 # define NINDIR (BSIZE / sizeof (daddr_t))
48 /* Number of direct block addresses in an inode. */
51 /* Return the number of 512-byte blocks in a file of SIZE bytes. */
54 st_blocks (off_t size)
56 off_t datablks = size / 512 + (size % 512 != 0);
61 indrblks = (datablks - NDIR - 1) / NINDIR + 1;
63 if (datablks > NDIR + NINDIR)
65 indrblks += (datablks - NDIR - NINDIR - 1) / (NINDIR * NINDIR) + 1;
67 if (datablks > NDIR + NINDIR + NINDIR * NINDIR)
72 return datablks + indrblks;
75 /* This declaration is solely to ensure that after preprocessing
76 this file is never empty. */
77 typedef int textutils_fileblocks_unused;