1/* 2 * This program is free software; you can redistribute it and/or 3 * modify it under the terms of the GNU General Public License as 4 * published by the Free Software Foundation; either version 2 of 5 * the License, or (at your option) any later version. 6 * 7 * This program is distributed in the hope that it will be useful, 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * GNU General Public License for more details. 11 * 12 * You should have received a copy of the GNU General Public License 13 * along with this program; if not, write to the Free Software 14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 15 * MA 02111-1307 USA 16 */ 17#include "portable.h" 18/**** ENDINCLUDE ****/ 19 20#ifdef HAVE_SYS_MOUNT_H 21# include <sys/mount.h> 22#endif 23#ifdef HAVE_SYS_STATVFS_H 24# include <sys/statvfs.h> 25#endif 26#ifdef HAVE_SYS_STATFS_H 27# include <sys/statfs.h> 28#endif 29#if defined(HAVE_SYS_VFS_H) && !defined(SOLARIS) 30# include <sys/vfs.h> 31#endif 32 33#ifdef SUNOS 34extern int statfs(const char *, struct statfs *); 35#endif 36 37# if USE_STATFS_TYPE == STATVFS 38# define plp_statfs(path,buf) statvfs(path,buf) 39# define plp_struct_statfs struct statvfs 40# define statfs(path, buf) statvfs(path, buf) 41# define USING "STATVFS" 42# define BLOCKSIZE(f) (unsigned long)(f.f_frsize?f.frsize:f.f_bsize) 43# define BLOCKS(f) (unsigned long)f.f_bavail 44# endif 45 46# if USE_STATFS_TYPE == ULTRIX_STATFS 47# define plp_statfs(path,buf) statfs(path,buf) 48# define plp_struct_statfs struct fs_data 49# define USING "ULTRIX_STATFS" 50# define BLOCKSIZE(f) (unsigned long)f.fd_bsize 51# define BLOCKS(f) (unsigned long)f.fd_bfree 52# endif 53 54# if USE_STATFS_TYPE == SVR3_STATFS 55# define plp_struct_statfs struct statfs 56# define plp_statfs(path,buf) statfs(path,buf,sizeof(struct statfs),0) 57# define USING "SV3_STATFS" 58# define BLOCKSIZE(f) (unsigned long)f.f_bsize 59# define BLOCKS(f) (unsigned long)f.f_bfree 60# endif 61 62# if USE_STATFS_TYPE == STATFS 63# define plp_struct_statfs struct statfs 64# define plp_statfs(path,buf) statfs(path,buf) 65# define USING "STATFS" 66# define BLOCKSIZE(f) (unsigned long)f.f_bsize 67# define BLOCKS(f) (unsigned long)f.f_bavail 68# endif 69 70/*************************************************************************** 71 * Space_avail() - get the amount of free space avail in the spool directory 72 ***************************************************************************/ 73 74int main( int argc, char *argv[], char *envp[] ) 75{ 76 char *pathname = argv[1]; 77 plp_struct_statfs fsb; 78 unsigned long space = 0; 79 80 if( !pathname ){ 81 pathname = "."; 82 } 83 if( plp_statfs( pathname, &fsb ) == -1 ){ 84 fprintf(stderr, "Space_avail: cannot stat '%s'", pathname ); 85 exit(1); 86 } 87 space = (1.0 * BLOCKS(fsb) * BLOCKSIZE(fsb))/1024; 88 printf("path '%s', Using '%s', %lu blocks, %lu blocksize, space %lu\n", 89 pathname, USING, BLOCKS(fsb), BLOCKSIZE(fsb), space ); 90 return(0); 91} 92