Ticket #1642: filegui.c contains Linux-specific things

mc 4.7.0-pre1 introduced dynamic "Save attributes" checkbox value in Copy/Move dialog.
But code is Linux-specific, and not even isolated by macros.

I suggest to add code specific for BSD and SVR4 systems.

In BSD systems (MacOS X, NetBSD, FreeBSD) there is statfs.f_fstypename which contains name of filesystem.
Valid FS names are: msdos, msdosfs (FreeBSD), ntfs, smbfs, procfs, fusefs (BSD), fusefs_subfstype (Mac)

In SVR4 systems (Solaris and other SVR4 Unixes) there are statvfs.f_basetype and statvfs
syscall instead of statfs and also autotools define STAT_STATVFS.
Valid FS names are: pcfs, proc, ntfs, fuse, smbfs

(Note that NetBSD 3.0+ also use statvfs but with BSD syntax.)

For all other OSes we simply return 1.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
sfionov 2009-10-20 01:22:43 +03:00 committed by Slava Zanko
parent ff860abd70
commit 1551db2f9f
2 changed files with 43 additions and 13 deletions

View File

@ -628,6 +628,11 @@ AC_DEFUN([gl_FSTYPENAME],
#include <sys/param.h>
#include <sys/mount.h>
])
AC_CHECK_MEMBERS([struct statvfs.f_fstypename, struct statvfs.f_basetype],,,
[
AC_INCLUDES_DEFAULT
#include <sys/statvfs.h>
])
])
dnl

View File

@ -55,19 +55,23 @@
#include <sys/types.h>
#include <sys/stat.h>
#if defined (__FreeBSD__)
#if defined(STAT_STATVFS) \
&& (defined(HAVE_STRUCT_STATVFS_F_BASETYPE) \
|| defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME))
# include <sys/statvfs.h>
# define STRUCT_STATFS struct statvfs
# define STATFS statvfs
#elif defined(HAVE_STATFS) && !defined(STAT_STATFS4)
# ifdef HAVE_SYS_VFS_H
# include <sys/vfs.h>
# elif defined(HAVE_SYS_MOUNT_H) && defined(HAVE_SYS_PARAM_H)
# include <sys/param.h>
#endif
#if defined(__APPLE__) || defined (__FreeBSD__)
# include <sys/mount.h>
#elif defined (__NetBSD__)
# include <sys/param.h>
#else
# ifdef HAVE_VFS
# include <sys/vfs.h>
# else
# include <sys/statfs.h>
# endif
# elif defined(HAVE_SYS_STATFS_H)
# include <sys/statfs.h>
# endif
# define STRUCT_STATFS struct statfs
# define STATFS statfs
#endif
#include <unistd.h>
@ -164,14 +168,16 @@ enum {
static int
filegui__check_attrs_on_fs(const char *fs_path)
{
struct statfs stfs;
#ifdef STATFS
STRUCT_STATFS stfs;
if (!setup_copymove_persistent_attr)
return 0;
if (statfs(fs_path, &stfs)!=0)
if (STATFS(fs_path, &stfs)!=0)
return 1;
# ifdef __linux__
switch ((filegui_nonattrs_fs_t) stfs.f_type)
{
case MSDOS_SUPER_MAGIC:
@ -184,6 +190,25 @@ filegui__check_attrs_on_fs(const char *fs_path)
return 0;
break;
}
# elif defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) \
|| defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME)
if (!strcmp(stfs.f_fstypename, "msdos")
|| !strcmp(stfs.f_fstypename, "msdosfs")
|| !strcmp(stfs.f_fstypename, "ntfs")
|| !strcmp(stfs.f_fstypename, "procfs")
|| !strcmp(stfs.f_fstypename, "smbfs")
|| strstr(stfs.f_fstypename, "fusefs"))
return 0;
# elif defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
if (!strcmp(stfs.f_basetype, "pcfs")
|| !strcmp(stfs.f_basetype, "ntfs")
|| !strcmp(stfs.f_basetype, "proc")
|| !strcmp(stfs.f_basetype, "smbfs")
|| !strcmp(stfs.f_basetype, "fuse"))
return 0;
# endif
#endif /* STATFS */
return 1;
}