7 /* determine available file system space
9 /* #include <fsspace.h>
13 /* unsigned long block_size;
14 /* unsigned long block_free;
18 /* void fsspace(path, sp)
20 /* struct fsspace *sp;
22 /* fsspace() returns the amount of available space in the file
23 /* system specified in \fIpath\fR, in terms of the block size and
24 /* of the number of available blocks.
26 /* All errors are fatal.
28 /* Use caution when doing computations with the result from fsspace().
29 /* It is easy to cause overflow (by multiplying large numbers) or to
30 /* cause underflow (by subtracting unsigned numbers).
34 /* The Secure Mailer license must be distributed with this software.
37 /* IBM T.J. Watson Research
39 /* Yorktown Heights, NY 10598, USA
46 #if defined(STATFS_IN_SYS_MOUNT_H)
47 #include <sys/param.h>
48 #include <sys/mount.h>
49 #elif defined(STATFS_IN_SYS_VFS_H)
51 #elif defined(STATVFS_IN_SYS_STATVFS_H)
52 #include <sys/statvfs.h>
53 #elif defined(STATFS_IN_SYS_STATFS_H)
54 #include <sys/statfs.h>
57 #error "please specify the include file with `struct statfs'"
59 #error "please specify the include file with `struct statvfs'"
63 /* Utility library. */
68 /* fsspace - find amount of available file system space */
70 void fsspace(const char *path
, struct fsspace
* sp
)
72 const char *myname
= "fsspace";
75 #ifdef USE_STRUCT_FS_DATA /* Ultrix */
78 if (statfs(path
, &fsbuf
) < 0)
79 msg_fatal("statfs %s: %m", path
);
80 sp
->block_size
= 1024;
81 sp
->block_free
= fsbuf
.fd_bfreen
;
85 if (statfs(path
, &fsbuf
) < 0)
86 msg_fatal("statfs %s: %m", path
);
87 sp
->block_size
= fsbuf
.f_bsize
;
88 sp
->block_free
= fsbuf
.f_bavail
;
94 if (statvfs(path
, &fsbuf
) < 0)
95 msg_fatal("statvfs %s: %m", path
);
96 sp
->block_size
= fsbuf
.f_frsize
;
97 sp
->block_free
= fsbuf
.f_bavail
;
100 msg_info("%s: %s: block size %lu, blocks free %lu",
101 myname
, path
, sp
->block_size
, sp
->block_free
);
107 * Proof-of-concept test program: print free space unit and count for all
108 * listed file systems.
113 int main(int argc
, char **argv
)
118 msg_fatal("usage: %s filesystem...", argv
[0]);
120 while (--argc
&& *++argv
) {
122 vstream_printf("%10s: block size %lu, blocks free %lu\n",
123 *argv
, sp
.block_size
, sp
.block_free
);
124 vstream_fflush(VSTREAM_OUT
);