Mercurial > gnulib
annotate lib/fsusage.c @ 39927:355c5b4c3f91
fsusage, mountlist: Remove support for DolphinOS (an SVR3 variant).
* lib/fsusage.c: Remove DOLPHIN case.
* m4/fsusage.m4 (gl_FILE_SYSTEM_USAGE): Update comments.
* lib/mountlist.c: Remove MOUNTED_GETMNTTBL case.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 16 Oct 2018 18:59:25 +0200 |
parents | 10eb9086bea0 |
children | aeadde756e55 |
rev | line source |
---|---|
5159 | 1 /* fsusage.c -- return space usage of mounted file systems |
4333 | 2 |
19484
10eb9086bea0
maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents:
19225
diff
changeset
|
3 Copyright (C) 1991-1992, 1996, 1998-1999, 2002-2006, 2009-2018 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 | |
19190 | 17 along with this program. If not, see <https://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 HAVE_SYS_STATFS_H | |
47 # include <sys/statfs.h> | |
48 # endif | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
49 # if HAVE_DUSTAT_H /* AIX PS/2 */ |
6912 | 50 # include <sys/dustat.h> |
51 # endif | |
669
20030d56c4ac
[HAVE_SYS_FS_S5PARAM_H]: Include sys/fs/s5param.h
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
52 #endif |
20030d56c4ac
[HAVE_SYS_FS_S5PARAM_H]: Include sys/fs/s5param.h
Jim Meyering <jim@meyering.net>
parents:
650
diff
changeset
|
53 |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
54 /* 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
|
55 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
|
56 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
|
57 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
|
58 #define PROPAGATE_ALL_ONES(x) \ |
7508
43875a037a03
Remove unnecessary part of previous change.
Paul Eggert <eggert@cs.ucla.edu>
parents:
7507
diff
changeset
|
59 ((sizeof (x) < sizeof (uintmax_t) \ |
3994
504d447035d2
2002-09-25 Paul Eggert <eggert@twinsun.com>
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
60 && (~ (x) == (sizeof (x) < sizeof (int) \ |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
61 ? - (1 << (sizeof (x) * CHAR_BIT)) \ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
62 : 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
|
63 ? UINTMAX_MAX : (uintmax_t) (x)) |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
64 |
1281 | 65 /* Extract the top bit of X as an uintmax_t value. */ |
66 #define EXTRACT_TOP_BIT(x) ((x) \ | |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
67 & ((uintmax_t) 1 << (sizeof (x) * CHAR_BIT - 1))) |
1281 | 68 |
69 /* If a value is negative, many space usage primitives store it into an | |
70 integer variable by assignment, even if the variable's type is unsigned. | |
71 So, if a space usage variable X's top bit is set, convert X to the | |
72 uintmax_t value V such that (- (uintmax_t) V) is the negative of | |
73 the original value. If X's top bit is clear, just yield X. | |
74 Use PROPAGATE_TOP_BIT if the original value might be negative; | |
75 otherwise, use PROPAGATE_ALL_ONES. */ | |
76 #define PROPAGATE_TOP_BIT(x) ((x) | ~ (EXTRACT_TOP_BIT (x) - 1)) | |
77 | |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
78 #ifdef STAT_STATVFS |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
79 /* 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
|
80 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
|
81 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
|
82 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
|
83 # 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
|
84 /* 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
|
85 # undef STAT_STATFS2_FRSIZE |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
86 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
|
87 # else |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
88 # include <string.h> /* for strverscmp */ |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
89 # include <sys/utsname.h> |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
90 # include <sys/statfs.h> |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
91 # define STAT_STATFS2_BSIZE 1 |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
92 |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
93 static int |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
94 statvfs_works (void) |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
95 { |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
96 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
|
97 struct utsname name; |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
98 if (statvfs_works_cache < 0) |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
99 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
|
100 && 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
|
101 return statvfs_works_cache; |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
102 } |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
103 # endif |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
104 #endif |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
105 |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
106 |
5 | 107 /* Fill in the fields of FSP with information about space usage for |
5907 | 108 the file system on which FILE resides. |
109 DISK is the device on which FILE is mounted, for space-getting | |
5 | 110 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
|
111 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
|
112 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
|
113 on a system that requires a non-NULL value. */ |
5 | 114 int |
11112
e7df8edd0e88
still avoid unused-parameter warnings, but do it cleanly
Jim Meyering <meyering@redhat.com>
parents:
11111
diff
changeset
|
115 get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) |
5 | 116 { |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
117 #ifdef STAT_STATVFS /* POSIX, except pre-2.6.36 glibc/Linux */ |
780 | 118 |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
119 if (statvfs_works ()) |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
120 { |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
121 struct statvfs vfsd; |
76 | 122 |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
123 if (statvfs (file, &vfsd) < 0) |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
124 return -1; |
780 | 125 |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
126 /* 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
|
127 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
|
128 ? 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
|
129 : PROPAGATE_ALL_ONES (vfsd.f_bsize)); |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
130 |
16847
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 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
|
137 return 0; |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
138 } |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
139 |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
140 #endif |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
141 |
53fb1ea35cc9
fsusage: check for GNU/Linux statvfs problem dynamically
Paul Eggert <eggert@cs.ucla.edu>
parents:
16201
diff
changeset
|
142 #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
|
143 |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
144 struct statvfs64 fsd; |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
145 |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
146 if (statvfs64 (file, &fsd) < 0) |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
147 return -1; |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
148 |
411d56b204ad
fsusage: Enable large volume support on AIX >= 5.2.
Bruno Haible <bruno@clisp.org>
parents:
14079
diff
changeset
|
149 /* 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
|
150 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
|
151 ? 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
|
152 : 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
|
153 |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
11414
diff
changeset
|
154 #elif defined STAT_STATFS2_FS_DATA /* Ultrix */ |
780 | 155 |
5 | 156 struct fs_data fsd; |
157 | |
5907 | 158 if (statfs (file, &fsd) != 1) |
5 | 159 return -1; |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
160 |
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
161 fsp->fsu_blocksize = 1024; |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
162 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
|
163 fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.fd_req.bfree); |
1281 | 164 fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.fd_req.bfreen); |
165 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
|
166 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
|
167 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree); |
5 | 168 |
13450
0394cf0c5bad
fsusage: Clarify which code applies to which platforms.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
169 #elif defined STAT_STATFS3_OSF1 /* OSF/1 */ |
6912 | 170 |
171 struct statfs fsd; | |
5 | 172 |
6912 | 173 if (statfs (file, &fsd, sizeof (struct statfs)) != 0) |
174 return -1; | |
175 | |
176 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); | |
177 | |
16857
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
178 #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
|
179 |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
180 struct statfs fsd; |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
181 |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
182 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
|
183 return -1; |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
184 |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
185 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
|
186 |
62fe7a186f63
fsusage: fix block size returned on older Linux 2.6
Pádraig Brady <P@draigBrady.com>
parents:
16847
diff
changeset
|
187 #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
|
188 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
|
189 NetBSD < 3.0, OpenBSD < 4.4 */ |
780 | 190 |
5 | 191 struct statfs fsd; |
192 | |
5907 | 193 if (statfs (file, &fsd) < 0) |
5 | 194 return -1; |
488
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
195 |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
196 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
|
197 |
774
2158edf8414e
cpp-indent + change some #ifdef to #if
Jim Meyering <jim@meyering.net>
parents:
670
diff
changeset
|
198 # ifdef STATFS_TRUNCATES_BLOCK_COUNTS |
780 | 199 |
488
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
200 /* 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
|
201 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
|
202 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
|
203 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
|
204 undocumented spare fields. */ |
1876
663e86d5d38c
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]:
Jim Meyering <jim@meyering.net>
parents:
1557
diff
changeset
|
205 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
|
206 { |
3b80433a4e28
(get_fs_usage) [STATFS_TRUNCATES_BLOCK_COUNTS]: Copy untruncated block
Jim Meyering <jim@meyering.net>
parents:
439
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 } |
774
2158edf8414e
cpp-indent + change some #ifdef to #if
Jim Meyering <jim@meyering.net>
parents:
670
diff
changeset
|
211 # 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
|
212 |
13450
0394cf0c5bad
fsusage: Clarify which code applies to which platforms.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
213 #elif defined STAT_STATFS2_FSIZE /* 4.4BSD and older NetBSD */ |
780 | 214 |
5 | 215 struct statfs fsd; |
216 | |
5907 | 217 if (statfs (file, &fsd) < 0) |
5 | 218 return -1; |
780 | 219 |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
220 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
|
221 |
39927
355c5b4c3f91
fsusage, mountlist: Remove support for DolphinOS (an SVR3 variant).
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
222 #elif defined STAT_STATFS4 /* SVR3, Dynix, old Irix, old AIX */ |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
223 |
39927
355c5b4c3f91
fsusage, mountlist: Remove support for DolphinOS (an SVR3 variant).
Bruno Haible <bruno@clisp.org>
parents:
19484
diff
changeset
|
224 # if !_AIX && !defined _SEQUENT_ |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
225 # define f_bavail f_bfree |
780 | 226 # endif |
227 | |
5 | 228 struct statfs fsd; |
229 | |
5907 | 230 if (statfs (file, &fsd, sizeof fsd, 0) < 0) |
5 | 231 return -1; |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
232 |
5 | 233 /* Empirically, the block counts on most SVR3 and SVR3-derived |
234 systems seem to always be in terms of 512-byte blocks, | |
235 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
|
236 # if _AIX || defined _CRAY |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
237 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
|
238 # else |
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
239 fsp->fsu_blocksize = 512; |
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
240 # endif |
780 | 241 |
6912 | 242 #endif |
1135
5306f6a320de
Do all calculations using uintmax_t.
Jim Meyering <jim@meyering.net>
parents:
793
diff
changeset
|
243 |
17000
9fc45cd5d9b5
fsusage: port back to Solaris
Paul Eggert <eggert@cs.ucla.edu>
parents:
16961
diff
changeset
|
244 #if (defined STAT_STATVFS64 || defined STAT_STATFS3_OSF1 \ |
9fc45cd5d9b5
fsusage: port back to Solaris
Paul Eggert <eggert@cs.ucla.edu>
parents:
16961
diff
changeset
|
245 || defined STAT_STATFS2_FRSIZE || defined STAT_STATFS2_BSIZE \ |
9fc45cd5d9b5
fsusage: port back to Solaris
Paul Eggert <eggert@cs.ucla.edu>
parents:
16961
diff
changeset
|
246 || defined STAT_STATFS2_FSIZE || defined STAT_STATFS4) |
780 | 247 |
1201
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
248 fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.f_blocks); |
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
249 fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.f_bfree); |
1281 | 250 fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.f_bavail); |
251 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
|
252 fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files); |
5f2881266806
(PROPAGATE_ALL_ONES): New macro.
Jim Meyering <jim@meyering.net>
parents:
1135
diff
changeset
|
253 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree); |
780 | 254 |
6912 | 255 #endif |
5 | 256 |
11414
854e145c049b
fsusage: avoid syntax error due to statement-before-declaration
Jim Meyering <meyering@redhat.com>
parents:
11112
diff
changeset
|
257 (void) disk; /* avoid argument-unused warning */ |
5 | 258 return 0; |
259 } | |
260 | |
4010
f1d0bc6f6458
Remove unneeded parentheses around operands of `defined'.
Jim Meyering <jim@meyering.net>
parents:
3994
diff
changeset
|
261 #if defined _AIX && defined _I386 |
5 | 262 /* AIX PS/2 does not supply statfs. */ |
263 | |
264 int | |
5907 | 265 statfs (char *file, struct statfs *fsb) |
5 | 266 { |
267 struct stat stats; | |
268 struct dustat fsd; | |
269 | |
5907 | 270 if (stat (file, &stats) != 0) |
5 | 271 return -1; |
272 if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd))) | |
273 return -1; | |
274 fsb->f_type = 0; | |
275 fsb->f_bsize = fsd.du_bsize; | |
276 fsb->f_blocks = fsd.du_fsize - fsd.du_isize; | |
277 fsb->f_bfree = fsd.du_tfree; | |
278 fsb->f_bavail = fsd.du_tfree; | |
279 fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb; | |
280 fsb->f_ffree = fsd.du_tinode; | |
281 fsb->f_fsid.val[0] = fsd.du_site; | |
282 fsb->f_fsid.val[1] = fsd.du_pckno; | |
283 return 0; | |
284 } | |
780 | 285 |
5 | 286 #endif /* _AIX && _I386 */ |