summaryrefslogtreecommitdiffstats
path: root/lib/fsusage.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fsusage.c')
-rw-r--r--lib/fsusage.c45
1 files changed, 21 insertions, 24 deletions
diff --git a/lib/fsusage.c b/lib/fsusage.c
index d9260293..b1377907 100644
--- a/lib/fsusage.c
+++ b/lib/fsusage.c
@@ -1,7 +1,7 @@
1/* fsusage.c -- return space usage of mounted filesystems 1/* fsusage.c -- return space usage of mounted file systems
2 2
3 Copyright (C) 1991, 1992, 1996, 1998, 1999, 2002, 2003 Free 3 Copyright (C) 1991, 1992, 1996, 1998, 1999, 2002, 2003, 2004, 2005
4 Software Foundation, Inc. 4 Free Software Foundation, Inc.
5 5
6 This program is free software; you can redistribute it and/or modify 6 This program 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 General Public License as published by
@@ -15,19 +15,19 @@
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 General Public License
17 along with this program; if not, write to the Free Software Foundation, 17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19 19
20#if HAVE_CONFIG_H 20#ifdef HAVE_CONFIG_H
21# include <config.h> 21# include <config.h>
22#endif 22#endif
23 23
24#if HAVE_INTTYPES_H 24#if HAVE_INTTYPES_H
25# include <inttypes.h> 25# include <inttypes.h>
26#else
27# if HAVE_STDINT_H
28# include <stdint.h>
29# endif
30#endif 26#endif
27#if HAVE_STDINT_H
28# include <stdint.h>
29#endif
30#include <unistd.h>
31#ifndef UINTMAX_MAX 31#ifndef UINTMAX_MAX
32# define UINTMAX_MAX ((uintmax_t) -1) 32# define UINTMAX_MAX ((uintmax_t) -1)
33#endif 33#endif
@@ -58,9 +58,7 @@
58# include <sys/filsys.h> /* SVR2 */ 58# include <sys/filsys.h> /* SVR2 */
59#endif 59#endif
60 60
61#if HAVE_FCNTL_H 61#include <fcntl.h>
62# include <fcntl.h>
63#endif
64 62
65#if HAVE_SYS_STATFS_H 63#if HAVE_SYS_STATFS_H
66# include <sys/statfs.h> 64# include <sys/statfs.h>
@@ -72,7 +70,6 @@
72 70
73#if HAVE_SYS_STATVFS_H /* SVR4 */ 71#if HAVE_SYS_STATVFS_H /* SVR4 */
74# include <sys/statvfs.h> 72# include <sys/statvfs.h>
75int statvfs ();
76#endif 73#endif
77 74
78#include "full-read.h" 75#include "full-read.h"
@@ -102,20 +99,20 @@ int statvfs ();
102#define PROPAGATE_TOP_BIT(x) ((x) | ~ (EXTRACT_TOP_BIT (x) - 1)) 99#define PROPAGATE_TOP_BIT(x) ((x) | ~ (EXTRACT_TOP_BIT (x) - 1))
103 100
104/* Fill in the fields of FSP with information about space usage for 101/* Fill in the fields of FSP with information about space usage for
105 the filesystem on which PATH resides. 102 the file system on which FILE resides.
106 DISK is the device on which PATH is mounted, for space-getting 103 DISK is the device on which FILE is mounted, for space-getting
107 methods that need to know it. 104 methods that need to know it.
108 Return 0 if successful, -1 if not. When returning -1, ensure that 105 Return 0 if successful, -1 if not. When returning -1, ensure that
109 ERRNO is either a system error value, or zero if DISK is NULL 106 ERRNO is either a system error value, or zero if DISK is NULL
110 on a system that requires a non-NULL value. */ 107 on a system that requires a non-NULL value. */
111int 108int
112get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp) 109get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp)
113{ 110{
114#ifdef STAT_STATFS3_OSF1 111#ifdef STAT_STATFS3_OSF1
115 112
116 struct statfs fsd; 113 struct statfs fsd;
117 114
118 if (statfs (path, &fsd, sizeof (struct statfs)) != 0) 115 if (statfs (file, &fsd, sizeof (struct statfs)) != 0)
119 return -1; 116 return -1;
120 117
121 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); 118 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize);
@@ -126,7 +123,7 @@ get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp)
126 123
127 struct fs_data fsd; 124 struct fs_data fsd;
128 125
129 if (statfs (path, &fsd) != 1) 126 if (statfs (file, &fsd) != 1)
130 return -1; 127 return -1;
131 128
132 fsp->fsu_blocksize = 1024; 129 fsp->fsu_blocksize = 1024;
@@ -180,7 +177,7 @@ get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp)
180 177
181 struct statfs fsd; 178 struct statfs fsd;
182 179
183 if (statfs (path, &fsd) < 0) 180 if (statfs (file, &fsd) < 0)
184 return -1; 181 return -1;
185 182
186 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_bsize); 183 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_bsize);
@@ -206,7 +203,7 @@ get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp)
206 203
207 struct statfs fsd; 204 struct statfs fsd;
208 205
209 if (statfs (path, &fsd) < 0) 206 if (statfs (file, &fsd) < 0)
210 return -1; 207 return -1;
211 208
212 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize); 209 fsp->fsu_blocksize = PROPAGATE_ALL_ONES (fsd.f_fsize);
@@ -221,7 +218,7 @@ get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp)
221 218
222 struct statfs fsd; 219 struct statfs fsd;
223 220
224 if (statfs (path, &fsd, sizeof fsd, 0) < 0) 221 if (statfs (file, &fsd, sizeof fsd, 0) < 0)
225 return -1; 222 return -1;
226 223
227 /* Empirically, the block counts on most SVR3 and SVR3-derived 224 /* Empirically, the block counts on most SVR3 and SVR3-derived
@@ -239,7 +236,7 @@ get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp)
239 236
240 struct statvfs fsd; 237 struct statvfs fsd;
241 238
242 if (statvfs (path, &fsd) < 0) 239 if (statvfs (file, &fsd) < 0)
243 return -1; 240 return -1;
244 241
245 /* f_frsize isn't guaranteed to be supported. */ 242 /* f_frsize isn't guaranteed to be supported. */
@@ -268,12 +265,12 @@ get_fs_usage (const char *path, const char *disk, struct fs_usage *fsp)
268/* AIX PS/2 does not supply statfs. */ 265/* AIX PS/2 does not supply statfs. */
269 266
270int 267int
271statfs (char *path, struct statfs *fsb) 268statfs (char *file, struct statfs *fsb)
272{ 269{
273 struct stat stats; 270 struct stat stats;
274 struct dustat fsd; 271 struct dustat fsd;
275 272
276 if (stat (path, &stats)) 273 if (stat (file, &stats) != 0)
277 return -1; 274 return -1;
278 if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd))) 275 if (dustat (stats.st_dev, 0, &fsd, sizeof (fsd)))
279 return -1; 276 return -1;