mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-04-16 12:28:48 +02:00
Avoid getmntinfo
- getmntinfo can take struct statfs or statvfs depending on the OS. Use getvfsstat and if not found getfsstat instead. Idea from Dan Winship. - g_local_file_query_filesystem_info(): use statvfs.f_fstypename if available https://bugzilla.gnome.org/show_bug.cgi?id=617949
This commit is contained in:
parent
5cea24fc88
commit
afa82ae805
@ -931,6 +931,7 @@ AC_CHECK_MEMBERS([struct stat.st_blksize, struct stat.st_blocks, struct statfs.f
|
|||||||
#endif])
|
#endif])
|
||||||
# struct statvfs.f_basetype is available on Solaris but not for Linux.
|
# struct statvfs.f_basetype is available on Solaris but not for Linux.
|
||||||
AC_CHECK_MEMBERS([struct statvfs.f_basetype],,, [#include <sys/statvfs.h>])
|
AC_CHECK_MEMBERS([struct statvfs.f_basetype],,, [#include <sys/statvfs.h>])
|
||||||
|
AC_CHECK_MEMBERS([struct statvfs.f_fstypename],,, [#include <sys/statvfs.h>])
|
||||||
AC_CHECK_MEMBERS([struct tm.tm_gmtoff, struct tm.__tm_gmtoff],,,[#include <time.h>])
|
AC_CHECK_MEMBERS([struct tm.tm_gmtoff, struct tm.__tm_gmtoff],,,[#include <time.h>])
|
||||||
|
|
||||||
# Checks for libcharset
|
# Checks for libcharset
|
||||||
@ -1001,14 +1002,14 @@ AC_MSG_RESULT(unsigned $glib_size_type)
|
|||||||
# Check for some functions
|
# Check for some functions
|
||||||
AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf stpcpy strcasecmp strncasecmp poll getcwd vasprintf setenv unsetenv getc_unlocked readlink symlink fdwalk memmem)
|
AC_CHECK_FUNCS(lstat strerror strsignal memmove vsnprintf stpcpy strcasecmp strncasecmp poll getcwd vasprintf setenv unsetenv getc_unlocked readlink symlink fdwalk memmem)
|
||||||
AC_CHECK_FUNCS(chown lchmod lchown fchmod fchown link utimes getgrgid getpwuid)
|
AC_CHECK_FUNCS(chown lchmod lchown fchmod fchown link utimes getgrgid getpwuid)
|
||||||
AC_CHECK_FUNCS(getmntent_r setmntent endmntent hasmntopt getmntinfo)
|
AC_CHECK_FUNCS(getmntent_r setmntent endmntent hasmntopt getfsstat getvfsstat)
|
||||||
# Check for high-resolution sleep functions
|
# Check for high-resolution sleep functions
|
||||||
AC_CHECK_FUNCS(splice)
|
AC_CHECK_FUNCS(splice)
|
||||||
|
|
||||||
# To avoid finding a compatibility unusable statfs, which typically
|
# To avoid finding a compatibility unusable statfs, which typically
|
||||||
# successfully compiles, but warns to use the newer statvfs interface:
|
# successfully compiles, but warns to use the newer statvfs interface:
|
||||||
AS_IF([test $ac_cv_header_sys_statvfs_h = yes], [AC_CHECK_FUNCS([statvfs])])
|
AS_IF([test $ac_cv_header_sys_statvfs_h = yes], [AC_CHECK_FUNCS([statvfs])])
|
||||||
AS_IF([test $ac_cv_header_sys_statfs_h = yes], [AC_CHECK_FUNCS([statfs])])
|
AS_IF([test $ac_cv_header_sys_statfs_h = yes -o $ac_cv_header_sys_mount_h = yes], [AC_CHECK_FUNCS([statfs])])
|
||||||
|
|
||||||
AC_MSG_CHECKING([whether to use statfs or statvfs])
|
AC_MSG_CHECKING([whether to use statfs or statvfs])
|
||||||
# Some systems have both statfs and statvfs, pick the most "native" for these
|
# Some systems have both statfs and statvfs, pick the most "native" for these
|
||||||
|
@ -578,7 +578,7 @@ g_local_file_get_child_for_display_name (GFile *file,
|
|||||||
return new_file;
|
return new_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_STATFS
|
#if defined(USE_STATFS) && !defined(HAVE_STRUCT_STATFS_F_FSTYPENAME)
|
||||||
static const char *
|
static const char *
|
||||||
get_fs_type (long f_type)
|
get_fs_type (long f_type)
|
||||||
{
|
{
|
||||||
@ -996,15 +996,19 @@ g_local_file_query_filesystem_info (GFile *file,
|
|||||||
#ifndef G_OS_WIN32
|
#ifndef G_OS_WIN32
|
||||||
#ifdef USE_STATFS
|
#ifdef USE_STATFS
|
||||||
#if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME)
|
#if defined(HAVE_STRUCT_STATFS_F_FSTYPENAME)
|
||||||
fstype = g_strdup(statfs_buffer.f_fstypename);
|
fstype = g_strdup (statfs_buffer.f_fstypename);
|
||||||
#else
|
#else
|
||||||
fstype = get_fs_type (statfs_buffer.f_type);
|
fstype = get_fs_type (statfs_buffer.f_type);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif defined(USE_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
|
#elif defined(USE_STATVFS)
|
||||||
fstype = g_strdup(statfs_buffer.f_basetype);
|
#if defined(HAVE_STRUCT_STATVFS_F_FSTYPENAME)
|
||||||
|
fstype = g_strdup (statfs_buffer.f_fstypename);
|
||||||
|
#elif defined(HAVE_STRUCT_STATVFS_F_BASETYPE)
|
||||||
|
fstype = g_strdup (statfs_buffer.f_basetype);
|
||||||
#else
|
#else
|
||||||
fstype = NULL;
|
fstype = NULL;
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (fstype &&
|
if (fstype &&
|
||||||
|
@ -73,7 +73,9 @@
|
|||||||
#include "gthemedicon.h"
|
#include "gthemedicon.h"
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef HAVE_MNTENT_H
|
||||||
static const char *_resolve_dev_root (void);
|
static const char *_resolve_dev_root (void);
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SECTION:gunixmounts
|
* SECTION:gunixmounts
|
||||||
@ -187,7 +189,7 @@ G_DEFINE_TYPE (GUnixMountMonitor, g_unix_mount_monitor, G_TYPE_OBJECT);
|
|||||||
#include <fshelp.h>
|
#include <fshelp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
|
#if (defined(HAVE_GETVFSSTAT) || defined(HAVE_GETFSSTAT)) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
|
||||||
#include <sys/ucred.h>
|
#include <sys/ucred.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
#include <fstab.h>
|
#include <fstab.h>
|
||||||
@ -582,7 +584,7 @@ _g_get_unix_mounts (void)
|
|||||||
return g_list_reverse (return_list);
|
return g_list_reverse (return_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
|
#elif (defined(HAVE_GETVFSSTAT) || defined(HAVE_GETFSSTAT)) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
get_mtab_monitor_file (void)
|
get_mtab_monitor_file (void)
|
||||||
@ -593,19 +595,35 @@ get_mtab_monitor_file (void)
|
|||||||
static GList *
|
static GList *
|
||||||
_g_get_unix_mounts (void)
|
_g_get_unix_mounts (void)
|
||||||
{
|
{
|
||||||
#if defined(USE_STATFS)
|
#if defined(HAVE_GETVFSSTAT)
|
||||||
struct statfs *mntent = NULL;
|
|
||||||
#elif defined(USE_STATVFS)
|
|
||||||
struct statvfs *mntent = NULL;
|
struct statvfs *mntent = NULL;
|
||||||
|
#elif defined(HAVE_GETFSSTAT)
|
||||||
|
struct statfs *mntent = NULL;
|
||||||
#else
|
#else
|
||||||
#error statfs juggling failed
|
#error statfs juggling failed
|
||||||
#endif
|
#endif
|
||||||
|
size_t bufsize;
|
||||||
int num_mounts, i;
|
int num_mounts, i;
|
||||||
GUnixMountEntry *mount_entry;
|
GUnixMountEntry *mount_entry;
|
||||||
GList *return_list;
|
GList *return_list;
|
||||||
|
|
||||||
/* Pass MNT_NOWAIT to avoid blocking trying to update NFS mounts. */
|
/* Pass NOWAIT to avoid blocking trying to update NFS mounts. */
|
||||||
if ((num_mounts = getmntinfo (&mntent, MNT_NOWAIT)) == 0)
|
#if defined(HAVE_GETVFSSTAT)
|
||||||
|
num_mounts = getvfsstat (NULL, 0, ST_NOWAIT);
|
||||||
|
#elif defined(HAVE_GETFSSTAT)
|
||||||
|
num_mounts = getfsstat (NULL, 0, MNT_NOWAIT);
|
||||||
|
#endif
|
||||||
|
if (num_mounts == -1)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
bufsize = num_mounts * sizeof (*mntent);
|
||||||
|
mntent = g_malloc (bufsize);
|
||||||
|
#if defined(HAVE_GETVFSSTAT)
|
||||||
|
num_mounts = getvfsstat (mntent, bufsize, ST_NOWAIT);
|
||||||
|
#elif defined(HAVE_GETFSSTAT)
|
||||||
|
num_mounts = getfsstat (mntent, bufsize, MNT_NOWAIT);
|
||||||
|
#endif
|
||||||
|
if (num_mounts == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return_list = NULL;
|
return_list = NULL;
|
||||||
@ -617,20 +635,22 @@ _g_get_unix_mounts (void)
|
|||||||
mount_entry->mount_path = g_strdup (mntent[i].f_mntonname);
|
mount_entry->mount_path = g_strdup (mntent[i].f_mntonname);
|
||||||
mount_entry->device_path = g_strdup (mntent[i].f_mntfromname);
|
mount_entry->device_path = g_strdup (mntent[i].f_mntfromname);
|
||||||
mount_entry->filesystem_type = g_strdup (mntent[i].f_fstypename);
|
mount_entry->filesystem_type = g_strdup (mntent[i].f_fstypename);
|
||||||
#if defined(USE_STATFS)
|
#if defined(HAVE_GETVFSSTAT)
|
||||||
|
if (mntent[i].f_flag & ST_RDONLY)
|
||||||
|
#elif defined(HAVE_GETFSSTAT)
|
||||||
if (mntent[i].f_flags & MNT_RDONLY)
|
if (mntent[i].f_flags & MNT_RDONLY)
|
||||||
#elif defined(USE_STATVFS)
|
|
||||||
if (mntent[i].f_flag & MNT_RDONLY)
|
|
||||||
#endif
|
#endif
|
||||||
mount_entry->is_read_only = TRUE;
|
mount_entry->is_read_only = TRUE;
|
||||||
|
|
||||||
mount_entry->is_system_internal =
|
mount_entry->is_system_internal =
|
||||||
guess_system_internal (mount_entry->mount_path,
|
guess_system_internal (mount_entry->mount_path,
|
||||||
mount_entry->filesystem_type,
|
mount_entry->filesystem_type,
|
||||||
mount_entry->device_path);
|
mount_entry->device_path);
|
||||||
|
|
||||||
return_list = g_list_prepend (return_list, mount_entry);
|
return_list = g_list_prepend (return_list, mount_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_free (mntent);
|
||||||
|
|
||||||
return g_list_reverse (return_list);
|
return g_list_reverse (return_list);
|
||||||
}
|
}
|
||||||
@ -993,7 +1013,7 @@ _g_get_unix_mount_points (void)
|
|||||||
return g_list_reverse (return_list);
|
return g_list_reverse (return_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
|
#elif (defined(HAVE_GETVFSSTAT) || defined(HAVE_GETFSSTAT)) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
|
||||||
|
|
||||||
static GList *
|
static GList *
|
||||||
_g_get_unix_mount_points (void)
|
_g_get_unix_mount_points (void)
|
||||||
@ -1003,7 +1023,6 @@ _g_get_unix_mount_points (void)
|
|||||||
GList *return_list;
|
GList *return_list;
|
||||||
#ifdef HAVE_SYS_SYSCTL_H
|
#ifdef HAVE_SYS_SYSCTL_H
|
||||||
int usermnt = 0;
|
int usermnt = 0;
|
||||||
size_t len = sizeof(usermnt);
|
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -2047,7 +2066,7 @@ g_unix_mount_point_guess_can_eject (GUnixMountPoint *mount_point)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_MNTENT_H
|
||||||
/* borrowed from gtk/gtkfilesystemunix.c in GTK+ on 02/23/2006 */
|
/* borrowed from gtk/gtkfilesystemunix.c in GTK+ on 02/23/2006 */
|
||||||
static void
|
static void
|
||||||
_canonicalize_filename (gchar *filename)
|
_canonicalize_filename (gchar *filename)
|
||||||
@ -2154,7 +2173,6 @@ _resolve_symlink (const char *file)
|
|||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_MNTENT_H
|
|
||||||
static const char *
|
static const char *
|
||||||
_resolve_dev_root (void)
|
_resolve_dev_root (void)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user