Mercurial > hg > octave-jordi > gnulib-hg
annotate lib/fileblocks.c @ 439:a9015d648b2e
No longer include safe-l?stat.h.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Fri, 19 May 1995 15:23:18 +0000 |
parents | f9fa66a3a613 |
children | 89a4657bb64a |
rev | line source |
---|---|
5 | 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 | |
163
4aeea06507af
[!NINDIR]: Define BSIZE only if it's not already defined.
Jim Meyering <jim@meyering.net>
parents:
5
diff
changeset
|
20 #ifdef HAVE_CONFIG_H |
4aeea06507af
[!NINDIR]: Define BSIZE only if it's not already defined.
Jim Meyering <jim@meyering.net>
parents:
5
diff
changeset
|
21 #include <config.h> |
4aeea06507af
[!NINDIR]: Define BSIZE only if it's not already defined.
Jim Meyering <jim@meyering.net>
parents:
5
diff
changeset
|
22 #endif |
4aeea06507af
[!NINDIR]: Define BSIZE only if it's not already defined.
Jim Meyering <jim@meyering.net>
parents:
5
diff
changeset
|
23 |
5 | 24 #if !defined (HAVE_ST_BLOCKS) && !defined(_POSIX_SOURCE) |
25 #include <sys/types.h> | |
26 #include <sys/param.h> | |
27 | |
28 #ifndef NINDIR | |
29 /* Some SysV's, like Irix, seem to lack these. Hope they're correct. */ | |
30 /* Size of a indirect block, in bytes. */ | |
163
4aeea06507af
[!NINDIR]: Define BSIZE only if it's not already defined.
Jim Meyering <jim@meyering.net>
parents:
5
diff
changeset
|
31 #ifndef BSIZE |
5 | 32 #define BSIZE 1024 |
163
4aeea06507af
[!NINDIR]: Define BSIZE only if it's not already defined.
Jim Meyering <jim@meyering.net>
parents:
5
diff
changeset
|
33 #endif |
5 | 34 |
35 /* Number of inode pointers per indirect block. */ | |
36 #define NINDIR (BSIZE/sizeof(daddr_t)) | |
37 #endif /* !NINDIR */ | |
38 | |
39 /* Number of direct block addresses in an inode. */ | |
40 #define NDIR 10 | |
41 | |
42 /* Return the number of 512-byte blocks in a file of SIZE bytes. */ | |
43 | |
44 long | |
45 st_blocks (size) | |
46 long size; | |
47 { | |
48 long datablks = (size + 512 - 1) / 512; | |
49 long indrblks = 0; | |
50 | |
51 if (datablks > NDIR) | |
52 { | |
53 indrblks = (datablks - NDIR - 1) / NINDIR + 1; | |
54 | |
55 if (datablks > NDIR + NINDIR) | |
56 { | |
57 indrblks += (datablks - NDIR - NINDIR - 1) / (NINDIR * NINDIR) + 1; | |
58 | |
59 if (datablks > NDIR + NINDIR + NINDIR * NINDIR) | |
60 indrblks++; | |
61 } | |
62 } | |
63 | |
64 return datablks + indrblks; | |
65 } | |
66 #endif |