summaryrefslogtreecommitdiffstats
path: root/gl/fsusage.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/fsusage.c')
-rw-r--r--gl/fsusage.c118
1 files changed, 10 insertions, 108 deletions
diff --git a/gl/fsusage.c b/gl/fsusage.c
index 0657555f..f6f4b1c3 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-2023 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
@@ -160,56 +148,6 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
160 ? PROPAGATE_ALL_ONES (fsd.f_frsize) 148 ? PROPAGATE_ALL_ONES (fsd.f_frsize)
161 : PROPAGATE_ALL_ONES (fsd.f_bsize)); 149 : PROPAGATE_ALL_ONES (fsd.f_bsize));
162 150
163#elif defined STAT_STATFS2_FS_DATA /* Ultrix */
164
165 struct fs_data fsd;
166
167 if (statfs (file, &fsd) != 1)
168 return -1;
169
170 fsp->fsu_blocksize = 1024;
171 fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.fd_req.btot);
172 fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.fd_req.bfree);
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;
175 fsp->fsu_files = PROPAGATE_ALL_ONES (fsd.fd_req.gtot);
176 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.fd_req.gfree);
177
178#elif defined STAT_READ_FILSYS /* SVR2 */
179# ifndef SUPERBOFF
180# define SUPERBOFF (SUPERB * 512)
181# endif
182
183 struct filsys fsd;
184 int fd;
185
186 if (! disk)
187 {
188 errno = 0;
189 return -1;
190 }
191
192 fd = open (disk, O_RDONLY);
193 if (fd < 0)
194 return -1;
195 lseek (fd, (off_t) SUPERBOFF, 0);
196 if (full_read (fd, (char *) &fsd, sizeof fsd) != sizeof fsd)
197 {
198 close (fd);
199 return -1;
200 }
201 close (fd);
202
203 fsp->fsu_blocksize = (fsd.s_type == Fs2b ? 1024 : 512);
204 fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.s_fsize);
205 fsp->fsu_bfree = PROPAGATE_ALL_ONES (fsd.s_tfree);
206 fsp->fsu_bavail = PROPAGATE_TOP_BIT (fsd.s_tfree);
207 fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (fsd.s_tfree) != 0;
208 fsp->fsu_files = (fsd.s_isize == -1
209 ? UINTMAX_MAX
210 : (fsd.s_isize - 2) * INOPB * (fsd.s_type == Fs2b ? 2 : 1));
211 fsp->fsu_ffree = PROPAGATE_ALL_ONES (fsd.s_tinode);
212
213#elif defined STAT_STATFS3_OSF1 /* OSF/1 */ 151#elif defined STAT_STATFS3_OSF1 /* OSF/1 */
214 152
215 struct statfs fsd; 153 struct statfs fsd;
@@ -263,12 +201,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
263 201
264 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); 202 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize);
265 203
266#elif defined STAT_STATFS4 /* SVR3, Dynix, old Irix, old AIX, \ 204#elif defined STAT_STATFS4 /* SVR3, old Irix */
267 Dolphin */
268
269# if !_AIX && !defined _SEQUENT_ && !defined DOLPHIN
270# define f_bavail f_bfree
271# endif
272 205
273 struct statfs fsd; 206 struct statfs fsd;
274 207
@@ -278,11 +211,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
278 /* Empirically, the block counts on most SVR3 and SVR3-derived 211 /* Empirically, the block counts on most SVR3 and SVR3-derived
279 systems seem to always be in terms of 512-byte blocks, 212 systems seem to always be in terms of 512-byte blocks,
280 no matter what value f_bsize has. */ 213 no matter what value f_bsize has. */
281# if _AIX || defined _CRAY
282 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_bsize);
283# else
284 fsp->fsu_blocksize = 512; 214 fsp->fsu_blocksize = 512;
285# endif
286 215
287#endif 216#endif
288 217
@@ -302,30 +231,3 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
302 (void) disk; /* avoid argument-unused warning */ 231 (void) disk; /* avoid argument-unused warning */
303 return 0; 232 return 0;
304} 233}
305
306#if defined _AIX && defined _I386
307/* AIX PS/2 does not supply statfs. */
308
309int
310statfs (char *file, struct statfs *fsb)
311{
312 struct stat stats;
313 struct dustat fsd;
314
315 if (stat (file, &stats) != 0)
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}
330
331#endif /* _AIX && _I386 */