]> git.cworth.org Git - tar/blob - gnu/fileblocks.c
upstream: Fix extraction of device nodes.
[tar] / gnu / fileblocks.c
1 /* -*- buffer-read-only: t -*- vi: set ro: */
2 /* DO NOT EDIT! GENERATED AUTOMATICALLY! */
3 /* Convert file size to number of blocks on System V-like machines.
4
5    Copyright (C) 1990, 1997-1999, 2004-2006, 2009-2010 Free Software
6    Foundation, Inc.
7
8    This program is free software: you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
21 /* Written by Brian L. Matthews, blm@6sceng.UUCP. */
22
23 #include <config.h>
24
25 #include <sys/types.h>
26
27 #if HAVE_SYS_PARAM_H
28 # include <sys/param.h>
29 #endif
30
31 #if !HAVE_STRUCT_STAT_ST_BLOCKS && !defined _POSIX_SOURCE && defined BSIZE
32
33 # include <unistd.h>
34
35 # ifndef NINDIR
36
37 #  if defined __DJGPP__
38 typedef long daddr_t; /* for disk address */
39 #  endif
40
41 /* Some SysV's, like Irix, seem to lack this.  Hope it's correct. */
42 /* Number of inode pointers per indirect block. */
43 #  define NINDIR (BSIZE / sizeof (daddr_t))
44 # endif /* !NINDIR */
45
46 /* Number of direct block addresses in an inode. */
47 # define NDIR   10
48
49 /* Return the number of 512-byte blocks in a file of SIZE bytes. */
50
51 off_t
52 st_blocks (off_t size)
53 {
54   off_t datablks = size / 512 + (size % 512 != 0);
55   off_t indrblks = 0;
56
57   if (datablks > NDIR)
58     {
59       indrblks = (datablks - NDIR - 1) / NINDIR + 1;
60
61       if (datablks > NDIR + NINDIR)
62         {
63           indrblks += (datablks - NDIR - NINDIR - 1) / (NINDIR * NINDIR) + 1;
64
65           if (datablks > NDIR + NINDIR + NINDIR * NINDIR)
66             indrblks++;
67         }
68     }
69
70   return datablks + indrblks;
71 }
72 #else
73 /* This declaration is solely to ensure that after preprocessing
74    this file is never empty.  */
75 typedef int textutils_fileblocks_unused;
76 #endif