home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / futils / futils~1 / src / file31s.zoo / file3.1 / lib / filebloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-18  |  1.5 KB  |  54 lines

  1. /* Convert file size to number of blocks on System V-like machines.
  2.    Copyright (C) 1990 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* Written by Brian L. Matthews, blm@6sceng.UUCP. */
  19.  
  20. #if defined (ST_BLOCKS_MISSING) && !defined(_POSIX_SOURCE)
  21. #include <sys/types.h>
  22. #include <sys/param.h>
  23.  
  24. /* Number of direct block addresses in an inode. */
  25. #define NDIR    10
  26.  
  27. /* Return the number of 512-byte blocks in a file of SIZE bytes. */
  28.  
  29. long
  30. st_blocks (size)
  31.      long size;
  32. {
  33.   long datablks = (size + 512 - 1) / 512;
  34.   long indrblks = 0;
  35.  
  36. #ifndef __atarist__
  37.   if (datablks > NDIR)
  38.     {
  39.       indrblks = (datablks - NDIR - 1) / NINDIR + 1;
  40.  
  41.       if (datablks > NDIR + NINDIR)
  42.     {
  43.       indrblks += (datablks - NDIR - NINDIR - 1) / (NINDIR * NINDIR) + 1;
  44.  
  45.       if (datablks > NDIR + NINDIR + NINDIR * NINDIR)
  46.         indrblks++;
  47.     }
  48.     }
  49. #endif
  50.  
  51.   return datablks + indrblks;
  52. }
  53. #endif
  54.