Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include <stdio.h>
00014 #include <string.h>
00015 #include <ctype.h>
00016 #include <math.h>
00017
00018
00019
00020
00021 #ifdef __sgi
00022 #include <sys/statfs.h>
00023 #include <sys/fstyp.h>
00024 #include <sys/fsid.h>
00025 struct statfs disk;
00026 char fstyp[ FSTYPSZ ];
00027 #endif
00028
00029
00030
00031
00032 #ifdef __linux__
00033 #include <sys/stat.h>
00034 #include <sys/vfs.h>
00035 struct statfs disk;
00036 #endif
00037
00038
00039
00040
00041
00042 #ifdef __DARWIN__
00043 #include <sys/param.h>
00044 #include <sys/mount.h>
00045 struct statfs disk;
00046 #endif
00047
00048
00049
00050
00051 #ifdef SUN
00052 #include <sys/types.h>
00053 #include <sys/statvfs.h>
00054 struct statvfs disk;
00055 #endif
00056
00057
00058
00059
00060
00061 #ifdef __hpux
00062 #include <sys/stat.h>
00063 #include <sys/mount.h>
00064 #include <sys/vfs.h>
00065 struct statfs disk;
00066 #endif
00067
00068
00069
00070
00071
00072 #ifdef __osf__
00073 #include <sys/mount.h>
00074 struct statfs disk;
00075 #endif
00076
00077 extern char buf[], str[], statusfile[];
00078
00079
00080
00081
00082
00083 float GetDiskSpace ( char * );
00084 int IsNFS ( char * );
00085
00086
00087
00088
00089 float
00090 GetDiskSpace(char *dir)
00091 {
00092 float free= 999999.0 ;
00093
00094 if (strlen(dir) < 1 ) return( free );
00095
00096 #ifdef __sgi
00097 if(statfs(dir, &disk, sizeof disk, 0) != 0) return( free );
00098 #elif (__linux__ || __hpux || __DARWIN__)
00099 if(statfs(dir, &disk) != 0) return( free );
00100 #elif ( SUN )
00101 if(statvfs(dir, &disk) != 0) return( free );
00102 #elif __osf__
00103 if(statfs(dir, &disk, sizeof disk ) != 0 )return( free );
00104 #endif
00105
00106 #ifdef __osf__
00107 free = (float)disk.f_bavail * (float)disk.f_fsize / 1024000.;
00108 #else
00109 if(disk.f_blocks > 0)
00110 free = (float)disk.f_bfree * (float)disk.f_bsize / 1024000. ;
00111 #endif
00112
00113 return( free );
00114 }
00115
00116
00117
00118
00119 int
00120 IsNFS(char *dir)
00121 {
00122 int i,is_nfs = 0;
00123 extern int debug;
00124
00125 if (strlen(dir) < 1 ) return( is_nfs );
00126
00127 #ifdef __sgi
00128 if(statfs(dir, &disk, sizeof disk, 0) != 0) return( is_nfs );
00129 i= sysfs( GETFSTYP, disk.f_fstyp, fstyp );
00130
00131
00132
00133
00134
00135
00136 if ( strstr( fstyp, "nfs" ) )
00137 is_nfs=1;
00138
00139 #ifdef DEBUG1
00140 printf("mar345: >>>%s<<< fs-type=%s (0x%x)\n",dir,fstyp,disk.f_fstyp);
00141 #endif
00142
00143 #elif (__linux__ )
00144
00145
00146 if(statfs(dir, &disk) != 0) return( is_nfs );
00147
00148 if ( disk.f_type == 0x6969 ) is_nfs = 1;
00149
00150 #ifdef DEBUG
00151 if (debug)
00152 printf("mar345: >>>%s<<< fs-type=0x%x\n",dir,disk.f_type);
00153 #endif
00154
00155 #elif __hpux
00156
00157
00158 if(statfs(dir, &disk) != 0) return( is_nfs );
00159
00160 if ( disk.f_type == MOUNT_NFS ) is_nfs = 1;
00161
00162 #elif SUN
00163
00164 if(statvfs(dir, &disk) != 0) return( is_nfs );
00165 if ( strstr( disk.f_basetype, "NFS" ) )
00166 is_nfs=1;
00167
00168 #ifdef DEBUG
00169 if (debug)
00170 printf("mar345: >>>%s<<< fs-type=0x%x\n",dir,disk.f_type);
00171 #endif
00172
00173 #elif __osf__
00174 if(statfs(dir, &disk, sizeof disk ) != 0 )return( is_nfs );
00175 #endif
00176
00177
00178 return(is_nfs);
00179 }