mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-09-28 10:07:13 +02:00
Implemented _g_get_unix_mounts() based on libmount
https://bugzilla.gnome.org/show_bug.cgi?id=522053
This commit is contained in:
@@ -326,25 +326,92 @@ guess_system_internal (const char *mountpoint,
|
|||||||
|
|
||||||
/* GUnixMounts (ie: mtab) implementations {{{1 */
|
/* GUnixMounts (ie: mtab) implementations {{{1 */
|
||||||
|
|
||||||
|
static GUnixMountEntry *
|
||||||
|
create_unix_mount_entry (const char *device_path,
|
||||||
|
const char *mount_path,
|
||||||
|
const char *filesystem_type,
|
||||||
|
gboolean is_read_only)
|
||||||
|
{
|
||||||
|
GUnixMountEntry *mount_entry = NULL;
|
||||||
|
|
||||||
|
mount_entry = g_new0 (GUnixMountEntry, 1);
|
||||||
|
mount_entry->device_path = g_strdup (device_path);
|
||||||
|
mount_entry->mount_path = g_strdup (mount_path);
|
||||||
|
mount_entry->filesystem_type = g_strdup (filesystem_type);
|
||||||
|
mount_entry->is_read_only = is_read_only;
|
||||||
|
|
||||||
|
mount_entry->is_system_internal =
|
||||||
|
guess_system_internal (mount_entry->mount_path,
|
||||||
|
mount_entry->filesystem_type,
|
||||||
|
mount_entry->device_path);
|
||||||
|
return mount_entry;
|
||||||
|
}
|
||||||
|
|
||||||
/* mntent.h (Linux, GNU, NSS) {{{2 */
|
/* mntent.h (Linux, GNU, NSS) {{{2 */
|
||||||
#ifdef HAVE_MNTENT_H
|
#ifdef HAVE_MNTENT_H
|
||||||
|
|
||||||
static char *
|
#ifdef HAVE_LIBMOUNT
|
||||||
get_mtab_read_file (void)
|
|
||||||
|
static GList *
|
||||||
|
_g_get_unix_mounts (void)
|
||||||
{
|
{
|
||||||
#ifdef _PATH_MOUNTED
|
struct libmnt_table *table = NULL;
|
||||||
# ifdef __linux__
|
struct libmnt_context *ctxt = NULL;
|
||||||
return "/proc/mounts";
|
struct libmnt_iter* iter = NULL;
|
||||||
# else
|
struct libmnt_fs *fs = NULL;
|
||||||
return _PATH_MOUNTED;
|
GUnixMountEntry *mount_entry = NULL;
|
||||||
# endif
|
GList *return_list = NULL;
|
||||||
#else
|
|
||||||
return "/etc/mtab";
|
ctxt = mnt_new_context ();
|
||||||
#endif
|
mnt_context_get_table (ctxt, "/proc/self/mountinfo", &table);
|
||||||
|
if (!table)
|
||||||
|
mnt_context_get_mtab (ctxt, &table);
|
||||||
|
|
||||||
|
/* Not much to do if neither mountinfo nor mtab are available */
|
||||||
|
if (!table)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
iter = mnt_new_iter (MNT_ITER_FORWARD);
|
||||||
|
while (mnt_table_next_fs (table, iter, &fs) == 0)
|
||||||
|
{
|
||||||
|
const char *device_path = NULL;
|
||||||
|
char *mount_options = NULL;
|
||||||
|
unsigned long mount_flags = 0;
|
||||||
|
gboolean is_read_only = FALSE;
|
||||||
|
|
||||||
|
if (!mnt_table_is_fs_mounted (table, fs))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
device_path = mnt_fs_get_source (fs);
|
||||||
|
if (g_strcmp0 (device_path, "/dev/root") == 0)
|
||||||
|
device_path = _resolve_dev_root ();
|
||||||
|
|
||||||
|
mount_options = mnt_fs_strdup_options (fs);
|
||||||
|
if (mount_options)
|
||||||
|
{
|
||||||
|
mnt_optstr_get_flags (mount_options, &mount_flags, mnt_get_builtin_optmap (MNT_LINUX_MAP));
|
||||||
|
g_free (mount_options);
|
||||||
|
}
|
||||||
|
is_read_only = (mount_flags & MS_RDONLY) ? TRUE : FALSE;
|
||||||
|
|
||||||
|
mount_entry = create_unix_mount_entry (device_path,
|
||||||
|
mnt_fs_get_target (fs),
|
||||||
|
mnt_fs_get_fstype (fs),
|
||||||
|
is_read_only);
|
||||||
|
|
||||||
|
return_list = g_list_prepend (return_list, mount_entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mnt_free_iter (iter);
|
||||||
|
mnt_free_context (ctxt);
|
||||||
|
|
||||||
|
return g_list_reverse (return_list);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
get_mtab_monitor_file (void)
|
get_mtab_read_file (void)
|
||||||
{
|
{
|
||||||
#ifdef _PATH_MOUNTED
|
#ifdef _PATH_MOUNTED
|
||||||
# ifdef __linux__
|
# ifdef __linux__
|
||||||
@@ -442,6 +509,22 @@ _g_get_unix_mounts (void)
|
|||||||
return g_list_reverse (return_list);
|
return g_list_reverse (return_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* HAVE_LIBMOUNT */
|
||||||
|
|
||||||
|
static char *
|
||||||
|
get_mtab_monitor_file (void)
|
||||||
|
{
|
||||||
|
#ifdef _PATH_MOUNTED
|
||||||
|
# ifdef __linux__
|
||||||
|
return "/proc/mounts";
|
||||||
|
# else
|
||||||
|
return _PATH_MOUNTED;
|
||||||
|
# endif
|
||||||
|
#else
|
||||||
|
return "/etc/mtab";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* mnttab.h {{{2 */
|
/* mnttab.h {{{2 */
|
||||||
#elif defined (HAVE_SYS_MNTTAB_H)
|
#elif defined (HAVE_SYS_MNTTAB_H)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user