From 4db9168a9322a69a08de2922b8cdde13c1f4da54 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Sun, 24 Jun 2012 10:39:01 +0400 Subject: [PATCH] Ticket #2906: crash on Solaris while trying to copy a file. Sync with gnulib c25bdbae48977a527dff69150f59fb0746d31b51: fs usage: check for GNU/Linux statvfs problem dynamically. * src/filemanager/mountlist.c [STAT_STATVFS && __linux__ && (__GLIBC__||__UCLIBC__)]: Define STAT_STATFS2_BSIZE too, since in this case the code now checks dynamically whether statvfs is reliable, falling back on Linux-style statfs otherwise. (statvfs_works): New function, for dynamically testing statvfs. (get_fs_usage) [STAT_STATVFS]: Use it. * src/filemanager/filegui.c (filegui__check_attrs_on_fs): apply the same statvfs_works function. * m4.include/fsusage.m4 (gl_FILE_SYSTEM_USAGE): Remove static check for statvfs on GNU/Linux hosts, since it's now done dynamically. Signed-off-by: Andrew Borodin --- m4.include/fsusage.m4 | 8 ------ src/filemanager/filegui.c | 46 +++++++++++++++++++++++++----- src/filemanager/mountlist.c | 69 ++++++++++++++++++++++++++++++++++++--------- 3 files changed, 94 insertions(+), 29 deletions(-) diff --git a/m4.include/fsusage.m4 b/m4.include/fsusage.m4 index 89637af30..17981f481 100644 --- a/m4.include/fsusage.m4 +++ b/m4.include/fsusage.m4 @@ -50,14 +50,6 @@ if test $ac_fsusage_space = no; then # OpenBSD >= 4.4, AIX, HP-UX, IRIX, Solaris, Cygwin, Interix, BeOS. AC_CACHE_CHECK([for statvfs function (SVR4)], [fu_cv_sys_stat_statvfs], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include -#if (defined __GLIBC__ || defined __UCLIBC__) && defined __linux__ -Do not use statvfs on systems with GNU libc on Linux, because that function -stats all preceding entries in /proc/mounts, and that makes df hang if even -one of the corresponding file systems is hard-mounted, but not available. -statvfs in GNU libc on Hurd, BeOS, Haiku operates differently: it only makes -a system call. -#endif - #ifdef __osf__ "Do not use Tru64's statvfs implementation" #endif diff --git a/src/filemanager/filegui.c b/src/filemanager/filegui.c index eb7374d81..d447279e2 100644 --- a/src/filemanager/filegui.c +++ b/src/filemanager/filegui.c @@ -91,14 +91,43 @@ #endif #if USE_STATVFS -#define STRUCT_STATVFS struct statvfs #if ! STAT_STATVFS && STAT_STATVFS64 +#define STRUCT_STATVFS struct statvfs64 #define STATFS statvfs64 #else +#define STRUCT_STATVFS struct statvfs #define STATFS statvfs +/* Return true if statvfs works. This is false for statvfs on systems + with GNU libc on Linux kernels before 2.6.36, which stats all + preceding entries in /proc/mounts; that makes df hang if even one + of the corresponding file systems is hard-mounted but not available. */ +#if ! (__linux__ && (__GLIBC__ || __UCLIBC__)) +static int +statvfs_works (void) +{ + return 1; +} +#else +#include /* for strverscmp */ +#include +#include +#define STAT_STATFS2_BSIZE 1 + +static int +statvfs_works (void) +{ + static int statvfs_works_cache = -1; + struct utsname name; + + if (statvfs_works_cache < 0) + statvfs_works_cache = (uname (&name) == 0 && 0 <= strverscmp (name.release, "2.6.36")); + return statvfs_works_cache; +} +#endif #endif #else #define STATFS statfs +#define STRUCT_STATVFS struct statfs #if HAVE_OS_H /* BeOS */ /* BeOS has a statvfs function, but it does not return sensible values for f_files, f_ffree and f_favail, and lacks f_type, f_basetype and @@ -237,16 +266,21 @@ typedef struct static gboolean filegui__check_attrs_on_fs (const char *fs_path) { -#ifdef USE_STATVFS STRUCT_STATVFS stfs; if (!setup_copymove_persistent_attr) return FALSE; - if (statfs (fs_path, &stfs) != 0) +#if USE_STATVFS && defined(STAT_STATVFS) + if (statvfs_works () && statvfs (fs_path, &stfs) != 0) + return TRUE; +#else + if (STATFS (fs_path, &stfs) != 0) return TRUE; +#endif -#ifdef __linux__ +#if (USE_STATVFS && defined(HAVE_STRUCT_STATVFS_F_TYPE)) || \ + (!USE_STATVFS && defined(HAVE_STRUCT_STATFS_F_TYPE)) switch ((filegui_nonattrs_fs_t) stfs.f_type) { case MSDOS_SUPER_MAGIC: @@ -259,8 +293,7 @@ filegui__check_attrs_on_fs (const char *fs_path) default: break; } -#elif defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) \ - || defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME) +#elif defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME) || defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) if (strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "msdos") == 0 || strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "msdosfs") == 0 || strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "ntfs") == 0 @@ -276,7 +309,6 @@ filegui__check_attrs_on_fs (const char *fs_path) || strcmp (stfs.STATXFS_FILE_SYSTEM_TYPE_MEMBER_NAME, "fuse") == 0) return FALSE; #endif -#endif /* USE_STATVFS */ return TRUE; } diff --git a/src/filemanager/mountlist.c b/src/filemanager/mountlist.c index 2be1a87e1..90c91b41d 100644 --- a/src/filemanager/mountlist.c +++ b/src/filemanager/mountlist.c @@ -270,7 +270,37 @@ me_remote (char const *fs_name, char const *fs_type _GL_UNUSED) otherwise, use PROPAGATE_ALL_ONES. */ #define PROPAGATE_TOP_BIT(x) ((x) | ~ (EXTRACT_TOP_BIT (x) - 1)) -#ifdef STAT_READ_FILSYS /* SVR2 */ +#ifdef STAT_STATVFS +/* Return true if statvfs works. This is false for statvfs on systems + with GNU libc on Linux kernels before 2.6.36, which stats all + preceding entries in /proc/mounts; that makes df hang if even one + of the corresponding file systems is hard-mounted but not available. */ +# if ! (__linux__ && (__GLIBC__ || __UCLIBC__)) +static int +statvfs_works (void) +{ + return 1; +} +#else +#include /* for strverscmp */ +#include +#include +#define STAT_STATFS2_BSIZE 1 + +static int +statvfs_works (void) +{ + static int statvfs_works_cache = -1; + struct utsname name; + + if (statvfs_works_cache < 0) + statvfs_works_cache = (uname (&name) == 0 && 0 <= strverscmp (name.release, "2.6.36")); + return statvfs_works_cache; +} +#endif +#endif + +#ifdef STAT_READ_FILSYS /* SVR2 */ /* Set errno to zero upon EOF. */ #define ZERO_BYTE_TRANSFER_ERRNO 0 @@ -1300,21 +1330,32 @@ full_read (int fd, void *buf, size_t count) static int get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) { -#ifdef STAT_STATVFS /* POSIX, except glibc/Linux */ +#ifdef STAT_STATVFS /* POSIX, except pre-2.6.36 glibc/Linux */ - struct statvfs fsd; - - if (statvfs (file, &fsd) < 0) - return -1; + if (statvfs_works ()) + { + struct statvfs vfsd; + + if (statvfs (file, &vfsd) < 0) + return -1; + + /* f_frsize isn't guaranteed to be supported. */ + fsp->fsu_blocksize = (vfsd.f_frsize + ? PROPAGATE_ALL_ONES (vfsd.f_frsize) + : PROPAGATE_ALL_ONES (vfsd.f_bsize)); + + fsp->fsu_blocks = PROPAGATE_ALL_ONES (vfsd.f_blocks); + fsp->fsu_bfree = PROPAGATE_ALL_ONES (vfsd.f_bfree); + fsp->fsu_bavail = PROPAGATE_TOP_BIT (vfsd.f_bavail); + fsp->fsu_bavail_top_bit_set = EXTRACT_TOP_BIT (vfsd.f_bavail) != 0; + fsp->fsu_files = PROPAGATE_ALL_ONES (vfsd.f_files); + fsp->fsu_ffree = PROPAGATE_ALL_ONES (vfsd.f_ffree); + return 0; + } - /* f_frsize isn't guaranteed to be supported. */ - /* *INDENT-OFF* */ - fsp->fsu_blocksize = fsd.f_frsize - ? PROPAGATE_ALL_ONES (fsd.f_frsize) - : PROPAGATE_ALL_ONES (fsd.f_bsize); - /* *INDENT-ON* */ +#endif -#elif defined STAT_STATVFS64 /* AIX */ +#if defined STAT_STATVFS64 /* AIX */ struct statvfs64 fsd; @@ -1444,7 +1485,7 @@ get_fs_usage (char const *file, char const *disk, struct fs_usage *fsp) #endif -#if (defined STAT_STATVFS || defined STAT_STATVFS64 \ +#if (defined STAT_STATVFS64 \ || (!defined STAT_STATFS2_FS_DATA && !defined STAT_READ_FILSYS)) fsp->fsu_blocks = PROPAGATE_ALL_ONES (fsd.f_blocks); -- 2.11.4.GIT