1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
3 /* GIO - GLib Input, Output and Streaming Library
5 * Copyright (C) 2006-2007 Red Hat, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307, USA.
22 * Author: Alexander Larsson <alexl@redhat.com>
27 #include <sys/types.h>
30 #ifndef HAVE_SYSCTLBYNAME
31 #ifdef HAVE_SYS_PARAM_H
32 #include <sys/param.h>
34 #ifdef HAVE_SYS_POLL_H
48 #include "gunixmounts.h"
50 #include "gfilemonitor.h"
52 #include "gthemedicon.h"
56 static const char *_resolve_dev_root (void);
60 * @include: gio/gunixmounts.h
61 * @short_description: Unix Mounts
63 * Routines for managing mounted UNIX mount points and paths.
69 * @G_UNIX_MOUNT_TYPE_UNKNOWN: Unknown UNIX mount type.
70 * @G_UNIX_MOUNT_TYPE_FLOPPY: Floppy disk UNIX mount type.
71 * @G_UNIX_MOUNT_TYPE_CDROM: CDROM UNIX mount type.
72 * @G_UNIX_MOUNT_TYPE_NFS: Network File System (NFS) UNIX mount type.
73 * @G_UNIX_MOUNT_TYPE_ZIP: ZIP UNIX mount type.
74 * @G_UNIX_MOUNT_TYPE_JAZ: JAZZ UNIX mount type.
75 * @G_UNIX_MOUNT_TYPE_MEMSTICK: Memory Stick UNIX mount type.
76 * @G_UNIX_MOUNT_TYPE_CF: Compact Flash UNIX mount type.
77 * @G_UNIX_MOUNT_TYPE_SM: Smart Media UNIX mount type.
78 * @G_UNIX_MOUNT_TYPE_SDMMC: SD/MMC UNIX mount type.
79 * @G_UNIX_MOUNT_TYPE_IPOD: iPod UNIX mount type.
80 * @G_UNIX_MOUNT_TYPE_CAMERA: Digital camera UNIX mount type.
81 * @G_UNIX_MOUNT_TYPE_HD: Hard drive UNIX mount type.
83 * Types of UNIX mounts.
86 G_UNIX_MOUNT_TYPE_UNKNOWN,
87 G_UNIX_MOUNT_TYPE_FLOPPY,
88 G_UNIX_MOUNT_TYPE_CDROM,
89 G_UNIX_MOUNT_TYPE_NFS,
90 G_UNIX_MOUNT_TYPE_ZIP,
91 G_UNIX_MOUNT_TYPE_JAZ,
92 G_UNIX_MOUNT_TYPE_MEMSTICK,
95 G_UNIX_MOUNT_TYPE_SDMMC,
96 G_UNIX_MOUNT_TYPE_IPOD,
97 G_UNIX_MOUNT_TYPE_CAMERA,
101 struct _GUnixMountEntry {
104 char *filesystem_type;
105 gboolean is_read_only;
106 gboolean is_system_internal;
109 struct _GUnixMountPoint {
112 char *filesystem_type;
113 gboolean is_read_only;
114 gboolean is_user_mountable;
115 gboolean is_loopback;
124 static guint signals[LAST_SIGNAL];
126 struct _GUnixMountMonitor {
129 GFileMonitor *fstab_monitor;
130 GFileMonitor *mtab_monitor;
133 struct _GUnixMountMonitorClass {
134 GObjectClass parent_class;
137 static GUnixMountMonitor *the_mount_monitor = NULL;
139 static GList *_g_get_unix_mounts (void);
140 static GList *_g_get_unix_mount_points (void);
142 G_DEFINE_TYPE (GUnixMountMonitor, g_unix_mount_monitor, G_TYPE_OBJECT);
144 #define MOUNT_POLL_INTERVAL 4000
146 #ifdef HAVE_SYS_MNTTAB_H
147 #define MNTOPT_RO "ro"
152 #elif defined (HAVE_SYS_MNTTAB_H)
153 #include <sys/mnttab.h>
156 #ifdef HAVE_SYS_VFSTAB_H
157 #include <sys/vfstab.h>
160 #if defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
161 #include <sys/mntctl.h>
163 #include <sys/vmount.h>
167 #if defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
168 #include <sys/ucred.h>
169 #include <sys/mount.h>
171 #ifdef HAVE_SYS_SYSCTL_H
172 #include <sys/sysctl.h>
176 #ifndef HAVE_SETMNTENT
177 #define setmntent(f,m) fopen(f,m)
179 #ifndef HAVE_ENDMNTENT
180 #define endmntent(f) fclose(f)
184 is_in (const char *value, const char *set[])
187 for (i = 0; set[i] != NULL; i++)
189 if (strcmp (set[i], value) == 0)
196 * g_unix_is_mount_path_system_internal:
197 * @mount_path: a mount path, e.g. <filename>/media/disk</filename>
198 * or <filename>/usr</filename>
200 * Determines if @mount_path is considered an implementation of the
201 * OS. This is primarily used for hiding mountable and mounted volumes
202 * that only are used in the OS and has little to no relevance to the
205 * Returns: %TRUE if @mount_path is considered an implementation detail
209 g_unix_is_mount_path_system_internal (const char *mount_path)
211 const char *ignore_mountpoints[] = {
212 /* Includes all FHS 2.3 toplevel dirs and other specilized
213 * directories that we want to hide from the user.
215 "/", /* we already have "Filesystem root" in Nautilus */
232 "/var/log/audit", /* https://bugzilla.redhat.com/show_bug.cgi?id=333041 */
233 "/var/tmp", /* https://bugzilla.redhat.com/show_bug.cgi?id=335241 */
240 if (is_in (mount_path, ignore_mountpoints))
243 if (g_str_has_prefix (mount_path, "/dev") ||
244 g_str_has_prefix (mount_path, "/proc") ||
245 g_str_has_prefix (mount_path, "/sys"))
248 if (strstr (mount_path, "/.gvfs") != NULL)
255 guess_system_internal (const char *mountpoint,
259 const char *ignore_fs[] = {
277 const char *ignore_devices[] = {
287 if (is_in (fs, ignore_fs))
290 if (is_in (device, ignore_devices))
293 if (g_unix_is_mount_path_system_internal (mountpoint))
302 get_mtab_read_file (void)
306 return "/proc/mounts";
308 return _PATH_MOUNTED;
316 get_mtab_monitor_file (void)
319 return _PATH_MOUNTED;
325 G_LOCK_DEFINE_STATIC(getmntent);
328 _g_get_unix_mounts ()
330 struct mntent *mntent;
333 GUnixMountEntry *mount_entry;
334 GHashTable *mounts_hash;
337 read_file = get_mtab_read_file ();
339 file = setmntent (read_file, "r");
345 mounts_hash = g_hash_table_new (g_str_hash, g_str_equal);
348 while ((mntent = getmntent (file)) != NULL)
350 /* ignore any mnt_fsname that is repeated and begins with a '/'
352 * We do this to avoid being fooled by --bind mounts, since
353 * these have the same device as the location they bind to.
354 * Its not an ideal solution to the problem, but its likely that
355 * the most important mountpoint is first and the --bind ones after
356 * that aren't as important. So it should work.
358 * The '/' is to handle procfs, tmpfs and other no device mounts.
360 if (mntent->mnt_fsname != NULL &&
361 mntent->mnt_fsname[0] == '/' &&
362 g_hash_table_lookup (mounts_hash, mntent->mnt_fsname))
365 mount_entry = g_new0 (GUnixMountEntry, 1);
366 mount_entry->mount_path = g_strdup (mntent->mnt_dir);
367 if (strcmp (mntent->mnt_fsname, "/dev/root") == 0)
368 mount_entry->device_path = g_strdup (_resolve_dev_root ());
370 mount_entry->device_path = g_strdup (mntent->mnt_fsname);
371 mount_entry->filesystem_type = g_strdup (mntent->mnt_type);
373 #if defined (HAVE_HASMNTOPT)
374 if (hasmntopt (mntent, MNTOPT_RO) != NULL)
375 mount_entry->is_read_only = TRUE;
378 mount_entry->is_system_internal =
379 guess_system_internal (mount_entry->mount_path,
380 mount_entry->filesystem_type,
381 mount_entry->device_path);
383 g_hash_table_insert (mounts_hash,
384 mount_entry->device_path,
385 mount_entry->device_path);
387 return_list = g_list_prepend (return_list, mount_entry);
389 g_hash_table_destroy (mounts_hash);
393 G_UNLOCK (getmntent);
395 return g_list_reverse (return_list);
398 #elif defined (HAVE_SYS_MNTTAB_H)
400 G_LOCK_DEFINE_STATIC(getmntent);
403 get_mtab_read_file (void)
406 return _PATH_MOUNTED;
408 return "/etc/mnttab";
413 get_mtab_monitor_file (void)
415 return get_mtab_read_file ();
419 _g_get_unix_mounts (void)
421 struct mnttab mntent;
424 GUnixMountEntry *mount_entry;
427 read_file = get_mtab_read_file ();
429 file = setmntent (read_file, "r");
436 while (! getmntent (file, &mntent))
438 mount_entry = g_new0 (GUnixMountEntry, 1);
440 mount_entry->mount_path = g_strdup (mntent.mnt_mountp);
441 mount_entry->device_path = g_strdup (mntent.mnt_special);
442 mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype);
444 #if defined (HAVE_HASMNTOPT)
445 if (hasmntopt (&mntent, MNTOPT_RO) != NULL)
446 mount_entry->is_read_only = TRUE;
449 mount_entry->is_system_internal =
450 guess_system_internal (mount_entry->mount_path,
451 mount_entry->filesystem_type,
452 mount_entry->device_path);
454 return_list = g_list_prepend (return_list, mount_entry);
459 G_UNLOCK (getmntent);
461 return g_list_reverse (return_list);
464 #elif defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
467 get_mtab_monitor_file (void)
473 _g_get_unix_mounts (void)
475 struct vfs_ent *fs_info;
476 struct vmount *vmount_info;
478 unsigned int vmount_size;
482 if (mntctl (MCTL_QUERY, sizeof (vmount_size), &vmount_size) != 0)
484 g_warning ("Unable to know the number of mounted volumes\n");
489 vmount_info = (struct vmount*)g_malloc (vmount_size);
491 vmount_number = mntctl (MCTL_QUERY, vmount_size, vmount_info);
493 if (vmount_info->vmt_revision != VMT_REVISION)
494 g_warning ("Bad vmount structure revision number, want %d, got %d\n", VMT_REVISION, vmount_info->vmt_revision);
496 if (vmount_number < 0)
498 g_warning ("Unable to recover mounted volumes information\n");
500 g_free (vmount_info);
505 while (vmount_number > 0)
507 mount_entry = g_new0 (GUnixMountEntry, 1);
509 mount_entry->device_path = g_strdup (vmt2dataptr (vmount_info, VMT_OBJECT));
510 mount_entry->mount_path = g_strdup (vmt2dataptr (vmount_info, VMT_STUB));
511 /* is_removable = (vmount_info->vmt_flags & MNT_REMOVABLE) ? 1 : 0; */
512 mount_entry->is_read_only = (vmount_info->vmt_flags & MNT_READONLY) ? 1 : 0;
514 fs_info = getvfsbytype (vmount_info->vmt_gfstype);
517 mount_entry->filesystem_type = g_strdup ("unknown");
519 mount_entry->filesystem_type = g_strdup (fs_info->vfsent_name);
521 mount_entry->is_system_internal =
522 guess_system_internal (mount_entry->mount_path,
523 mount_entry->filesystem_type,
524 mount_entry->device_path);
526 return_list = g_list_prepend (return_list, mount_entry);
528 vmount_info = (struct vmount *)( (char*)vmount_info
529 + vmount_info->vmt_length);
534 g_free (vmount_info);
536 return g_list_reverse (return_list);
539 #elif defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
542 get_mtab_monitor_file (void)
548 _g_get_unix_mounts (void)
550 struct statfs *mntent = NULL;
552 GUnixMountEntry *mount_entry;
555 /* Pass MNT_NOWAIT to avoid blocking trying to update NFS mounts. */
556 if ((num_mounts = getmntinfo (&mntent, MNT_NOWAIT)) == 0)
561 for (i = 0; i < num_mounts; i++)
563 mount_entry = g_new0 (GUnixMountEntry, 1);
565 mount_entry->mount_path = g_strdup (mntent[i].f_mntonname);
566 mount_entry->device_path = g_strdup (mntent[i].f_mntfromname);
567 mount_entry->filesystem_type = g_strdup (mntent[i].f_fstypename);
568 if (mntent[i].f_flags & MNT_RDONLY)
569 mount_entry->is_read_only = TRUE;
571 mount_entry->is_system_internal =
572 guess_system_internal (mount_entry->mount_path,
573 mount_entry->filesystem_type,
574 mount_entry->device_path);
576 return_list = g_list_prepend (return_list, mount_entry);
579 return g_list_reverse (return_list);
582 #error No _g_get_unix_mounts() implementation for system
585 /* _g_get_unix_mount_points():
587 * don't return swap and ignore mounts.
591 get_fstab_file (void)
593 #if defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
595 return "/etc/filesystems";
596 #elif defined(_PATH_MNTTAB)
598 #elif defined(VFSTAB)
607 _g_get_unix_mount_points (void)
609 struct mntent *mntent;
612 GUnixMountPoint *mount_entry;
615 read_file = get_fstab_file ();
617 file = setmntent (read_file, "r");
624 while ((mntent = getmntent (file)) != NULL)
626 if ((strcmp (mntent->mnt_dir, "ignore") == 0) ||
627 (strcmp (mntent->mnt_dir, "swap") == 0))
630 mount_entry = g_new0 (GUnixMountPoint, 1);
631 mount_entry->mount_path = g_strdup (mntent->mnt_dir);
632 if (strcmp (mntent->mnt_fsname, "/dev/root") == 0)
633 mount_entry->device_path = g_strdup (_resolve_dev_root ());
635 mount_entry->device_path = g_strdup (mntent->mnt_fsname);
636 mount_entry->filesystem_type = g_strdup (mntent->mnt_type);
638 #ifdef HAVE_HASMNTOPT
639 if (hasmntopt (mntent, MNTOPT_RO) != NULL)
640 mount_entry->is_read_only = TRUE;
642 if (hasmntopt (mntent, "loop") != NULL)
643 mount_entry->is_loopback = TRUE;
647 if ((mntent->mnt_type != NULL && strcmp ("supermount", mntent->mnt_type) == 0)
648 #ifdef HAVE_HASMNTOPT
649 || (hasmntopt (mntent, "user") != NULL
650 && hasmntopt (mntent, "user") != hasmntopt (mntent, "user_xattr"))
651 || hasmntopt (mntent, "pamconsole") != NULL
652 || hasmntopt (mntent, "users") != NULL
653 || hasmntopt (mntent, "owner") != NULL
656 mount_entry->is_user_mountable = TRUE;
658 return_list = g_list_prepend (return_list, mount_entry);
662 G_UNLOCK (getmntent);
664 return g_list_reverse (return_list);
667 #elif defined (HAVE_SYS_MNTTAB_H)
670 _g_get_unix_mount_points (void)
672 struct mnttab mntent;
675 GUnixMountPoint *mount_entry;
678 read_file = get_fstab_file ();
680 file = setmntent (read_file, "r");
687 while (! getmntent (file, &mntent))
689 if ((strcmp (mntent.mnt_mountp, "ignore") == 0) ||
690 (strcmp (mntent.mnt_mountp, "swap") == 0))
693 mount_entry = g_new0 (GUnixMountPoint, 1);
695 mount_entry->mount_path = g_strdup (mntent.mnt_mountp);
696 mount_entry->device_path = g_strdup (mntent.mnt_special);
697 mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype);
699 #ifdef HAVE_HASMNTOPT
700 if (hasmntopt (&mntent, MNTOPT_RO) != NULL)
701 mount_entry->is_read_only = TRUE;
703 if (hasmntopt (&mntent, "lofs") != NULL)
704 mount_entry->is_loopback = TRUE;
707 if ((mntent.mnt_fstype != NULL)
708 #ifdef HAVE_HASMNTOPT
709 || (hasmntopt (&mntent, "user") != NULL
710 && hasmntopt (&mntent, "user") != hasmntopt (&mntent, "user_xattr"))
711 || hasmntopt (&mntent, "pamconsole") != NULL
712 || hasmntopt (&mntent, "users") != NULL
713 || hasmntopt (&mntent, "owner") != NULL
716 mount_entry->is_user_mountable = TRUE;
719 return_list = g_list_prepend (return_list, mount_entry);
723 G_UNLOCK (getmntent);
725 return g_list_reverse (return_list);
727 #elif defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
729 /* functions to parse /etc/filesystems on aix */
731 /* read character, ignoring comments (begin with '*', end with '\n' */
733 aix_fs_getc (FILE *fd)
737 while ((c = getc (fd)) == '*')
739 while (((c = getc (fd)) != '\n') && (c != EOF))
744 /* eat all continuous spaces in a file */
746 aix_fs_ignorespace (FILE *fd)
750 while ((c = aix_fs_getc (fd)) != EOF)
752 if (!g_ascii_isspace (c))
762 /* read one word from file */
764 aix_fs_getword (FILE *fd,
769 aix_fs_ignorespace (fd);
771 while (((c = aix_fs_getc (fd)) != EOF) && !g_ascii_isspace (c))
775 while (((c = aix_fs_getc (fd)) != EOF) && (c != '"'))
787 char mnt_mount[PATH_MAX];
788 char mnt_special[PATH_MAX];
790 char mnt_options[128];
791 } AixMountTableEntry;
793 /* read mount points properties */
795 aix_fs_get (FILE *fd,
796 AixMountTableEntry *prop)
798 static char word[PATH_MAX] = { 0 };
799 char value[PATH_MAX];
804 if (aix_fs_getword (fd, word) == EOF)
808 word[strlen(word) - 1] = 0;
809 strcpy (prop->mnt_mount, word);
811 /* read attributes and value */
813 while (aix_fs_getword (fd, word) != EOF)
815 /* test if is attribute or new stanza */
816 if (word[strlen(word) - 1] == ':')
820 aix_fs_getword (fd, value);
823 aix_fs_getword (fd, value);
825 if (strcmp (word, "dev") == 0)
826 strcpy (prop->mnt_special, value);
827 else if (strcmp (word, "vfs") == 0)
828 strcpy (prop->mnt_fstype, value);
829 else if (strcmp (word, "options") == 0)
830 strcpy(prop->mnt_options, value);
837 _g_get_unix_mount_points (void)
839 struct mntent *mntent;
842 GUnixMountPoint *mount_entry;
843 AixMountTableEntry mntent;
846 read_file = get_fstab_file ();
848 file = setmntent (read_file, "r");
854 while (!aix_fs_get (file, &mntent))
856 if (strcmp ("cdrfs", mntent.mnt_fstype) == 0)
858 mount_entry = g_new0 (GUnixMountPoint, 1);
861 mount_entry->mount_path = g_strdup (mntent.mnt_mount);
862 mount_entry->device_path = g_strdup (mntent.mnt_special);
863 mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype);
864 mount_entry->is_read_only = TRUE;
865 mount_entry->is_user_mountable = TRUE;
867 return_list = g_list_prepend (return_list, mount_entry);
873 return g_list_reverse (return_list);
876 #elif defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
879 _g_get_unix_mount_points (void)
881 struct fstab *fstab = NULL;
882 GUnixMountPoint *mount_entry;
884 #ifdef HAVE_SYS_SYSCTL_H
886 size_t len = sizeof(usermnt);
895 #ifdef HAVE_SYS_SYSCTL_H
896 #if defined(HAVE_SYSCTLBYNAME)
897 sysctlbyname ("vfs.usermount", &usermnt, &len, NULL, 0);
898 #elif defined(CTL_VFS) && defined(VFS_USERMOUNT)
903 mib[1] = VFS_USERMOUNT;
904 sysctl (mib, 2, &usermnt, &len, NULL, 0);
906 #elif defined(CTL_KERN) && defined(KERN_USERMOUNT)
911 mib[1] = KERN_USERMOUNT;
912 sysctl (mib, 2, &usermnt, &len, NULL, 0);
917 while ((fstab = getfsent ()) != NULL)
919 if (strcmp (fstab->fs_vfstype, "swap") == 0)
922 mount_entry = g_new0 (GUnixMountPoint, 1);
924 mount_entry->mount_path = g_strdup (fstab->fs_file);
925 mount_entry->device_path = g_strdup (fstab->fs_spec);
926 mount_entry->filesystem_type = g_strdup (fstab->fs_vfstype);
928 if (strcmp (fstab->fs_type, "ro") == 0)
929 mount_entry->is_read_only = TRUE;
931 #ifdef HAVE_SYS_SYSCTL_H
934 uid_t uid = getuid ();
935 if (stat (fstab->fs_file, &sb) == 0)
937 if (uid == 0 || sb.st_uid == uid)
938 mount_entry->is_user_mountable = TRUE;
943 return_list = g_list_prepend (return_list, mount_entry);
948 return g_list_reverse (return_list);
951 #error No g_get_mount_table() implementation for system
955 get_mounts_timestamp (void)
957 const char *monitor_file;
960 monitor_file = get_mtab_monitor_file ();
963 if (stat (monitor_file, &buf) == 0)
964 return (guint64)buf.st_mtime;
970 get_mount_points_timestamp (void)
972 const char *monitor_file;
975 monitor_file = get_fstab_file ();
978 if (stat (monitor_file, &buf) == 0)
979 return (guint64)buf.st_mtime;
986 * @time_read: guint64 to contain a timestamp.
988 * Gets a #GList of strings containing the unix mounts.
989 * If @time_read is set, it will be filled with the mount
990 * timestamp, allowing for checking if the mounts have changed
991 * with g_unix_mounts_changed_since().
993 * Returns: a #GList of the UNIX mounts.
996 g_unix_mounts_get (guint64 *time_read)
999 *time_read = get_mounts_timestamp ();
1001 return _g_get_unix_mounts ();
1006 * @mount_path: path for a possible unix mount.
1007 * @time_read: guint64 to contain a timestamp.
1009 * Gets a #GUnixMountEntry for a given mount path. If @time_read
1010 * is set, it will be filled with a unix timestamp for checking
1011 * if the mounts have changed since with g_unix_mounts_changed_since().
1013 * Returns: a #GUnixMount.
1016 g_unix_mount_at (const char *mount_path,
1020 GUnixMountEntry *mount_entry, *found;
1022 mounts = g_unix_mounts_get (time_read);
1025 for (l = mounts; l != NULL; l = l->next)
1027 mount_entry = l->data;
1029 if (strcmp (mount_path, mount_entry->mount_path) == 0)
1030 found = mount_entry;
1032 g_unix_mount_free (mount_entry);
1035 g_list_free (mounts);
1041 * g_unix_mount_points_get:
1042 * @time_read: guint64 to contain a timestamp.
1044 * Gets a #GList of strings containing the unix mount points.
1045 * If @time_read is set, it will be filled with the mount timestamp,
1046 * allowing for checking if the mounts have changed with
1047 * g_unix_mounts_points_changed_since().
1049 * Returns: a #GList of the UNIX mountpoints.
1052 g_unix_mount_points_get (guint64 *time_read)
1055 *time_read = get_mount_points_timestamp ();
1057 return _g_get_unix_mount_points ();
1061 * g_unix_mounts_changed_since:
1062 * @time: guint64 to contain a timestamp.
1064 * Checks if the unix mounts have changed since a given unix time.
1066 * Returns: %TRUE if the mounts have changed since @time.
1069 g_unix_mounts_changed_since (guint64 time)
1071 return get_mounts_timestamp () != time;
1075 * g_unix_mount_points_changed_since:
1076 * @time: guint64 to contain a timestamp.
1078 * Checks if the unix mount points have changed since a given unix time.
1080 * Returns: %TRUE if the mount points have changed since @time.
1083 g_unix_mount_points_changed_since (guint64 time)
1085 return get_mount_points_timestamp () != time;
1089 g_unix_mount_monitor_finalize (GObject *object)
1091 GUnixMountMonitor *monitor;
1093 monitor = G_UNIX_MOUNT_MONITOR (object);
1095 if (monitor->fstab_monitor)
1097 g_file_monitor_cancel (monitor->fstab_monitor);
1098 g_object_unref (monitor->fstab_monitor);
1101 if (monitor->mtab_monitor)
1103 g_file_monitor_cancel (monitor->mtab_monitor);
1104 g_object_unref (monitor->mtab_monitor);
1107 the_mount_monitor = NULL;
1109 if (G_OBJECT_CLASS (g_unix_mount_monitor_parent_class)->finalize)
1110 (*G_OBJECT_CLASS (g_unix_mount_monitor_parent_class)->finalize) (object);
1115 g_unix_mount_monitor_class_init (GUnixMountMonitorClass *klass)
1117 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1119 gobject_class->finalize = g_unix_mount_monitor_finalize;
1121 * GUnixMountMonitor::mounts-changed:
1123 * Emitted when the unix mounts have changed.
1125 signals[MOUNTS_CHANGED] =
1126 g_signal_new ("mounts_changed",
1127 G_TYPE_FROM_CLASS (klass),
1131 g_cclosure_marshal_VOID__VOID,
1134 * GUnixMountMonitor::mountpoints-changed:
1136 * Emitted when the unix mount points have changed.
1138 signals[MOUNTPOINTS_CHANGED] =
1139 g_signal_new ("mountpoints_changed",
1140 G_TYPE_FROM_CLASS (klass),
1144 g_cclosure_marshal_VOID__VOID,
1149 fstab_file_changed (GFileMonitor *monitor,
1152 GFileMonitorEvent event_type,
1155 GUnixMountMonitor *mount_monitor;
1157 if (event_type != G_FILE_MONITOR_EVENT_CHANGED &&
1158 event_type != G_FILE_MONITOR_EVENT_CREATED &&
1159 event_type != G_FILE_MONITOR_EVENT_DELETED)
1162 mount_monitor = user_data;
1163 g_signal_emit (mount_monitor, signals[MOUNTPOINTS_CHANGED], 0);
1167 mtab_file_changed (GFileMonitor *monitor,
1170 GFileMonitorEvent event_type,
1173 GUnixMountMonitor *mount_monitor;
1175 if (event_type != G_FILE_MONITOR_EVENT_CHANGED &&
1176 event_type != G_FILE_MONITOR_EVENT_CREATED &&
1177 event_type != G_FILE_MONITOR_EVENT_DELETED)
1180 mount_monitor = user_data;
1181 g_signal_emit (mount_monitor, signals[MOUNTS_CHANGED], 0);
1185 g_unix_mount_monitor_init (GUnixMountMonitor *monitor)
1189 if (get_fstab_file () != NULL)
1191 file = g_file_new_for_path (get_fstab_file ());
1192 monitor->fstab_monitor = g_file_monitor_file (file, 0, NULL);
1193 g_object_unref (file);
1195 g_signal_connect (monitor->fstab_monitor, "changed", (GCallback)fstab_file_changed, monitor);
1198 if (get_mtab_monitor_file () != NULL)
1200 file = g_file_new_for_path (get_mtab_monitor_file ());
1201 monitor->mtab_monitor = g_file_monitor_file (file, 0, NULL);
1202 g_object_unref (file);
1204 g_signal_connect (monitor->mtab_monitor, "changed", (GCallback)mtab_file_changed, monitor);
1209 * g_unix_mount_monitor_new:
1211 * Gets a new #GUnixMountMonitor.
1213 * Returns: a #GUnixMountMonitor.
1216 g_unix_mount_monitor_new (void)
1218 if (the_mount_monitor == NULL)
1220 the_mount_monitor = g_object_new (G_TYPE_UNIX_MOUNT_MONITOR, NULL);
1221 return the_mount_monitor;
1224 return g_object_ref (the_mount_monitor);
1228 * g_unix_mount_free:
1229 * @mount_entry: a #GUnixMount.
1231 * Frees a unix mount.
1234 g_unix_mount_free (GUnixMountEntry *mount_entry)
1236 g_return_if_fail (mount_entry != NULL);
1238 g_free (mount_entry->mount_path);
1239 g_free (mount_entry->device_path);
1240 g_free (mount_entry->filesystem_type);
1241 g_free (mount_entry);
1245 * g_unix_mount_point_free:
1246 * @mount_point: unix mount point to free.
1248 * Frees a unix mount point.
1251 g_unix_mount_point_free (GUnixMountPoint *mount_point)
1253 g_return_if_fail (mount_point != NULL);
1255 g_free (mount_point->mount_path);
1256 g_free (mount_point->device_path);
1257 g_free (mount_point->filesystem_type);
1258 g_free (mount_point);
1262 strcmp_null (const char *str1,
1267 if (str1 == NULL && str2 != NULL)
1269 if (str1 != NULL && str2 == NULL)
1271 return strcmp (str1, str2);
1275 * g_unix_mount_compare:
1276 * @mount1: first #GUnixMountEntry to compare.
1277 * @mount2: second #GUnixMountEntry to compare.
1279 * Compares two unix mounts.
1281 * Returns: 1, 0 or -1 if @mount1 is greater than, equal to,
1282 * or less than @mount2, respectively.
1285 g_unix_mount_compare (GUnixMountEntry *mount1,
1286 GUnixMountEntry *mount2)
1290 g_return_val_if_fail (mount1 != NULL && mount2 != NULL, 0);
1292 res = strcmp_null (mount1->mount_path, mount2->mount_path);
1296 res = strcmp_null (mount1->device_path, mount2->device_path);
1300 res = strcmp_null (mount1->filesystem_type, mount2->filesystem_type);
1304 res = mount1->is_read_only - mount2->is_read_only;
1312 * g_unix_mount_get_mount_path:
1313 * @mount_entry: input #GUnixMountEntry to get the mount path for.
1315 * Gets the mount path for a unix mount.
1317 * Returns: the mount path for @mount_entry.
1320 g_unix_mount_get_mount_path (GUnixMountEntry *mount_entry)
1322 g_return_val_if_fail (mount_entry != NULL, NULL);
1324 return mount_entry->mount_path;
1328 * g_unix_mount_get_device_path:
1329 * @mount_entry: a #GUnixMount.
1331 * Gets the device path for a unix mount.
1333 * Returns: a string containing the device path.
1336 g_unix_mount_get_device_path (GUnixMountEntry *mount_entry)
1338 g_return_val_if_fail (mount_entry != NULL, NULL);
1340 return mount_entry->device_path;
1344 * g_unix_mount_get_fs_type:
1345 * @mount_entry: a #GUnixMount.
1347 * Gets the filesystem type for the unix mount.
1349 * Returns: a string containing the file system type.
1352 g_unix_mount_get_fs_type (GUnixMountEntry *mount_entry)
1354 g_return_val_if_fail (mount_entry != NULL, NULL);
1356 return mount_entry->filesystem_type;
1360 * g_unix_mount_is_readonly:
1361 * @mount_entry: a #GUnixMount.
1363 * Checks if a unix mount is mounted read only.
1365 * Returns: %TRUE if @mount_entry is read only.
1368 g_unix_mount_is_readonly (GUnixMountEntry *mount_entry)
1370 g_return_val_if_fail (mount_entry != NULL, FALSE);
1372 return mount_entry->is_read_only;
1376 * g_unix_mount_is_system_internal:
1377 * @mount_entry: a #GUnixMount.
1379 * Checks if a unix mount is a system path.
1381 * Returns: %TRUE if the unix mount is for a system path.
1384 g_unix_mount_is_system_internal (GUnixMountEntry *mount_entry)
1386 g_return_val_if_fail (mount_entry != NULL, FALSE);
1388 return mount_entry->is_system_internal;
1392 * g_unix_mount_point_compare:
1393 * @mount1: a #GUnixMount.
1394 * @mount2: a #GUnixMount.
1396 * Compares two unix mount points.
1398 * Returns: 1, 0 or -1 if @mount1 is greater than, equal to,
1399 * or less than @mount2, respectively.
1402 g_unix_mount_point_compare (GUnixMountPoint *mount1,
1403 GUnixMountPoint *mount2)
1407 g_return_val_if_fail (mount1 != NULL && mount2 != NULL, 0);
1409 res = strcmp_null (mount1->mount_path, mount2->mount_path);
1413 res = strcmp_null (mount1->device_path, mount2->device_path);
1417 res = strcmp_null (mount1->filesystem_type, mount2->filesystem_type);
1421 res = mount1->is_read_only - mount2->is_read_only;
1425 res = mount1->is_user_mountable - mount2->is_user_mountable;
1429 res = mount1->is_loopback - mount2->is_loopback;
1437 * g_unix_mount_point_get_mount_path:
1438 * @mount_point: a #GUnixMountPoint.
1440 * Gets the mount path for a unix mount point.
1442 * Returns: a string containing the mount path.
1445 g_unix_mount_point_get_mount_path (GUnixMountPoint *mount_point)
1447 g_return_val_if_fail (mount_point != NULL, NULL);
1449 return mount_point->mount_path;
1453 * g_unix_mount_point_get_device_path:
1454 * @mount_point: a #GUnixMountPoint.
1456 * Gets the device path for a unix mount point.
1458 * Returns: a string containing the device path.
1461 g_unix_mount_point_get_device_path (GUnixMountPoint *mount_point)
1463 g_return_val_if_fail (mount_point != NULL, NULL);
1465 return mount_point->device_path;
1469 * g_unix_mount_point_get_fs_type:
1470 * @mount_point: a #GUnixMountPoint.
1472 * Gets the file system type for the mount point.
1474 * Returns: a string containing the file system type.
1477 g_unix_mount_point_get_fs_type (GUnixMountPoint *mount_point)
1479 g_return_val_if_fail (mount_point != NULL, NULL);
1481 return mount_point->filesystem_type;
1485 * g_unix_mount_point_is_readonly:
1486 * @mount_point: a #GUnixMountPoint.
1488 * Checks if a unix mount point is read only.
1490 * Returns: %TRUE if a mount point is read only.
1493 g_unix_mount_point_is_readonly (GUnixMountPoint *mount_point)
1495 g_return_val_if_fail (mount_point != NULL, FALSE);
1497 return mount_point->is_read_only;
1501 * g_unix_mount_point_is_user_mountable:
1502 * @mount_point: a #GUnixMountPoint.
1504 * Checks if a unix mount point is mountable by the user.
1506 * Returns: %TRUE if the mount point is user mountable.
1509 g_unix_mount_point_is_user_mountable (GUnixMountPoint *mount_point)
1511 g_return_val_if_fail (mount_point != NULL, FALSE);
1513 return mount_point->is_user_mountable;
1517 * g_unix_mount_point_is_loopback:
1518 * @mount_point: a #GUnixMountPoint.
1520 * Checks if a unix mount point is a loopback device.
1522 * Returns: %TRUE if the mount point is a loopback. %FALSE otherwise.
1525 g_unix_mount_point_is_loopback (GUnixMountPoint *mount_point)
1527 g_return_val_if_fail (mount_point != NULL, FALSE);
1529 return mount_point->is_loopback;
1532 static GUnixMountType
1533 guess_mount_type (const char *mount_path,
1534 const char *device_path,
1535 const char *filesystem_type)
1537 GUnixMountType type;
1540 type = G_UNIX_MOUNT_TYPE_UNKNOWN;
1542 if ((strcmp (filesystem_type, "udf") == 0) ||
1543 (strcmp (filesystem_type, "iso9660") == 0) ||
1544 (strcmp (filesystem_type, "cd9660") == 0))
1545 type = G_UNIX_MOUNT_TYPE_CDROM;
1546 else if (strcmp (filesystem_type, "nfs") == 0)
1547 type = G_UNIX_MOUNT_TYPE_NFS;
1548 else if (g_str_has_prefix (device_path, "/vol/dev/diskette/") ||
1549 g_str_has_prefix (device_path, "/dev/fd") ||
1550 g_str_has_prefix (device_path, "/dev/floppy"))
1551 type = G_UNIX_MOUNT_TYPE_FLOPPY;
1552 else if (g_str_has_prefix (device_path, "/dev/cdrom") ||
1553 g_str_has_prefix (device_path, "/dev/acd") ||
1554 g_str_has_prefix (device_path, "/dev/cd"))
1555 type = G_UNIX_MOUNT_TYPE_CDROM;
1556 else if (g_str_has_prefix (device_path, "/vol/"))
1558 const char *name = mount_path + strlen ("/");
1560 if (g_str_has_prefix (name, "cdrom"))
1561 type = G_UNIX_MOUNT_TYPE_CDROM;
1562 else if (g_str_has_prefix (name, "floppy") ||
1563 g_str_has_prefix (device_path, "/vol/dev/diskette/"))
1564 type = G_UNIX_MOUNT_TYPE_FLOPPY;
1565 else if (g_str_has_prefix (name, "rmdisk"))
1566 type = G_UNIX_MOUNT_TYPE_ZIP;
1567 else if (g_str_has_prefix (name, "jaz"))
1568 type = G_UNIX_MOUNT_TYPE_JAZ;
1569 else if (g_str_has_prefix (name, "memstick"))
1570 type = G_UNIX_MOUNT_TYPE_MEMSTICK;
1574 basename = g_path_get_basename (mount_path);
1576 if (g_str_has_prefix (basename, "cdrom") ||
1577 g_str_has_prefix (basename, "cdwriter") ||
1578 g_str_has_prefix (basename, "burn") ||
1579 g_str_has_prefix (basename, "cdr") ||
1580 g_str_has_prefix (basename, "cdrw") ||
1581 g_str_has_prefix (basename, "dvdrom") ||
1582 g_str_has_prefix (basename, "dvdram") ||
1583 g_str_has_prefix (basename, "dvdr") ||
1584 g_str_has_prefix (basename, "dvdrw") ||
1585 g_str_has_prefix (basename, "cdrom_dvdrom") ||
1586 g_str_has_prefix (basename, "cdrom_dvdram") ||
1587 g_str_has_prefix (basename, "cdrom_dvdr") ||
1588 g_str_has_prefix (basename, "cdrom_dvdrw") ||
1589 g_str_has_prefix (basename, "cdr_dvdrom") ||
1590 g_str_has_prefix (basename, "cdr_dvdram") ||
1591 g_str_has_prefix (basename, "cdr_dvdr") ||
1592 g_str_has_prefix (basename, "cdr_dvdrw") ||
1593 g_str_has_prefix (basename, "cdrw_dvdrom") ||
1594 g_str_has_prefix (basename, "cdrw_dvdram") ||
1595 g_str_has_prefix (basename, "cdrw_dvdr") ||
1596 g_str_has_prefix (basename, "cdrw_dvdrw"))
1597 type = G_UNIX_MOUNT_TYPE_CDROM;
1598 else if (g_str_has_prefix (basename, "floppy"))
1599 type = G_UNIX_MOUNT_TYPE_FLOPPY;
1600 else if (g_str_has_prefix (basename, "zip"))
1601 type = G_UNIX_MOUNT_TYPE_ZIP;
1602 else if (g_str_has_prefix (basename, "jaz"))
1603 type = G_UNIX_MOUNT_TYPE_JAZ;
1604 else if (g_str_has_prefix (basename, "camera"))
1605 type = G_UNIX_MOUNT_TYPE_CAMERA;
1606 else if (g_str_has_prefix (basename, "memstick") ||
1607 g_str_has_prefix (basename, "memory_stick") ||
1608 g_str_has_prefix (basename, "ram"))
1609 type = G_UNIX_MOUNT_TYPE_MEMSTICK;
1610 else if (g_str_has_prefix (basename, "compact_flash"))
1611 type = G_UNIX_MOUNT_TYPE_CF;
1612 else if (g_str_has_prefix (basename, "smart_media"))
1613 type = G_UNIX_MOUNT_TYPE_SM;
1614 else if (g_str_has_prefix (basename, "sd_mmc"))
1615 type = G_UNIX_MOUNT_TYPE_SDMMC;
1616 else if (g_str_has_prefix (basename, "ipod"))
1617 type = G_UNIX_MOUNT_TYPE_IPOD;
1622 if (type == G_UNIX_MOUNT_TYPE_UNKNOWN)
1623 type = G_UNIX_MOUNT_TYPE_HD;
1629 * g_unix_mount_guess_type:
1630 * @mount_entry: a #GUnixMount.
1632 * Guesses the type of a unix mount. If the mount type cannot be
1633 * determined, returns %G_UNIX_MOUNT_TYPE_UNKNOWN.
1635 * Returns: a #GUnixMountType.
1637 static GUnixMountType
1638 g_unix_mount_guess_type (GUnixMountEntry *mount_entry)
1640 g_return_val_if_fail (mount_entry != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1641 g_return_val_if_fail (mount_entry->mount_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1642 g_return_val_if_fail (mount_entry->device_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1643 g_return_val_if_fail (mount_entry->filesystem_type != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1645 return guess_mount_type (mount_entry->mount_path,
1646 mount_entry->device_path,
1647 mount_entry->filesystem_type);
1651 * g_unix_mount_point_guess_type:
1652 * @mount_point: a #GUnixMountPoint.
1654 * Guesses the type of a unix mount point.
1655 * If the mount type cannot be determined,
1656 * returns %G_UNIX_MOUNT_TYPE_UNKNOWN.
1658 * Returns: a #GUnixMountType.
1660 static GUnixMountType
1661 g_unix_mount_point_guess_type (GUnixMountPoint *mount_point)
1663 g_return_val_if_fail (mount_point != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1664 g_return_val_if_fail (mount_point->mount_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1665 g_return_val_if_fail (mount_point->device_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1666 g_return_val_if_fail (mount_point->filesystem_type != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1668 return guess_mount_type (mount_point->mount_path,
1669 mount_point->device_path,
1670 mount_point->filesystem_type);
1674 type_to_icon (GUnixMountType type, gboolean is_mount_point)
1676 const char *icon_name;
1680 case G_UNIX_MOUNT_TYPE_HD:
1682 icon_name = "drive-removable-media";
1684 icon_name = "drive-harddisk";
1686 case G_UNIX_MOUNT_TYPE_FLOPPY:
1687 case G_UNIX_MOUNT_TYPE_ZIP:
1688 case G_UNIX_MOUNT_TYPE_JAZ:
1690 icon_name = "drive-removable-media";
1692 icon_name = "media-floppy";
1694 case G_UNIX_MOUNT_TYPE_CDROM:
1696 icon_name = "drive-optical";
1698 icon_name = "media-optical";
1700 case G_UNIX_MOUNT_TYPE_NFS:
1701 /* TODO: Would like a better icon here... */
1703 icon_name = "drive-removable-media";
1705 icon_name = "drive-harddisk";
1707 case G_UNIX_MOUNT_TYPE_MEMSTICK:
1709 icon_name = "drive-removable-media";
1711 icon_name = "media-flash";
1713 case G_UNIX_MOUNT_TYPE_CAMERA:
1715 icon_name = "drive-removable-media";
1717 icon_name = "camera-photo";
1719 case G_UNIX_MOUNT_TYPE_IPOD:
1721 icon_name = "drive-removable-media";
1723 icon_name = "multimedia-player";
1725 case G_UNIX_MOUNT_TYPE_UNKNOWN:
1728 icon_name = "drive-removable-media";
1730 icon_name = "drive-harddisk";
1738 * g_unix_mount_guess_name:
1739 * @mount_entry: a #GUnixMountEntry
1741 * Guesses the name of a Unix mount.
1742 * The result is a translated string.
1744 * Returns: A newly allocated string that must
1745 * be freed with g_free()
1748 g_unix_mount_guess_name (GUnixMountEntry *mount_entry)
1752 if (strcmp (mount_entry->mount_path, "/") == 0)
1753 name = g_strdup (_("Filesystem root"));
1755 name = g_filename_display_basename (mount_entry->mount_path);
1761 * g_unix_mount_guess_icon:
1762 * @mount_entry: a #GUnixMountEntry
1764 * Guesses the icon of a Unix mount.
1769 g_unix_mount_guess_icon (GUnixMountEntry *mount_entry)
1771 return g_themed_icon_new (type_to_icon (g_unix_mount_guess_type (mount_entry), FALSE));
1775 * g_unix_mount_point_guess_name:
1776 * @mount_point: a #GUnixMountPoint
1778 * Guesses the name of a Unix mount point.
1779 * The result is a translated string.
1781 * Returns: A newly allocated string that must
1782 * be freed with g_free()
1785 g_unix_mount_point_guess_name (GUnixMountPoint *mount_point)
1789 if (strcmp (mount_point->mount_path, "/") == 0)
1790 name = g_strdup (_("Filesystem root"));
1792 name = g_filename_display_basename (mount_point->mount_path);
1798 * g_unix_mount_point_guess_icon:
1799 * @mount_point: a #GUnixMountPoint
1801 * Guesses the icon of a Unix mount point.
1806 g_unix_mount_point_guess_icon (GUnixMountPoint *mount_point)
1808 return g_themed_icon_new (type_to_icon (g_unix_mount_point_guess_type (mount_point), TRUE));
1812 * g_unix_mount_guess_can_eject:
1813 * @mount_entry: a #GUnixMountEntry
1815 * Guesses whether a Unix mount can be ejected.
1817 * Returns: %TRUE if @mount_entry is deemed to be ejectable.
1820 g_unix_mount_guess_can_eject (GUnixMountEntry *mount_entry)
1822 GUnixMountType guessed_type;
1824 guessed_type = g_unix_mount_guess_type (mount_entry);
1825 if (guessed_type == G_UNIX_MOUNT_TYPE_IPOD ||
1826 guessed_type == G_UNIX_MOUNT_TYPE_CDROM)
1833 * g_unix_mount_point_guess_can_eject:
1834 * @mount_point: a #GUnixMountPoint
1836 * Guesses whether a Unix mount point can be ejected.
1838 * Returns: %TRUE if @mount_point is deemed to be ejectable.
1841 g_unix_mount_point_guess_can_eject (GUnixMountPoint *mount_point)
1843 GUnixMountType guessed_type;
1845 guessed_type = g_unix_mount_point_guess_type (mount_point);
1846 if (guessed_type == G_UNIX_MOUNT_TYPE_IPOD ||
1847 guessed_type == G_UNIX_MOUNT_TYPE_CDROM)
1854 /* borrowed from gtk/gtkfilesystemunix.c in GTK+ on 02/23/2006 */
1856 _canonicalize_filename (gchar *filename)
1859 gboolean last_was_slash = FALSE;
1866 if (*p == G_DIR_SEPARATOR)
1868 if (!last_was_slash)
1869 *q++ = G_DIR_SEPARATOR;
1871 last_was_slash = TRUE;
1875 if (last_was_slash && *p == '.')
1877 if (*(p + 1) == G_DIR_SEPARATOR ||
1880 if (*(p + 1) == '\0')
1885 else if (*(p + 1) == '.' &&
1886 (*(p + 2) == G_DIR_SEPARATOR ||
1889 if (q > filename + 1)
1892 while (q > filename + 1 &&
1893 *(q - 1) != G_DIR_SEPARATOR)
1897 if (*(p + 2) == '\0')
1905 last_was_slash = FALSE;
1911 last_was_slash = FALSE;
1918 if (q > filename + 1 && *(q - 1) == G_DIR_SEPARATOR)
1925 _resolve_symlink (const char *file)
1933 f = g_strdup (file);
1935 while (g_file_test (f, G_FILE_TEST_IS_SYMLINK)) {
1936 link = g_file_read_link (f, &error);
1938 g_error_free (error);
1944 dir = g_path_get_dirname (f);
1945 f1 = g_strdup_printf ("%s/%s", dir, link);
1954 _canonicalize_filename (f);
1958 #ifdef HAVE_MNTENT_H
1960 _resolve_dev_root (void)
1962 static gboolean have_real_dev_root = FALSE;
1963 static char real_dev_root[256];
1964 struct stat statbuf;
1966 /* see if it's cached already */
1967 if (have_real_dev_root)
1970 /* otherwise we're going to find it right away.. */
1971 have_real_dev_root = TRUE;
1973 if (stat ("/dev/root", &statbuf) == 0) {
1974 if (! S_ISLNK (statbuf.st_mode)) {
1975 dev_t root_dev = statbuf.st_dev;
1979 /* see if device with similar major:minor as /dev/root is mention
1980 * in /etc/mtab (it usually is)
1982 f = fopen ("/etc/mtab", "r");
1986 while (getmntent_r (f, &ent, buf, sizeof (buf)) != NULL) {
1988 if (stat (ent.mnt_fsname, &statbuf) == 0 &&
1989 statbuf.st_dev == root_dev) {
1990 strncpy (real_dev_root, ent.mnt_fsname, sizeof (real_dev_root) - 1);
1991 real_dev_root[sizeof (real_dev_root) - 1] = '\0';
1999 /* no, that didn't work.. next we could scan /dev ... but I digress.. */
2003 resolved = _resolve_symlink ("/dev/root");
2004 if (resolved != NULL) {
2005 strncpy (real_dev_root, resolved, sizeof (real_dev_root) - 1);
2006 real_dev_root[sizeof (real_dev_root) - 1] = '\0';
2014 strcpy (real_dev_root, "/dev/root");
2017 return real_dev_root;
2021 #define __G_UNIX_MOUNTS_C__
2022 #include "gioaliasdef.c"