Back to index

courier  0.68.2
comstatfs.c
Go to the documentation of this file.
00001 /*
00002 ** Copyright 1998 - 1999 Double Precision, Inc.
00003 ** See COPYING for distribution information.
00004 */
00005 
00006 #if    HAVE_CONFIG_H
00007 #include      "courier_lib_config.h"
00008 #endif
00009 
00010 #include      "courier.h"
00011 
00012 #include      <sys/types.h>
00013 
00014 #if HAVE_STATVFS
00015 #include      <sys/statvfs.h>
00016 #define       DOIT
00017 #else
00018 
00019 #if HAVE_STATFS
00020 
00021 #if HAVE_SYS_STATFS_H
00022 #include      <sys/statfs.h>
00023 #else
00024 
00025 #if HAVE_SYS_PARAM_H
00026 #include      <sys/param.h>
00027 #endif
00028 
00029 #if HAVE_SYS_MOUNT_H
00030 #include      <sys/mount.h>
00031 #endif
00032 #endif
00033 
00034 
00035 
00036 
00037 #define       DOIT
00038 #else
00039 int config_statfs(const char *ptr, unsigned long *nblocks,
00040        unsigned long *ninodes, unsigned *blksize)
00041 {
00042        return (-1);
00043 }
00044 #endif
00045 #endif
00046 
00047 #ifdef DOIT
00048 
00049 int freespace(const char *ptr,
00050        unsigned long *tblocks, unsigned long *nblocks,
00051        unsigned long *tinodes, unsigned long *ninodes,
00052        unsigned *blksize)
00053 {
00054 #if HAVE_STATVFS
00055 struct statvfs buf;
00056 
00057        if (statvfs(ptr, &buf))     return (-1);
00058 
00059 #define       BTOTAL buf.f_blocks
00060 #define       BAVAIL buf.f_bavail
00061 #define       ITOTAL buf.f_files
00062 #define       IAVAIL buf.f_favail
00063 
00064        *blksize=buf.f_bsize;
00065 
00066 #else
00067 #if HAVE_STATFS
00068 struct statfs buf;
00069 
00070        if (statfs(ptr, &buf))      return (-1);
00071 
00072 #define       BTOTAL buf.f_blocks
00073 #define       BAVAIL buf.f_bfree
00074 #define       ITOTAL buf.f_files
00075 #define       IAVAIL buf.f_ffree
00076 
00077        *blksize=buf.f_bsize;
00078 #endif
00079 #endif
00080 
00081        *tblocks= BTOTAL;
00082        *nblocks= BAVAIL;
00083        *tinodes= ITOTAL;
00084        *ninodes= IAVAIL;
00085 
00086        if (*tblocks != BTOTAL) *tblocks= ~0;     /* Overflow */
00087        if (*nblocks != BAVAIL) *nblocks= ~0;     /* Overflow */
00088        if (*tinodes != ITOTAL) *tinodes= ~0;     /* Overflow */
00089        if (*ninodes != IAVAIL) *ninodes= ~0;     /* Overflow */
00090 
00091        return (0);
00092 }
00093 #endif