Mercurial > hg > octave-kai > gnulib-hg
annotate lib/fsusage.c @ 17249:e542fd46ad6f
maint: update all copyright year number ranges
Run "make update-copyright". Compare to commit 1602f0a from last year.
Signed-off-by: Eric Blake <eblake@redhat.com>
author | Eric Blake <eblake@redhat.com> |
---|---|
date | Tue, 01 Jan 2013 00:50:58 +0000 |
parents | 9fc45cd5d9b5 |
children |
rev | line source |
---|---|
5159 | 1 /* fsusage.c -- return space usage of mounted file systems |
4333 | 2 |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
17000
diff
changeset
|
3 Copyright (C) 1991-1992, 1996, 1998-1999, 2002-2006, 2009-2013 Free Software |
12518
b5e42ef33b49
update nearly all FSF copyright year lists to include 2009
Jim Meyering <meyering@redhat.com>
parents:
12421
diff
changeset
|
4 Foundation, Inc. |
5 | 5 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7863
diff
changeset
|
6 This program is free software: you can redistribute it and/or modify |
5 | 7 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7863
diff
changeset
|
8 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7863
diff
changeset
|
9 (at your option) any later version. |
5 | 10 |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
7863
diff
changeset
|
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
5 | 18 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6912
diff
changeset
|
19 #include <config.h> |
105 | 20 |
5 | 21 #include "fsusage.h" |
22 | |
4333 | 23 #include <limits.h> |
6912 | 24 #include <sys/types.h> |
76 | 25 |
15449
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
26 #if STAT_STATVFS || STAT_STATVFS64 /* POSIX 1003.1-2001 (and later) with XSI */ |
6912 | 27 # include <sys/statvfs.h> |
28 #else | |
29 /* Don't include backward-compatibility files unless they're needed. | |
30 Eventually we'd like to remove all this cruft. */ | |
31 # include <fcntl.h> | |
32 # include <unistd.h> | |
33 # include <sys/stat.h> | |
16961
1ba5ea17c907
fsusage: remove code not needed on non GNU/Linux systems.
Pádraig Brady <P@draigBrady.com>
parents:
16960
diff
changeset
|
34 #if HAVE_SYS_PARAM_H |
1ba5ea17c907
fsusage: remove code not needed on non GNU/Linux systems.
Pádraig Brady <P@draigBrady.com>
parents:
16960
diff
changeset
|
35 # include <sys/param.h> |
1ba5ea17c907
fsusage: remove code not needed on non GNU/Linux systems.
Pádraig Brady <P@draigBrady.com>
parents:
16960
diff
changeset
|
36 #endif |
1ba5ea17c907
fsusage: remove code not needed on non GNU/Linux systems.
Pádraig Brady <P@draigBrady.com>
parents:
16960
diff
changeset
|
37 #if HAVE_SYS_MOUNT_H |
1ba5ea17c907
fsusage: remove code not needed on non GNU/Linux systems.
Pádraig Brady <P@draigBrady.com>
parents:
16960
diff
changeset
|
38 # include <sys/mount.h> |
1ba5ea17c907
fsusage: remove code not needed on non GNU/Linux systems.
Pádraig Brady <P@draigBrady.com>
parents:
16960
diff
changeset
|
39 #endif |
1ba5ea17c907
fsusage: remove code not needed on non GNU/Linux systems.
Pádraig Brady <P@draigBrady.com>
parents:
16960
diff
changeset
|
40 #if HAVE_SYS_VFS_H |
1ba5ea17c907
fsusage: remove code not needed on non GNU/Linux systems.
Pádraig Brady <P@draigBrady.com>
parents:
16960
diff
changeset
|
41 # include <sys/vfs.h> |
1ba5ea17c907
fsusage: remove code not needed on non GNU/Linux systems.
Pádraig Brady <P@draigBrady.com>
parents:
16960
diff
changeset
|
42 #endif |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
43 # if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */ |
6912 | 44 # include <sys/fs/s5param.h> |
45 # endif | |
46 # if defined HAVE_SYS_FILSYS_H && !defined _CRAY | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
47 # include <sys/filsys.h> /* SVR2 */ |
6912 | 48 # endif |
49 # if HAVE_SYS_STATFS_H | |
50 # include <sys/statfs.h> | |
51 # endif | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
52 # if HAVE_DUSTAT_H /* AIX PS/2 */ |
6912 | 53 # include <sys/dustat.h> |
54 # endif | |
55 # include "full-read.h" | |
669
20030d56c4ac
[HAVE_SYS_FS_S5PARAM_H]: Include sys/fs/s5param.h
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
56 #endif |
20030d56c4ac
[HAVE_SYS_FS_S5PARAM_H]: Include sys/fs/s5param.h
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
57 |
7863 | 58 /* The results of open() in this file are not used with fchdir, |
59 therefore save some unnecessary work in fchdir.c. */ | |
60 #undef open | |
61 #undef close | |
62 | |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
63 /* Many space usage primitives use all 1 bits to denote a value that is |
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
64 not applicable or unknown. Propagate this information by returning |
3994
504d447035d2
2002-09-25 Paul Eggert <eggert@twinsun.com>
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
65 a uintmax_t value that is all 1 bits if X is all 1 bits, even if X |
504d447035d2
2002-09-25 Paul Eggert <eggert@twinsun.com>
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
66 is unsigned and narrower than uintmax_t. */ |
504d447035d2
2002-09-25 Paul Eggert <eggert@twinsun.com>
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
67 #define PROPAGATE_ALL_ONES(x) \ |
7508
43875a037a03
Remove unnecessary part of previous change.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7507
diff
changeset
|
68 ((sizeof (x) < sizeof (uintmax_t) \ |
3994
504d447035d2
2002-09-25 Paul Eggert <eggert@twinsun.com>
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
69 && (~ (x) == (sizeof (x) < sizeof (int) \ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
70 ? - (1 << (sizeof (x) * CHAR_BIT)) \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
71 : 0))) \ |
7507
bfd8f6c918c9
* lib/fsusage.c (PROPAGATE_ALL_ONES): Don't assume uintmax_t is
Paul Eggert <eggert@cs.ucla.edu>
parents:
7406
diff
changeset
|
72 ? UINTMAX_MAX : (uintmax_t) (x)) |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
73 |
1281 | 74 /* Extract the top bit of X as an uintmax_t value. */ |
75 #define EXTRACT_TOP_BIT(x) ((x) \ | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
76 & ((uintmax_t) 1 << (sizeof (x) * CHAR_BIT - 1))) |
1281 | 77 |
78 /* If a value is negative, many space usage primitives store it into an | |
79 integer variable by assignment, even if the variable's type is unsigned. | |
80 So, if a space usage variable X's top bit is set, convert X to the | |
81 uintmax_t value V such that (- (uintmax_t) V) is the negative of | |
82 the original value. If X's top bit is clear, just yield X. | |
83 Use PROPAGATE_TOP_BIT if the original value might be negative; | |
84 otherwise, use PROPAGATE_ALL_ONES. */ | |
85 #define PROPAGATE_TOP_BIT(x) ((x) | ~ (EXTRACT_TOP_BIT (x) - 1)) | |
86 | |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
87 #ifdef STAT_STATVFS |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
88 /* Return true if statvfs works. This is false for statvfs on systems |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
89 with GNU libc on Linux kernels before 2.6.36, which stats all |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
90 preceding entries in /proc/mounts; that makes df hang if even one |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
91 of the corresponding file systems is hard-mounted but not available. */ |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
92 # if ! (__linux__ && (__GLIBC__ || __UCLIBC__)) |
16961
1ba5ea17c907
fsusage: remove code not needed on non GNU/Linux systems.
Pádraig Brady <P@draigBrady.com>
parents:
16960
diff
changeset
|
93 /* The FRSIZE fallback is not required in this case. */ |
1ba5ea17c907
fsusage: remove code not needed on non GNU/Linux systems.
Pádraig Brady <P@draigBrady.com>
parents:
16960
diff
changeset
|
94 # undef STAT_STATFS2_FRSIZE |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
95 static int statvfs_works (void) { return 1; } |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
96 # else |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
97 # include <string.h> /* for strverscmp */ |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
98 # include <sys/utsname.h> |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
99 # include <sys/statfs.h> |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
100 # define STAT_STATFS2_BSIZE 1 |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
101 |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
102 static int |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
103 statvfs_works (void) |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
104 { |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
105 static int statvfs_works_cache = -1; |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
106 struct utsname name; |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
107 if (statvfs_works_cache < 0) |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
108 statvfs_works_cache = (uname (&name) == 0 |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
109 && 0 <= strverscmp (name.release, "2.6.36")); |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
110 return statvfs_works_cache; |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
111 } |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
112 # endif |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
113 #endif |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
114 |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
115 |
5 | 116 /* Fill in the fields of FSP with information about space usage for |
5907 | 117 the file system on which FILE resides. |
118 DISK is the device on which FILE is mounted, for space-getting | |
5 | 119 methods that need to know it. |
793
d257c9ac0e72
(get_fs_usage): If DISK is 0 and we needed to use
Jim Meyering <jim@meyering.net>
parents:
780
diff
changeset
|
120 Return 0 if successful, -1 if not. When returning -1, ensure that |
d257c9ac0e72
(get_fs_usage): If DISK is 0 and we needed to use
Jim Meyering <jim@meyering.net>
parents:
780
diff
changeset
|
121 ERRNO is either a system error value, or zero if DISK is NULL |
d257c9ac0e72
(get_fs_usage): If DISK is 0 and we needed to use
Jim Meyering <jim@meyering.net>
parents:
780
diff
changeset
|
122 on a system that requires a non-NULL value. */ |
5 | 123 int |
11112
e7df8edd0e88
still avoid unused-parameter warnings, but do it cleanly
Jim Meyering <meyering@redhat.com>
parents:
11111
diff
changeset
|
124 get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) |
5 | 125 { |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
126 #ifdef STAT_STATVFS /* POSIX, except pre-2.6.36 glibc/Linux */ |
780 | 127 |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
128 if (statvfs_works ()) |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
129 { |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
130 struct statvfs vfsd; |
76 | 131 |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
132 if (statvfs (file, &vfsd) < 0) |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
133 return -1; |
780 | 134 |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
135 /* f_frsize isn't guaranteed to be supported. */ |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
136 fsp->fsu_blocksize = (vfsd.f_frsize |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
137 ? PROPAGATE_ALL_ONES (vfsd.f_frsize) |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
138 : PROPAGATE_ALL_ONES (vfsd.f_bsize)); |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
139 |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
140 fsp->fsu_blocks = PROPAGATE_ALL_ONES (vfsd.f_blocks); |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
141 fsp->fsu_bfree = PROPAGATE_ALL_ONES (vfsd.f_bfree); |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
142 fsp->fsu_bavail = PROPAGATE_TOP_BIT (vfsd.f_bavail); |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
143 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (vfsd.f_bavail) != 0; |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
144 fsp->fsu_files = PROPAGATE_ALL_ONES (vfsd.f_files); |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
145 fsp->fsu_ffree = PROPAGATE_ALL_ONES (vfsd.f_ffree); |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
146 return 0; |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
147 } |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
148 |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
149 #endif |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
150 |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
151 #if defined STAT_STATVFS64 /* AIX */ |
15449
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
152 |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
153 struct statvfs64 fsd; |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
154 |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
155 if (statvfs64 (file, &fsd) < 0) |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
156 return -1; |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
157 |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
158 /* f_frsize isn't guaranteed to be supported. */ |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
159 fsp->fsu_blocksize = (fsd.f_frsize |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
160 ? PROPAGATE_ALL_ONES (fsd.f_frsize) |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
161 : PROPAGATE_ALL_ONES (fsd.f_bsize)); |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
162 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
163 #elif defined STAT_STATFS2_FS_DATA /* Ultrix */ |
780 | 164 |
5 | 165 struct fs_data fsd; |
166 | |
5907 | 167 if (statfs (file, &fsd) != 1) |
5 | 168 return -1; |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
169 |
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
170 fsp->fsu_blocksize = 1024; |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
171 fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.fd_req.btot); |
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
172 fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.fd_req.bfree); |
1281 | 173 fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.fd_req.bfreen); |
174 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.fd_req.bfreen) != 0; | |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
175 fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot); |
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
176 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); |
5 | 177 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
178 #elif defined STAT_READ_FILSYS /* SVR2 */ |
774
2158edf8414e
cpp-indent + change some #ifdef to #if
Jim Meyering <jim@meyering.net>
parents:
670
diff
changeset
|
179 # ifndef SUPERBOFF |
2158edf8414e
cpp-indent + change some #ifdef to #if
Jim Meyering <jim@meyering.net>
parents:
670
diff
changeset
|
180 # define SUPERBOFF (SUPERB * 512) |
2158edf8414e
cpp-indent + change some #ifdef to #if
Jim Meyering <jim@meyering.net>
parents:
670
diff
changeset
|
181 # endif |
780 | 182 |
5 | 183 struct filsys fsd; |
184 int fd; | |
185 | |
793
d257c9ac0e72
(get_fs_usage): If DISK is 0 and we needed to use
Jim Meyering <jim@meyering.net>
parents:
780
diff
changeset
|
186 if (! disk) |
d257c9ac0e72
(get_fs_usage): If DISK is 0 and we needed to use
Jim Meyering <jim@meyering.net>
parents:
780
diff
changeset
|
187 { |
d257c9ac0e72
(get_fs_usage): If DISK is 0 and we needed to use
Jim Meyering <jim@meyering.net>
parents:
780
diff
changeset
|
188 errno = 0; |
d257c9ac0e72
(get_fs_usage): If DISK is 0 and we needed to use
Jim Meyering <jim@meyering.net>
parents:
780
diff
changeset
|
189 return -1; |
d257c9ac0e72
(get_fs_usage): If DISK is 0 and we needed to use
Jim Meyering <jim@meyering.net>
parents:
780
diff
changeset
|
190 } |
d257c9ac0e72
(get_fs_usage): If DISK is 0 and we needed to use
Jim Meyering <jim@meyering.net>
parents:
780
diff
changeset
|
191 |
5 | 192 fd = open (disk, O_RDONLY); |
193 if (fd < 0) | |
194 return -1; | |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
195 lseek (fd, (off_t) SUPERBOFF, 0); |
4087
1546b85827ac
Use full_read instead of safe_read.
Bruno Haible <bruno@clisp.org>
parents:
4010
diff
changeset
|
196 if (full_read (fd, (char *) &fsd, sizeof fsd) != sizeof fsd) |
5 | 197 { |
198 close (fd); | |
199 return -1; | |
200 } | |
201 close (fd); | |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
202 |
1202
c9448dd2fd94
(get_fs_usage): Add parens.
Jim Meyering <jim@meyering.net>
parents:
1201
diff
changeset
|
203 fsp->fsu_blocksize = (fsd.s_type == Fs2b ? 1024 : 512); |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
204 fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.s_fsize); |
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
205 fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.s_tfree); |
1281 | 206 fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.s_tfree); |
207 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.s_tfree) != 0; | |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
208 fsp->fsu_files = (fsd.s_isize == -1 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
209 ? UINTMAX_MAX |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
210 : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1)); |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
211 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode); |
780 | 212 |
13450
0394cf0c5bad
fsusage: Clarify which code applies to which platforms.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
213 #elif defined STAT_STATFS3_OSF1 /* OSF/1 */ |
6912 | 214 |
215 struct statfs fsd; | |
5 | 216 |
6912 | 217 if (statfs (file, &fsd, sizeof (struct statfs)) != 0) |
218 return -1; | |
219 | |
220 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); | |
221 | |
16857
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
222 #elif defined STAT_STATFS2_FRSIZE /* 2.6 < glibc/Linux < 2.6.36 */ |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
223 |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
224 struct statfs fsd; |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
225 |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
226 if (statfs (file, &fsd) < 0) |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
227 return -1; |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
228 |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
229 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_frsize); |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
230 |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
231 #elif defined STAT_STATFS2_BSIZE /* glibc/Linux < 2.6, 4.3BSD, SunOS 4, \ |
16935
498a2211d839
Write "Mac OS X" instead of "MacOS X".
Bruno Haible <bruno@clisp.org>
parents:
16857
diff
changeset
|
232 Mac OS X < 10.4, FreeBSD < 5.0, \ |
13450
0394cf0c5bad
fsusage: Clarify which code applies to which platforms.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
233 NetBSD < 3.0, OpenBSD < 4.4 */ |
780 | 234 |
5 | 235 struct statfs fsd; |
236 | |
5907 | 237 if (statfs (file, &fsd) < 0) |
5 | 238 return -1; |
488
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
239 |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
240 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_bsize); |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
241 |
774
2158edf8414e
cpp-indent + change some #ifdef to #if
Jim Meyering <jim@meyering.net>
parents:
670
diff
changeset
|
242 # ifdef STATFS_TRUNCATES_BLOCK_COUNTS |
780 | 243 |
488
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
244 /* In SunOS 4.1.2, 4.1.3, and 4.1.3_U1, the block counts in the |
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
245 struct statfs are truncated to 2GB. These conditions detect that |
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
246 truncation, presumably without botching the 4.1.1 case, in which |
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
247 the values are not truncated. The correct counts are stored in |
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
248 undocumented spare fields. */ |
1876
663e86d5d38c
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]:
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
249 if (fsd.f_blocks == 0x7fffffff / fsd.f_bsize && fsd.f_spare[0] > 0) |
488
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
250 { |
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
251 fsd.f_blocks = fsd.f_spare[0]; |
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
252 fsd.f_bfree = fsd.f_spare[1]; |
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
253 fsd.f_bavail = fsd.f_spare[2]; |
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
254 } |
774
2158edf8414e
cpp-indent + change some #ifdef to #if
Jim Meyering <jim@meyering.net>
parents:
670
diff
changeset
|
255 # endif /* STATFS_TRUNCATES_BLOCK_COUNTS */ |
488
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
256 |
13450
0394cf0c5bad
fsusage: Clarify which code applies to which platforms.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
257 #elif defined STAT_STATFS2_FSIZE /* 4.4BSD and older NetBSD */ |
780 | 258 |
5 | 259 struct statfs fsd; |
260 | |
5907 | 261 if (statfs (file, &fsd) < 0) |
5 | 262 return -1; |
780 | 263 |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
264 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
265 |
13450
0394cf0c5bad
fsusage: Clarify which code applies to which platforms.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
266 #elif defined STAT_STATFS4 /* SVR3, Dynix, old Irix, old AIX, \ |
0394cf0c5bad
fsusage: Clarify which code applies to which platforms.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
267 Dolphin */ |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
268 |
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
269 # if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN |
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
270 # define f_bavail f_bfree |
780 | 271 # endif |
272 | |
5 | 273 struct statfs fsd; |
274 | |
5907 | 275 if (statfs (file, &fsd, sizeof fsd, 0) < 0) |
5 | 276 return -1; |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
277 |
5 | 278 /* Empirically, the block counts on most SVR3 and SVR3-derived |
279 systems seem to always be in terms of 512-byte blocks, | |
280 no matter what value f_bsize has. */ | |
4010
f1d0bc6f6458
Remove unneeded parentheses around operands of `defined'.
Jim Meyering <jim@meyering.net>
parents:
3994
diff
changeset
|
281 # if _AIX || defined _CRAY |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
282 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_bsize); |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
283 # else |
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
284 fsp->fsu_blocksize = 512; |
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
285 # endif |
780 | 286 |
6912 | 287 #endif |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
288 |
17000
9fc45cd5d9b5
fsusage: port back to Solaris
Paul Eggert <eggert@cs.ucla.edu>
parents:
16961
diff
changeset
|
289 #if (defined STAT_STATVFS64 || defined STAT_STATFS3_OSF1 \ |
9fc45cd5d9b5
fsusage: port back to Solaris
Paul Eggert <eggert@cs.ucla.edu>
parents:
16961
diff
changeset
|
290 || defined STAT_STATFS2_FRSIZE || defined STAT_STATFS2_BSIZE \ |
9fc45cd5d9b5
fsusage: port back to Solaris
Paul Eggert <eggert@cs.ucla.edu>
parents:
16961
diff
changeset
|
291 || defined STAT_STATFS2_FSIZE || defined STAT_STATFS4) |
780 | 292 |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
293 fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.f_blocks); |
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
294 fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.f_bfree); |
1281 | 295 fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.f_bavail); |
296 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.f_bavail) != 0; | |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
297 fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files); |
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
298 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree); |
780 | 299 |
6912 | 300 #endif |
5 | 301 |
11414
854e145c049b
fsusage: avoid syntax error due to statement-before-declaration
Jim Meyering <meyering@redhat.com>
parents:
11112
diff
changeset
|
302 (void) disk; /* avoid argument-unused warning */ |
5 | 303 return 0; |
304 } | |
305 | |
4010
f1d0bc6f6458
Remove unneeded parentheses around operands of `defined'.
Jim Meyering <jim@meyering.net>
parents:
3994
diff
changeset
|
306 #if defined _AIX && defined _I386 |
5 | 307 /* AIX PS/2 does not supply statfs. */ |
308 | |
309 int | |
5907 | 310 statfs (char *file, struct statfs *fsb) |
5 | 311 { |
312 struct stat stats; | |
313 struct dustat fsd; | |
314 | |
5907 | 315 if (stat (file, &stats) != 0) |
5 | 316 return -1; |
317 if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd))) | |
318 return -1; | |
319 fsb->f_type = 0; | |
320 fsb->f_bsize = fsd.du_bsize; | |
321 fsb->f_blocks = fsd.du_fsize - fsd.du_isize; | |
322 fsb->f_bfree = fsd.du_tfree; | |
323 fsb->f_bavail = fsd.du_tfree; | |
324 fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb; | |
325 fsb->f_ffree = fsd.du_tinode; | |
326 fsb->f_fsid.val[0] = fsd.du_site; | |
327 fsb->f_fsid.val[1] = fsd.du_pckno; | |
328 return 0; | |
329 } | |
780 | 330 |
5 | 331 #endif /* _AIX && _I386 */ |