Subject: bug#9140: fsusage: add large volume support on AIX

From: Bruno Haible <[email-masked]>
Date: Sat, 23 Jul 2011 17:24:31 +0200

> 3) To make use of statvfs64 on AIX.

Here's the proposed patch for it. As expected we get:
  - On AIX 5.2, 6.1, 7.1:
    checking whether to use statvfs64... yes
  - On AIX 5.1, HP-UX, IRIX, Solaris:
    checking whether to use statvfs64... no

2011-07-23  Bruno Haible  <[email-masked]>

	fsusage: Enable large volume support on AIX >= 5.2.
	* m4/fsusage.m4 (gl_FILE_SYSTEM_USAGE): If 'struct statvfs64' has a larger
	f_blocks field than 'struct statvfs', define STAT_STATVFS64 instead of
	STAT_STATVFS.
	* lib/fsusage.c (get_fs_usage) [STAT_STATVFS64]: Use statvfs64.

--- lib/fsusage.c.orig	Sat Jul 23 17:15:05 2011
+++ lib/fsusage.c	Sat Jul 23 17:13:38 2011
@@ -23,7 +23,7 @@
 #include <limits.h>
 #include <sys/types.h>
 
-#if STAT_STATVFS                /* POSIX 1003.1-2001 (and later) with XSI */
+#if STAT_STATVFS || STAT_STATVFS64 /* POSIX 1003.1-2001 (and later) with XSI */
 # include <sys/statvfs.h>
 #else
 /* Don't include backward-compatibility files unless they're needed.
@@ -106,6 +106,18 @@
                         ? PROPAGATE_ALL_ONES (fsd.f_frsize)
                         : PROPAGATE_ALL_ONES (fsd.f_bsize));
 
+#elif defined STAT_STATVFS64            /* AIX */
+
+  struct statvfs64 fsd;
+
+  if (statvfs64 (file, &fsd) < 0)
+    return -1;
+
+  /* f_frsize isn't guaranteed to be supported.  */
+  fsp->fsu_blocksize = (fsd.f_frsize
+                        ? PROPAGATE_ALL_ONES (fsd.f_frsize)
+                        : PROPAGATE_ALL_ONES (fsd.f_bsize));
+
 #elif defined STAT_STATFS2_FS_DATA      /* Ultrix */
 
   struct fs_data fsd;
@@ -223,7 +235,7 @@
 
 #endif
 
-#if (defined STAT_STATVFS \
+#if (defined STAT_STATVFS || defined STAT_STATVFS64 \
      || (!defined STAT_STATFS2_FS_DATA && !defined STAT_READ_FILSYS))
 
   fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.f_blocks);
--- m4/fsusage.m4.orig	Sat Jul 23 17:15:05 2011
+++ m4/fsusage.m4	Sat Jul 23 17:12:20 2011
@@ -1,4 +1,4 @@
-# serial 29
+# serial 30
 # Obtaining file system usage information.
 
 # Copyright (C) 1997-1998, 2000-2001, 2003-2011 Free Software Foundation, Inc.
@@ -81,8 +81,32 @@
                                  [fu_cv_sys_stat_statvfs=no])])
   if test $fu_cv_sys_stat_statvfs = yes; then
     ac_fsusage_space=yes
-    AC_DEFINE([STAT_STATVFS], [1],
-              [  Define if there is a function named statvfs.  (SVR4)])
+    # AIX >= 5.2 has statvfs64 that has a wider f_blocks field than statvfs.
+    # glibc, HP-UX, IRIX, Solaris have statvfs64 as well, but on these systems
+    # statvfs with large-file support is already equivalent to statvfs64.
+    AC_CACHE_CHECK([whether to use statvfs64],
+      [fu_cv_sys_stat_statvfs64],
+      [AC_LINK_IFELSE(
+         [AC_LANG_PROGRAM(
+            [[#include <sys/types.h>
+              #include <sys/statvfs.h>
+              struct statvfs64 fsd;
+              int check_f_blocks_larger_in_statvfs64
+                [sizeof (((struct statvfs64 *) 0)->f_blocks)
+                 > sizeof (((struct statvfs *) 0)->f_blocks)
+                 ? 1 : -1];
+            ]],
+            [[statvfs64 (0, &fsd);]])],
+         [fu_cv_sys_stat_statvfs64=yes],
+         [fu_cv_sys_stat_statvfs64=no])
+      ])
+    if test $fu_cv_sys_stat_statvfs64 = yes; then
+      AC_DEFINE([STAT_STATVFS64], [1],
+                [  Define if statvfs64 should be preferred over statvfs.])
+    else
+      AC_DEFINE([STAT_STATVFS], [1],
+                [  Define if there is a function named statvfs.  (SVR4)])
+    fi
   fi
 fi
 
-- 
In memoriam Adam Czerniaków <http://en.wikipedia.org/wiki/Adam_Czerniaków>