X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ffsusage.c;h=7f7a4a7cd8b90bb1d4ba4bee80d3bc3591d81285;hb=8cb2dc320be13ef5873d8dce5706a3fabcf8de5a;hp=8cc0c6d7333d858177ed4b1ebfc9b85e72eee151;hpb=b01778752f699303762e2307867d462133ae2b1a;p=gnulib.git diff --git a/lib/fsusage.c b/lib/fsusage.c index 8cc0c6d73..7f7a4a7cd 100644 --- a/lib/fsusage.c +++ b/lib/fsusage.c @@ -15,11 +15,26 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifdef HAVE_CONFIG_H +#if defined (CONFIG_BROKETS) +/* We use instead of "config.h" so that a compilation + using -I. -I will use ./config.h rather than /config.h + (which it would do because it found this file in ). */ +#include +#else +#include "config.h" +#endif +#endif + #include #include "fsusage.h" int statfs (); +#if defined (STAT_STATFS3_OSF1) /* DEC Alpha running OSF/1 */ +# include +#endif + #if defined(STAT_STATFS2_BSIZE) && !defined(_IBMR2) /* 4.3BSD, SunOS 4, HP-UX, AIX PS/2. */ #include #endif @@ -54,16 +69,20 @@ int statvfs (); #endif /* Return the number of TOSIZE-byte blocks used by - BLOCKS FROMSIZE-byte blocks, rounding up. */ + BLOCKS FROMSIZE-byte blocks, rounding away from zero. */ -#define adjust_blocks(blocks, fromsize, tosize) \ - (((fromsize) == (tosize)) \ - ? (blocks) /* E.g., from 512 to 512. */ \ - : (((fromsize) > (tosize)) \ - /* E.g., from 2048 to 512. */ \ - ? (blocks) * ((fromsize) / (tosize)) \ - /* E.g., from 256 to 512. */ \ - : ((blocks) + 1) / ((tosize) / (fromsize)))) +static long +adjust_blocks (blocks, fromsize, tosize) + long blocks; + int fromsize, tosize; +{ + if (fromsize == tosize) /* E.g., from 512 to 512. */ + return blocks; + else if (fromsize > tosize) /* E.g., from 2048 to 512. */ + return blocks * (fromsize / tosize); + else /* E.g., from 256 to 512. */ + return (blocks + (blocks < 0 ? -1 : 1)) / (tosize / fromsize); +} /* Fill in the fields of FSP with information about space usage for the filesystem on which PATH resides. @@ -76,6 +95,14 @@ get_fs_usage (path, disk, fsp) char *path, *disk; struct fs_usage *fsp; { +#if defined (STAT_STATFS3_OSF1) + struct statfs fsd; + + if (statfs (path, &fsd, sizeof (struct statfs)) != 0) + return (-1); +#define convert_blocks(b) adjust_blocks ((b),fsd.f_fsize, 512) +#endif /* STAT_STATFS3_OSF1 */ + #ifdef STAT_STATFS2_FS_DATA /* Ultrix. */ struct fs_data fsd; @@ -140,9 +167,11 @@ get_fs_usage (path, disk, fsp) no matter what value f_bsize has. */ #define convert_blocks(b) (b) #ifndef _SEQUENT_ /* _SEQUENT_ is DYNIX/ptx. */ +#ifndef DOLPHIN /* DOLPHIN 3.8.alfa/7.18 has f_bavail */ #define f_bavail f_bfree #endif #endif +#endif #ifdef STAT_STATVFS /* SVR4. */ struct statvfs fsd;