1 #include "portable.h"
2 /**** ENDINCLUDE ****/
3 
4 #ifdef HAVE_SYS_MOUNT_H
5 # include <sys/mount.h>
6 #endif
7 #ifdef HAVE_SYS_STATVFS_H
8 # include <sys/statvfs.h>
9 #endif
10 #ifdef HAVE_SYS_STATFS_H
11 # include <sys/statfs.h>
12 #endif
13 #if defined(HAVE_SYS_VFS_H) && !defined(SOLARIS)
14 # include <sys/vfs.h>
15 #endif
16 
17 # if USE_STATFS_TYPE == STATVFS
18 #  define plp_statfs(path,buf) statvfs(path,buf)
19 #  define plp_struct_statfs struct statvfs
20 #  define statfs(path, buf) statvfs(path, buf)
21 #  define USING "STATVFS"
22 #  define BLOCKSIZE(f) (unsigned long)(f.f_frsize?f.frsize:f.f_bsize)
23 #  define BLOCKS(f)    (unsigned long)f.f_bavail
24 # endif
25 
26 # if USE_STATFS_TYPE == ULTRIX_STATFS
27 #  define plp_statfs(path,buf) statfs(path,buf)
28 #  define plp_struct_statfs struct fs_data
29 #  define USING "ULTRIX_STATFS"
30 #  define BLOCKSIZE(f) (unsigned long)f.fd_bsize
31 #  define BLOCKS(f)    (unsigned long)f.fd_bfree
32 # endif
33 
34 # if USE_STATFS_TYPE ==  SVR3_STATFS
35 #  define plp_struct_statfs struct statfs
36 #  define plp_statfs(path,buf) statfs(path,buf,sizeof(struct statfs),0)
37 #  define USING "SV3_STATFS"
38 #  define BLOCKSIZE(f) (unsigned long)f.f_bsize
39 #  define BLOCKS(f)    (unsigned long)f.f_bfree
40 # endif
41 
42 # if USE_STATFS_TYPE == STATFS
43 #  define plp_struct_statfs struct statfs
44 #  define plp_statfs(path,buf) statfs(path,buf)
45 #  define USING "STATFS"
46 #  define BLOCKSIZE(f) (unsigned long)f.f_bsize
47 #  define BLOCKS(f)    (unsigned long)f.f_bavail
48 # endif
49 
50 /***************************************************************************
51  * Space_avail() - get the amount of free space avail in the spool directory
52  ***************************************************************************/
53 
main(int argc,char * argv[],char * envp[])54 int main( int argc, char *argv[], char *envp[] )
55 {
56 	char *pathname = argv[1];
57 	plp_struct_statfs fsb;
58 	unsigned long space = 0;
59 
60 	if( !pathname ){
61 		pathname = ".";
62 	}
63 	if( plp_statfs( pathname, &fsb ) == -1 ){
64 		fprintf(stderr, "Space_avail: cannot stat '%s'", pathname );
65 		exit(1);
66 	}
67 	space = (1.0 * BLOCKS(fsb) * BLOCKSIZE(fsb))/1024;
68 	printf("path '%s', Using '%s', %lu blocks, %lu blocksize, space %lu\n",
69 	pathname, USING, BLOCKS(fsb), BLOCKSIZE(fsb), space );
70 	return(0);
71 }
72