summaryrefslogtreecommitdiffstats
path: root/gl/fsusage.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/fsusage.c')
-rw-r--r--gl/fsusage.c123
1 files changed, 10 insertions, 113 deletions
diff --git a/gl/fsusage.c b/gl/fsusage.c
index 6103ecf..740cdc2 100644
--- a/gl/fsusage.c
+++ b/gl/fsusage.c
@@ -1,20 +1,20 @@
1/* fsusage.c -- return space usage of mounted file systems 1/* fsusage.c -- return space usage of mounted file systems
2 2
3 Copyright (C) 1991-1992, 1996, 1998-1999, 2002-2006, 2009-2013 Free Software 3 Copyright (C) 1991-1992, 1996, 1998-1999, 2002-2006, 2009-2021 Free Software
4 Foundation, Inc. 4 Foundation, Inc.
5 5
6 This program is free software: you can redistribute it and/or modify 6 This file is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 7 it under the terms of the GNU Lesser General Public License as
8 the Free Software Foundation; either version 3 of the License, or 8 published by the Free Software Foundation; either version 3 of the
9 (at your option) any later version. 9 License, or (at your option) any later version.
10 10
11 This program is distributed in the hope that it will be useful, 11 This file is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details. 14 GNU Lesser General Public License for more details.
15 15
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 18
19#include <config.h> 19#include <config.h>
20 20
@@ -43,23 +43,11 @@
43# if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */ 43# if HAVE_SYS_FS_S5PARAM_H /* Fujitsu UXP/V */
44# include <sys/fs/s5param.h> 44# include <sys/fs/s5param.h>
45# endif 45# endif
46# if defined HAVE_SYS_FILSYS_H && !defined _CRAY
47# include <sys/filsys.h> /* SVR2 */
48# endif
49# if HAVE_SYS_STATFS_H 46# if HAVE_SYS_STATFS_H
50# include <sys/statfs.h> 47# include <sys/statfs.h>
51# endif 48# endif
52# if HAVE_DUSTAT_H /* AIX PS/2 */
53# include <sys/dustat.h>
54# endif
55# include "full-read.h"
56#endif 49#endif
57 50
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
63/* Many space usage primitives use all 1 bits to denote a value that is 51/* Many space usage primitives use all 1 bits to denote a value that is
64 not applicable or unknown. Propagate this information by returning 52 not applicable or unknown. Propagate this information by returning
65 a uintmax_t value that is all 1 bits if X is all 1 bits, even if X 53 a uintmax_t value that is all 1 bits if X is all 1 bits, even if X
@@ -143,7 +131,6 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
143 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (vfsd.f_bavail) != 0; 131 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (vfsd.f_bavail) != 0;
144 fsp->fsu_files = PROPAGATE_ALL_ONES (vfsd.f_files); 132 fsp->fsu_files = PROPAGATE_ALL_ONES (vfsd.f_files);
145 fsp->fsu_ffree = PROPAGATE_ALL_ONES (vfsd.f_ffree); 133 fsp->fsu_ffree = PROPAGATE_ALL_ONES (vfsd.f_ffree);
146 fsp->fsu_favail = PROPAGATE_ALL_ONES (vfsd.f_favail);
147 return 0; 134 return 0;
148 } 135 }
149 136
@@ -161,58 +148,6 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
161 ? PROPAGATE_ALL_ONES (fsd.f_frsize) 148 ? PROPAGATE_ALL_ONES (fsd.f_frsize)
162 : PROPAGATE_ALL_ONES (fsd.f_bsize)); 149 : PROPAGATE_ALL_ONES (fsd.f_bsize));
163 150
164#elif defined STAT_STATFS2_FS_DATA /* Ultrix */
165
166 struct fs_data fsd;
167
168 if (statfs (file, &fsd) != 1)
169 return -1;
170
171 fsp->fsu_blocksize = 1024;
172 fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.fd_req.btot);
173 fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.fd_req.bfree);
174 fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.fd_req.bfreen);
175 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.fd_req.bfreen) != 0;
176 fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot);
177 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree);
178 fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.fd_req.gfree);
179
180#elif defined STAT_READ_FILSYS /* SVR2 */
181# ifndef SUPERBOFF
182# define SUPERBOFF (SUPERB * 512)
183# endif
184
185 struct filsys fsd;
186 int fd;
187
188 if (! disk)
189 {
190 errno = 0;
191 return -1;
192 }
193
194 fd = open (disk, O_RDONLY);
195 if (fd < 0)
196 return -1;
197 lseek (fd, (off_t) SUPERBOFF, 0);
198 if (full_read (fd, (char *) &fsd, sizeof fsd) != sizeof fsd)
199 {
200 close (fd);
201 return -1;
202 }
203 close (fd);
204
205 fsp->fsu_blocksize = (fsd.s_type == Fs2b ? 1024 : 512);
206 fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.s_fsize);
207 fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.s_tfree);
208 fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.s_tfree);
209 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.s_tfree) != 0;
210 fsp->fsu_files = (fsd.s_isize == -1
211 ? UINTMAX_MAX
212 : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1));
213 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode);
214 fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.s_tinode);
215
216#elif defined STAT_STATFS3_OSF1 /* OSF/1 */ 151#elif defined STAT_STATFS3_OSF1 /* OSF/1 */
217 152
218 struct statfs fsd; 153 struct statfs fsd;
@@ -266,12 +201,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
266 201
267 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); 202 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize);
268 203
269#elif defined STAT_STATFS4 /* SVR3, Dynix, old Irix, old AIX, \ 204#elif defined STAT_STATFS4 /* SVR3, old Irix */
270 Dolphin */
271
272# if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN
273# define f_bavail f_bfree
274# endif
275 205
276 struct statfs fsd; 206 struct statfs fsd;
277 207
@@ -281,11 +211,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
281 /* Empirically, the block counts on most SVR3 and SVR3-derived 211 /* Empirically, the block counts on most SVR3 and SVR3-derived
282 systems seem to always be in terms of 512-byte blocks, 212 systems seem to always be in terms of 512-byte blocks,
283 no matter what value f_bsize has. */ 213 no matter what value f_bsize has. */
284# if _AIX || defined _CRAY
285 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_bsize);
286# else
287 fsp->fsu_blocksize = 512; 214 fsp->fsu_blocksize = 512;
288# endif
289 215
290#endif 216#endif
291 217
@@ -299,38 +225,9 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
299 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.f_bavail) != 0; 225 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.f_bavail) != 0;
300 fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files); 226 fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.f_files);
301 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree); 227 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.f_ffree);
302 fsp->fsu_favail = PROPAGATE_ALL_ONES (fsd.f_ffree);
303 228
304#endif 229#endif
305 230
306 (void) disk; /* avoid argument-unused warning */ 231 (void) disk; /* avoid argument-unused warning */
307 return 0; 232 return 0;
308} 233}
309
310#if defined _AIX && defined _I386
311/* AIX PS/2 does not supply statfs. */
312
313int
314statfs (char *file, struct statfs *fsb)
315{
316 struct stat stats;
317 struct dustat fsd;
318
319 if (stat (file, &stats) != 0)
320 return -1;
321 if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd)))
322 return -1;
323 fsb->f_type = 0;
324 fsb->f_bsize = fsd.du_bsize;
325 fsb->f_blocks = fsd.du_fsize - fsd.du_isize;
326 fsb->f_bfree = fsd.du_tfree;
327 fsb->f_bavail = fsd.du_tfree;
328 fsb->f_files = (fsd.du_isize - 2) * fsd.du_inopb;
329 fsb->f_ffree = fsd.du_tinode;
330 fsb->f_favail = fsd.du_tinode;
331 fsb->f_fsid.val[0] = fsd.du_site;
332 fsb->f_fsid.val[1] = fsd.du_pckno;
333 return 0;
334}
335
336#endif /* _AIX && _I386 */