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 */
233 "/var/log/audit", /* https://bugzilla.redhat.com/show_bug.cgi?id=333041 */
234 "/var/tmp", /* https://bugzilla.redhat.com/show_bug.cgi?id=335241 */
241 if (is_in (mount_path, ignore_mountpoints))
244 if (g_str_has_prefix (mount_path, "/dev") ||
245 g_str_has_prefix (mount_path, "/proc") ||
246 g_str_has_prefix (mount_path, "/sys"))
249 if (strstr (mount_path, "/.gvfs") != NULL)
256 guess_system_internal (const char *mountpoint,
260 const char *ignore_fs[] = {
278 const char *ignore_devices[] = {
288 if (is_in (fs, ignore_fs))
291 if (is_in (device, ignore_devices))
294 if (g_unix_is_mount_path_system_internal (mountpoint))
303 get_mtab_read_file (void)
307 return "/proc/mounts";
309 return _PATH_MOUNTED;
317 get_mtab_monitor_file (void)
320 return _PATH_MOUNTED;
326 G_LOCK_DEFINE_STATIC(getmntent);
329 _g_get_unix_mounts ()
331 struct mntent *mntent;
334 GUnixMountEntry *mount_entry;
335 GHashTable *mounts_hash;
338 read_file = get_mtab_read_file ();
340 file = setmntent (read_file, "r");
346 mounts_hash = g_hash_table_new (g_str_hash, g_str_equal);
349 while ((mntent = getmntent (file)) != NULL)
351 /* ignore any mnt_fsname that is repeated and begins with a '/'
353 * We do this to avoid being fooled by --bind mounts, since
354 * these have the same device as the location they bind to.
355 * Its not an ideal solution to the problem, but its likely that
356 * the most important mountpoint is first and the --bind ones after
357 * that aren't as important. So it should work.
359 * The '/' is to handle procfs, tmpfs and other no device mounts.
361 if (mntent->mnt_fsname != NULL &&
362 mntent->mnt_fsname[0] == '/' &&
363 g_hash_table_lookup (mounts_hash, mntent->mnt_fsname))
366 mount_entry = g_new0 (GUnixMountEntry, 1);
367 mount_entry->mount_path = g_strdup (mntent->mnt_dir);
368 if (strcmp (mntent->mnt_fsname, "/dev/root") == 0)
369 mount_entry->device_path = g_strdup (_resolve_dev_root ());
371 mount_entry->device_path = g_strdup (mntent->mnt_fsname);
372 mount_entry->filesystem_type = g_strdup (mntent->mnt_type);
374 #if defined (HAVE_HASMNTOPT)
375 if (hasmntopt (mntent, MNTOPT_RO) != NULL)
376 mount_entry->is_read_only = TRUE;
379 mount_entry->is_system_internal =
380 guess_system_internal (mount_entry->mount_path,
381 mount_entry->filesystem_type,
382 mount_entry->device_path);
384 g_hash_table_insert (mounts_hash,
385 mount_entry->device_path,
386 mount_entry->device_path);
388 return_list = g_list_prepend (return_list, mount_entry);
390 g_hash_table_destroy (mounts_hash);
394 G_UNLOCK (getmntent);
396 return g_list_reverse (return_list);
399 #elif defined (HAVE_SYS_MNTTAB_H)
401 G_LOCK_DEFINE_STATIC(getmntent);
404 get_mtab_read_file (void)
407 return _PATH_MOUNTED;
409 return "/etc/mnttab";
414 get_mtab_monitor_file (void)
416 return get_mtab_read_file ();
420 _g_get_unix_mounts (void)
422 struct mnttab mntent;
425 GUnixMountEntry *mount_entry;
428 read_file = get_mtab_read_file ();
430 file = setmntent (read_file, "r");
437 while (! getmntent (file, &mntent))
439 mount_entry = g_new0 (GUnixMountEntry, 1);
441 mount_entry->mount_path = g_strdup (mntent.mnt_mountp);
442 mount_entry->device_path = g_strdup (mntent.mnt_special);
443 mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype);
445 #if defined (HAVE_HASMNTOPT)
446 if (hasmntopt (&mntent, MNTOPT_RO) != NULL)
447 mount_entry->is_read_only = TRUE;
450 mount_entry->is_system_internal =
451 guess_system_internal (mount_entry->mount_path,
452 mount_entry->filesystem_type,
453 mount_entry->device_path);
455 return_list = g_list_prepend (return_list, mount_entry);
460 G_UNLOCK (getmntent);
462 return g_list_reverse (return_list);
465 #elif defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
468 get_mtab_monitor_file (void)
474 _g_get_unix_mounts (void)
476 struct vfs_ent *fs_info;
477 struct vmount *vmount_info;
479 unsigned int vmount_size;
483 if (mntctl (MCTL_QUERY, sizeof (vmount_size), &vmount_size) != 0)
485 g_warning ("Unable to know the number of mounted volumes\n");
490 vmount_info = (struct vmount*)g_malloc (vmount_size);
492 vmount_number = mntctl (MCTL_QUERY, vmount_size, vmount_info);
494 if (vmount_info->vmt_revision != VMT_REVISION)
495 g_warning ("Bad vmount structure revision number, want %d, got %d\n", VMT_REVISION, vmount_info->vmt_revision);
497 if (vmount_number < 0)
499 g_warning ("Unable to recover mounted volumes information\n");
501 g_free (vmount_info);
506 while (vmount_number > 0)
508 mount_entry = g_new0 (GUnixMountEntry, 1);
510 mount_entry->device_path = g_strdup (vmt2dataptr (vmount_info, VMT_OBJECT));
511 mount_entry->mount_path = g_strdup (vmt2dataptr (vmount_info, VMT_STUB));
512 /* is_removable = (vmount_info->vmt_flags & MNT_REMOVABLE) ? 1 : 0; */
513 mount_entry->is_read_only = (vmount_info->vmt_flags & MNT_READONLY) ? 1 : 0;
515 fs_info = getvfsbytype (vmount_info->vmt_gfstype);
518 mount_entry->filesystem_type = g_strdup ("unknown");
520 mount_entry->filesystem_type = g_strdup (fs_info->vfsent_name);
522 mount_entry->is_system_internal =
523 guess_system_internal (mount_entry->mount_path,
524 mount_entry->filesystem_type,
525 mount_entry->device_path);
527 return_list = g_list_prepend (return_list, mount_entry);
529 vmount_info = (struct vmount *)( (char*)vmount_info
530 + vmount_info->vmt_length);
535 g_free (vmount_info);
537 return g_list_reverse (return_list);
540 #elif defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
543 get_mtab_monitor_file (void)
549 _g_get_unix_mounts (void)
551 struct statfs *mntent = NULL;
553 GUnixMountEntry *mount_entry;
556 /* Pass MNT_NOWAIT to avoid blocking trying to update NFS mounts. */
557 if ((num_mounts = getmntinfo (&mntent, MNT_NOWAIT)) == 0)
562 for (i = 0; i < num_mounts; i++)
564 mount_entry = g_new0 (GUnixMountEntry, 1);
566 mount_entry->mount_path = g_strdup (mntent[i].f_mntonname);
567 mount_entry->device_path = g_strdup (mntent[i].f_mntfromname);
568 mount_entry->filesystem_type = g_strdup (mntent[i].f_fstypename);
569 if (mntent[i].f_flags & MNT_RDONLY)
570 mount_entry->is_read_only = TRUE;
572 mount_entry->is_system_internal =
573 guess_system_internal (mount_entry->mount_path,
574 mount_entry->filesystem_type,
575 mount_entry->device_path);
577 return_list = g_list_prepend (return_list, mount_entry);
580 return g_list_reverse (return_list);
583 #error No _g_get_unix_mounts() implementation for system
586 /* _g_get_unix_mount_points():
588 * don't return swap and ignore mounts.
592 get_fstab_file (void)
594 #if defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
596 return "/etc/filesystems";
597 #elif defined(_PATH_MNTTAB)
599 #elif defined(VFSTAB)
608 _g_get_unix_mount_points (void)
610 struct mntent *mntent;
613 GUnixMountPoint *mount_entry;
616 read_file = get_fstab_file ();
618 file = setmntent (read_file, "r");
625 while ((mntent = getmntent (file)) != NULL)
627 if ((strcmp (mntent->mnt_dir, "ignore") == 0) ||
628 (strcmp (mntent->mnt_dir, "swap") == 0))
631 mount_entry = g_new0 (GUnixMountPoint, 1);
632 mount_entry->mount_path = g_strdup (mntent->mnt_dir);
633 if (strcmp (mntent->mnt_fsname, "/dev/root") == 0)
634 mount_entry->device_path = g_strdup (_resolve_dev_root ());
636 mount_entry->device_path = g_strdup (mntent->mnt_fsname);
637 mount_entry->filesystem_type = g_strdup (mntent->mnt_type);
639 #ifdef HAVE_HASMNTOPT
640 if (hasmntopt (mntent, MNTOPT_RO) != NULL)
641 mount_entry->is_read_only = TRUE;
643 if (hasmntopt (mntent, "loop") != NULL)
644 mount_entry->is_loopback = TRUE;
648 if ((mntent->mnt_type != NULL && strcmp ("supermount", mntent->mnt_type) == 0)
649 #ifdef HAVE_HASMNTOPT
650 || (hasmntopt (mntent, "user") != NULL
651 && hasmntopt (mntent, "user") != hasmntopt (mntent, "user_xattr"))
652 || hasmntopt (mntent, "pamconsole") != NULL
653 || hasmntopt (mntent, "users") != NULL
654 || hasmntopt (mntent, "owner") != NULL
657 mount_entry->is_user_mountable = TRUE;
659 return_list = g_list_prepend (return_list, mount_entry);
663 G_UNLOCK (getmntent);
665 return g_list_reverse (return_list);
668 #elif defined (HAVE_SYS_MNTTAB_H)
671 _g_get_unix_mount_points (void)
673 struct mnttab mntent;
676 GUnixMountPoint *mount_entry;
679 read_file = get_fstab_file ();
681 file = setmntent (read_file, "r");
688 while (! getmntent (file, &mntent))
690 if ((strcmp (mntent.mnt_mountp, "ignore") == 0) ||
691 (strcmp (mntent.mnt_mountp, "swap") == 0))
694 mount_entry = g_new0 (GUnixMountPoint, 1);
696 mount_entry->mount_path = g_strdup (mntent.mnt_mountp);
697 mount_entry->device_path = g_strdup (mntent.mnt_special);
698 mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype);
700 #ifdef HAVE_HASMNTOPT
701 if (hasmntopt (&mntent, MNTOPT_RO) != NULL)
702 mount_entry->is_read_only = TRUE;
704 if (hasmntopt (&mntent, "lofs") != NULL)
705 mount_entry->is_loopback = TRUE;
708 if ((mntent.mnt_fstype != NULL)
709 #ifdef HAVE_HASMNTOPT
710 || (hasmntopt (&mntent, "user") != NULL
711 && hasmntopt (&mntent, "user") != hasmntopt (&mntent, "user_xattr"))
712 || hasmntopt (&mntent, "pamconsole") != NULL
713 || hasmntopt (&mntent, "users") != NULL
714 || hasmntopt (&mntent, "owner") != NULL
717 mount_entry->is_user_mountable = TRUE;
720 return_list = g_list_prepend (return_list, mount_entry);
724 G_UNLOCK (getmntent);
726 return g_list_reverse (return_list);
728 #elif defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
730 /* functions to parse /etc/filesystems on aix */
732 /* read character, ignoring comments (begin with '*', end with '\n' */
734 aix_fs_getc (FILE *fd)
738 while ((c = getc (fd)) == '*')
740 while (((c = getc (fd)) != '\n') && (c != EOF))
745 /* eat all continuous spaces in a file */
747 aix_fs_ignorespace (FILE *fd)
751 while ((c = aix_fs_getc (fd)) != EOF)
753 if (!g_ascii_isspace (c))
763 /* read one word from file */
765 aix_fs_getword (FILE *fd,
770 aix_fs_ignorespace (fd);
772 while (((c = aix_fs_getc (fd)) != EOF) && !g_ascii_isspace (c))
776 while (((c = aix_fs_getc (fd)) != EOF) && (c != '"'))
788 char mnt_mount[PATH_MAX];
789 char mnt_special[PATH_MAX];
791 char mnt_options[128];
792 } AixMountTableEntry;
794 /* read mount points properties */
796 aix_fs_get (FILE *fd,
797 AixMountTableEntry *prop)
799 static char word[PATH_MAX] = { 0 };
800 char value[PATH_MAX];
805 if (aix_fs_getword (fd, word) == EOF)
809 word[strlen(word) - 1] = 0;
810 strcpy (prop->mnt_mount, word);
812 /* read attributes and value */
814 while (aix_fs_getword (fd, word) != EOF)
816 /* test if is attribute or new stanza */
817 if (word[strlen(word) - 1] == ':')
821 aix_fs_getword (fd, value);
824 aix_fs_getword (fd, value);
826 if (strcmp (word, "dev") == 0)
827 strcpy (prop->mnt_special, value);
828 else if (strcmp (word, "vfs") == 0)
829 strcpy (prop->mnt_fstype, value);
830 else if (strcmp (word, "options") == 0)
831 strcpy(prop->mnt_options, value);
838 _g_get_unix_mount_points (void)
840 struct mntent *mntent;
843 GUnixMountPoint *mount_entry;
844 AixMountTableEntry mntent;
847 read_file = get_fstab_file ();
849 file = setmntent (read_file, "r");
855 while (!aix_fs_get (file, &mntent))
857 if (strcmp ("cdrfs", mntent.mnt_fstype) == 0)
859 mount_entry = g_new0 (GUnixMountPoint, 1);
862 mount_entry->mount_path = g_strdup (mntent.mnt_mount);
863 mount_entry->device_path = g_strdup (mntent.mnt_special);
864 mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype);
865 mount_entry->is_read_only = TRUE;
866 mount_entry->is_user_mountable = TRUE;
868 return_list = g_list_prepend (return_list, mount_entry);
874 return g_list_reverse (return_list);
877 #elif defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
880 _g_get_unix_mount_points (void)
882 struct fstab *fstab = NULL;
883 GUnixMountPoint *mount_entry;
885 #ifdef HAVE_SYS_SYSCTL_H
887 size_t len = sizeof(usermnt);
896 #ifdef HAVE_SYS_SYSCTL_H
897 #if defined(HAVE_SYSCTLBYNAME)
898 sysctlbyname ("vfs.usermount", &usermnt, &len, NULL, 0);
899 #elif defined(CTL_VFS) && defined(VFS_USERMOUNT)
904 mib[1] = VFS_USERMOUNT;
905 sysctl (mib, 2, &usermnt, &len, NULL, 0);
907 #elif defined(CTL_KERN) && defined(KERN_USERMOUNT)
912 mib[1] = KERN_USERMOUNT;
913 sysctl (mib, 2, &usermnt, &len, NULL, 0);
918 while ((fstab = getfsent ()) != NULL)
920 if (strcmp (fstab->fs_vfstype, "swap") == 0)
923 mount_entry = g_new0 (GUnixMountPoint, 1);
925 mount_entry->mount_path = g_strdup (fstab->fs_file);
926 mount_entry->device_path = g_strdup (fstab->fs_spec);
927 mount_entry->filesystem_type = g_strdup (fstab->fs_vfstype);
929 if (strcmp (fstab->fs_type, "ro") == 0)
930 mount_entry->is_read_only = TRUE;
932 #ifdef HAVE_SYS_SYSCTL_H
935 uid_t uid = getuid ();
936 if (stat (fstab->fs_file, &sb) == 0)
938 if (uid == 0 || sb.st_uid == uid)
939 mount_entry->is_user_mountable = TRUE;
944 return_list = g_list_prepend (return_list, mount_entry);
949 return g_list_reverse (return_list);
952 #error No g_get_mount_table() implementation for system
956 get_mounts_timestamp (void)
958 const char *monitor_file;
961 monitor_file = get_mtab_monitor_file ();
964 if (stat (monitor_file, &buf) == 0)
965 return (guint64)buf.st_mtime;
971 get_mount_points_timestamp (void)
973 const char *monitor_file;
976 monitor_file = get_fstab_file ();
979 if (stat (monitor_file, &buf) == 0)
980 return (guint64)buf.st_mtime;
987 * @time_read: guint64 to contain a timestamp.
989 * Gets a #GList of strings containing the unix mounts.
990 * If @time_read is set, it will be filled with the mount
991 * timestamp, allowing for checking if the mounts have changed
992 * with g_unix_mounts_changed_since().
994 * Returns: a #GList of the UNIX mounts.
997 g_unix_mounts_get (guint64 *time_read)
1000 *time_read = get_mounts_timestamp ();
1002 return _g_get_unix_mounts ();
1007 * @mount_path: path for a possible unix mount.
1008 * @time_read: guint64 to contain a timestamp.
1010 * Gets a #GUnixMountEntry for a given mount path. If @time_read
1011 * is set, it will be filled with a unix timestamp for checking
1012 * if the mounts have changed since with g_unix_mounts_changed_since().
1014 * Returns: a #GUnixMount.
1017 g_unix_mount_at (const char *mount_path,
1021 GUnixMountEntry *mount_entry, *found;
1023 mounts = g_unix_mounts_get (time_read);
1026 for (l = mounts; l != NULL; l = l->next)
1028 mount_entry = l->data;
1030 if (strcmp (mount_path, mount_entry->mount_path) == 0)
1031 found = mount_entry;
1033 g_unix_mount_free (mount_entry);
1036 g_list_free (mounts);
1042 * g_unix_mount_points_get:
1043 * @time_read: guint64 to contain a timestamp.
1045 * Gets a #GList of strings containing the unix mount points.
1046 * If @time_read is set, it will be filled with the mount timestamp,
1047 * allowing for checking if the mounts have changed with
1048 * g_unix_mounts_points_changed_since().
1050 * Returns: a #GList of the UNIX mountpoints.
1053 g_unix_mount_points_get (guint64 *time_read)
1056 *time_read = get_mount_points_timestamp ();
1058 return _g_get_unix_mount_points ();
1062 * g_unix_mounts_changed_since:
1063 * @time: guint64 to contain a timestamp.
1065 * Checks if the unix mounts have changed since a given unix time.
1067 * Returns: %TRUE if the mounts have changed since @time.
1070 g_unix_mounts_changed_since (guint64 time)
1072 return get_mounts_timestamp () != time;
1076 * g_unix_mount_points_changed_since:
1077 * @time: guint64 to contain a timestamp.
1079 * Checks if the unix mount points have changed since a given unix time.
1081 * Returns: %TRUE if the mount points have changed since @time.
1084 g_unix_mount_points_changed_since (guint64 time)
1086 return get_mount_points_timestamp () != time;
1090 g_unix_mount_monitor_finalize (GObject *object)
1092 GUnixMountMonitor *monitor;
1094 monitor = G_UNIX_MOUNT_MONITOR (object);
1096 if (monitor->fstab_monitor)
1098 g_file_monitor_cancel (monitor->fstab_monitor);
1099 g_object_unref (monitor->fstab_monitor);
1102 if (monitor->mtab_monitor)
1104 g_file_monitor_cancel (monitor->mtab_monitor);
1105 g_object_unref (monitor->mtab_monitor);
1108 the_mount_monitor = NULL;
1110 if (G_OBJECT_CLASS (g_unix_mount_monitor_parent_class)->finalize)
1111 (*G_OBJECT_CLASS (g_unix_mount_monitor_parent_class)->finalize) (object);
1116 g_unix_mount_monitor_class_init (GUnixMountMonitorClass *klass)
1118 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1120 gobject_class->finalize = g_unix_mount_monitor_finalize;
1122 * GUnixMountMonitor::mounts-changed:
1124 * Emitted when the unix mounts have changed.
1126 signals[MOUNTS_CHANGED] =
1127 g_signal_new ("mounts_changed",
1128 G_TYPE_FROM_CLASS (klass),
1132 g_cclosure_marshal_VOID__VOID,
1135 * GUnixMountMonitor::mountpoints-changed:
1137 * Emitted when the unix mount points have changed.
1139 signals[MOUNTPOINTS_CHANGED] =
1140 g_signal_new ("mountpoints_changed",
1141 G_TYPE_FROM_CLASS (klass),
1145 g_cclosure_marshal_VOID__VOID,
1150 fstab_file_changed (GFileMonitor *monitor,
1153 GFileMonitorEvent event_type,
1156 GUnixMountMonitor *mount_monitor;
1158 if (event_type != G_FILE_MONITOR_EVENT_CHANGED &&
1159 event_type != G_FILE_MONITOR_EVENT_CREATED &&
1160 event_type != G_FILE_MONITOR_EVENT_DELETED)
1163 mount_monitor = user_data;
1164 g_signal_emit (mount_monitor, signals[MOUNTPOINTS_CHANGED], 0);
1168 mtab_file_changed (GFileMonitor *monitor,
1171 GFileMonitorEvent event_type,
1174 GUnixMountMonitor *mount_monitor;
1176 if (event_type != G_FILE_MONITOR_EVENT_CHANGED &&
1177 event_type != G_FILE_MONITOR_EVENT_CREATED &&
1178 event_type != G_FILE_MONITOR_EVENT_DELETED)
1181 mount_monitor = user_data;
1182 g_signal_emit (mount_monitor, signals[MOUNTS_CHANGED], 0);
1186 g_unix_mount_monitor_init (GUnixMountMonitor *monitor)
1190 if (get_fstab_file () != NULL)
1192 file = g_file_new_for_path (get_fstab_file ());
1193 monitor->fstab_monitor = g_file_monitor_file (file, 0, NULL);
1194 g_object_unref (file);
1196 g_signal_connect (monitor->fstab_monitor, "changed", (GCallback)fstab_file_changed, monitor);
1199 if (get_mtab_monitor_file () != NULL)
1201 file = g_file_new_for_path (get_mtab_monitor_file ());
1202 monitor->mtab_monitor = g_file_monitor_file (file, 0, NULL);
1203 g_object_unref (file);
1205 g_signal_connect (monitor->mtab_monitor, "changed", (GCallback)mtab_file_changed, monitor);
1210 * g_unix_mount_monitor_new:
1212 * Gets a new #GUnixMountMonitor.
1214 * Returns: a #GUnixMountMonitor.
1217 g_unix_mount_monitor_new (void)
1219 if (the_mount_monitor == NULL)
1221 the_mount_monitor = g_object_new (G_TYPE_UNIX_MOUNT_MONITOR, NULL);
1222 return the_mount_monitor;
1225 return g_object_ref (the_mount_monitor);
1229 * g_unix_mount_free:
1230 * @mount_entry: a #GUnixMount.
1232 * Frees a unix mount.
1235 g_unix_mount_free (GUnixMountEntry *mount_entry)
1237 g_return_if_fail (mount_entry != NULL);
1239 g_free (mount_entry->mount_path);
1240 g_free (mount_entry->device_path);
1241 g_free (mount_entry->filesystem_type);
1242 g_free (mount_entry);
1246 * g_unix_mount_point_free:
1247 * @mount_point: unix mount point to free.
1249 * Frees a unix mount point.
1252 g_unix_mount_point_free (GUnixMountPoint *mount_point)
1254 g_return_if_fail (mount_point != NULL);
1256 g_free (mount_point->mount_path);
1257 g_free (mount_point->device_path);
1258 g_free (mount_point->filesystem_type);
1259 g_free (mount_point);
1263 strcmp_null (const char *str1,
1268 if (str1 == NULL && str2 != NULL)
1270 if (str1 != NULL && str2 == NULL)
1272 return strcmp (str1, str2);
1276 * g_unix_mount_compare:
1277 * @mount1: first #GUnixMountEntry to compare.
1278 * @mount2: second #GUnixMountEntry to compare.
1280 * Compares two unix mounts.
1282 * Returns: 1, 0 or -1 if @mount1 is greater than, equal to,
1283 * or less than @mount2, respectively.
1286 g_unix_mount_compare (GUnixMountEntry *mount1,
1287 GUnixMountEntry *mount2)
1291 g_return_val_if_fail (mount1 != NULL && mount2 != NULL, 0);
1293 res = strcmp_null (mount1->mount_path, mount2->mount_path);
1297 res = strcmp_null (mount1->device_path, mount2->device_path);
1301 res = strcmp_null (mount1->filesystem_type, mount2->filesystem_type);
1305 res = mount1->is_read_only - mount2->is_read_only;
1313 * g_unix_mount_get_mount_path:
1314 * @mount_entry: input #GUnixMountEntry to get the mount path for.
1316 * Gets the mount path for a unix mount.
1318 * Returns: the mount path for @mount_entry.
1321 g_unix_mount_get_mount_path (GUnixMountEntry *mount_entry)
1323 g_return_val_if_fail (mount_entry != NULL, NULL);
1325 return mount_entry->mount_path;
1329 * g_unix_mount_get_device_path:
1330 * @mount_entry: a #GUnixMount.
1332 * Gets the device path for a unix mount.
1334 * Returns: a string containing the device path.
1337 g_unix_mount_get_device_path (GUnixMountEntry *mount_entry)
1339 g_return_val_if_fail (mount_entry != NULL, NULL);
1341 return mount_entry->device_path;
1345 * g_unix_mount_get_fs_type:
1346 * @mount_entry: a #GUnixMount.
1348 * Gets the filesystem type for the unix mount.
1350 * Returns: a string containing the file system type.
1353 g_unix_mount_get_fs_type (GUnixMountEntry *mount_entry)
1355 g_return_val_if_fail (mount_entry != NULL, NULL);
1357 return mount_entry->filesystem_type;
1361 * g_unix_mount_is_readonly:
1362 * @mount_entry: a #GUnixMount.
1364 * Checks if a unix mount is mounted read only.
1366 * Returns: %TRUE if @mount_entry is read only.
1369 g_unix_mount_is_readonly (GUnixMountEntry *mount_entry)
1371 g_return_val_if_fail (mount_entry != NULL, FALSE);
1373 return mount_entry->is_read_only;
1377 * g_unix_mount_is_system_internal:
1378 * @mount_entry: a #GUnixMount.
1380 * Checks if a unix mount is a system path.
1382 * Returns: %TRUE if the unix mount is for a system path.
1385 g_unix_mount_is_system_internal (GUnixMountEntry *mount_entry)
1387 g_return_val_if_fail (mount_entry != NULL, FALSE);
1389 return mount_entry->is_system_internal;
1393 * g_unix_mount_point_compare:
1394 * @mount1: a #GUnixMount.
1395 * @mount2: a #GUnixMount.
1397 * Compares two unix mount points.
1399 * Returns: 1, 0 or -1 if @mount1 is greater than, equal to,
1400 * or less than @mount2, respectively.
1403 g_unix_mount_point_compare (GUnixMountPoint *mount1,
1404 GUnixMountPoint *mount2)
1408 g_return_val_if_fail (mount1 != NULL && mount2 != NULL, 0);
1410 res = strcmp_null (mount1->mount_path, mount2->mount_path);
1414 res = strcmp_null (mount1->device_path, mount2->device_path);
1418 res = strcmp_null (mount1->filesystem_type, mount2->filesystem_type);
1422 res = mount1->is_read_only - mount2->is_read_only;
1426 res = mount1->is_user_mountable - mount2->is_user_mountable;
1430 res = mount1->is_loopback - mount2->is_loopback;
1438 * g_unix_mount_point_get_mount_path:
1439 * @mount_point: a #GUnixMountPoint.
1441 * Gets the mount path for a unix mount point.
1443 * Returns: a string containing the mount path.
1446 g_unix_mount_point_get_mount_path (GUnixMountPoint *mount_point)
1448 g_return_val_if_fail (mount_point != NULL, NULL);
1450 return mount_point->mount_path;
1454 * g_unix_mount_point_get_device_path:
1455 * @mount_point: a #GUnixMountPoint.
1457 * Gets the device path for a unix mount point.
1459 * Returns: a string containing the device path.
1462 g_unix_mount_point_get_device_path (GUnixMountPoint *mount_point)
1464 g_return_val_if_fail (mount_point != NULL, NULL);
1466 return mount_point->device_path;
1470 * g_unix_mount_point_get_fs_type:
1471 * @mount_point: a #GUnixMountPoint.
1473 * Gets the file system type for the mount point.
1475 * Returns: a string containing the file system type.
1478 g_unix_mount_point_get_fs_type (GUnixMountPoint *mount_point)
1480 g_return_val_if_fail (mount_point != NULL, NULL);
1482 return mount_point->filesystem_type;
1486 * g_unix_mount_point_is_readonly:
1487 * @mount_point: a #GUnixMountPoint.
1489 * Checks if a unix mount point is read only.
1491 * Returns: %TRUE if a mount point is read only.
1494 g_unix_mount_point_is_readonly (GUnixMountPoint *mount_point)
1496 g_return_val_if_fail (mount_point != NULL, FALSE);
1498 return mount_point->is_read_only;
1502 * g_unix_mount_point_is_user_mountable:
1503 * @mount_point: a #GUnixMountPoint.
1505 * Checks if a unix mount point is mountable by the user.
1507 * Returns: %TRUE if the mount point is user mountable.
1510 g_unix_mount_point_is_user_mountable (GUnixMountPoint *mount_point)
1512 g_return_val_if_fail (mount_point != NULL, FALSE);
1514 return mount_point->is_user_mountable;
1518 * g_unix_mount_point_is_loopback:
1519 * @mount_point: a #GUnixMountPoint.
1521 * Checks if a unix mount point is a loopback device.
1523 * Returns: %TRUE if the mount point is a loopback. %FALSE otherwise.
1526 g_unix_mount_point_is_loopback (GUnixMountPoint *mount_point)
1528 g_return_val_if_fail (mount_point != NULL, FALSE);
1530 return mount_point->is_loopback;
1533 static GUnixMountType
1534 guess_mount_type (const char *mount_path,
1535 const char *device_path,
1536 const char *filesystem_type)
1538 GUnixMountType type;
1541 type = G_UNIX_MOUNT_TYPE_UNKNOWN;
1543 if ((strcmp (filesystem_type, "udf") == 0) ||
1544 (strcmp (filesystem_type, "iso9660") == 0) ||
1545 (strcmp (filesystem_type, "cd9660") == 0))
1546 type = G_UNIX_MOUNT_TYPE_CDROM;
1547 else if (strcmp (filesystem_type, "nfs") == 0)
1548 type = G_UNIX_MOUNT_TYPE_NFS;
1549 else if (g_str_has_prefix (device_path, "/vol/dev/diskette/") ||
1550 g_str_has_prefix (device_path, "/dev/fd") ||
1551 g_str_has_prefix (device_path, "/dev/floppy"))
1552 type = G_UNIX_MOUNT_TYPE_FLOPPY;
1553 else if (g_str_has_prefix (device_path, "/dev/cdrom") ||
1554 g_str_has_prefix (device_path, "/dev/acd") ||
1555 g_str_has_prefix (device_path, "/dev/cd"))
1556 type = G_UNIX_MOUNT_TYPE_CDROM;
1557 else if (g_str_has_prefix (device_path, "/vol/"))
1559 const char *name = mount_path + strlen ("/");
1561 if (g_str_has_prefix (name, "cdrom"))
1562 type = G_UNIX_MOUNT_TYPE_CDROM;
1563 else if (g_str_has_prefix (name, "floppy") ||
1564 g_str_has_prefix (device_path, "/vol/dev/diskette/"))
1565 type = G_UNIX_MOUNT_TYPE_FLOPPY;
1566 else if (g_str_has_prefix (name, "rmdisk"))
1567 type = G_UNIX_MOUNT_TYPE_ZIP;
1568 else if (g_str_has_prefix (name, "jaz"))
1569 type = G_UNIX_MOUNT_TYPE_JAZ;
1570 else if (g_str_has_prefix (name, "memstick"))
1571 type = G_UNIX_MOUNT_TYPE_MEMSTICK;
1575 basename = g_path_get_basename (mount_path);
1577 if (g_str_has_prefix (basename, "cdrom") ||
1578 g_str_has_prefix (basename, "cdwriter") ||
1579 g_str_has_prefix (basename, "burn") ||
1580 g_str_has_prefix (basename, "cdr") ||
1581 g_str_has_prefix (basename, "cdrw") ||
1582 g_str_has_prefix (basename, "dvdrom") ||
1583 g_str_has_prefix (basename, "dvdram") ||
1584 g_str_has_prefix (basename, "dvdr") ||
1585 g_str_has_prefix (basename, "dvdrw") ||
1586 g_str_has_prefix (basename, "cdrom_dvdrom") ||
1587 g_str_has_prefix (basename, "cdrom_dvdram") ||
1588 g_str_has_prefix (basename, "cdrom_dvdr") ||
1589 g_str_has_prefix (basename, "cdrom_dvdrw") ||
1590 g_str_has_prefix (basename, "cdr_dvdrom") ||
1591 g_str_has_prefix (basename, "cdr_dvdram") ||
1592 g_str_has_prefix (basename, "cdr_dvdr") ||
1593 g_str_has_prefix (basename, "cdr_dvdrw") ||
1594 g_str_has_prefix (basename, "cdrw_dvdrom") ||
1595 g_str_has_prefix (basename, "cdrw_dvdram") ||
1596 g_str_has_prefix (basename, "cdrw_dvdr") ||
1597 g_str_has_prefix (basename, "cdrw_dvdrw"))
1598 type = G_UNIX_MOUNT_TYPE_CDROM;
1599 else if (g_str_has_prefix (basename, "floppy"))
1600 type = G_UNIX_MOUNT_TYPE_FLOPPY;
1601 else if (g_str_has_prefix (basename, "zip"))
1602 type = G_UNIX_MOUNT_TYPE_ZIP;
1603 else if (g_str_has_prefix (basename, "jaz"))
1604 type = G_UNIX_MOUNT_TYPE_JAZ;
1605 else if (g_str_has_prefix (basename, "camera"))
1606 type = G_UNIX_MOUNT_TYPE_CAMERA;
1607 else if (g_str_has_prefix (basename, "memstick") ||
1608 g_str_has_prefix (basename, "memory_stick") ||
1609 g_str_has_prefix (basename, "ram"))
1610 type = G_UNIX_MOUNT_TYPE_MEMSTICK;
1611 else if (g_str_has_prefix (basename, "compact_flash"))
1612 type = G_UNIX_MOUNT_TYPE_CF;
1613 else if (g_str_has_prefix (basename, "smart_media"))
1614 type = G_UNIX_MOUNT_TYPE_SM;
1615 else if (g_str_has_prefix (basename, "sd_mmc"))
1616 type = G_UNIX_MOUNT_TYPE_SDMMC;
1617 else if (g_str_has_prefix (basename, "ipod"))
1618 type = G_UNIX_MOUNT_TYPE_IPOD;
1623 if (type == G_UNIX_MOUNT_TYPE_UNKNOWN)
1624 type = G_UNIX_MOUNT_TYPE_HD;
1630 * g_unix_mount_guess_type:
1631 * @mount_entry: a #GUnixMount.
1633 * Guesses the type of a unix mount. If the mount type cannot be
1634 * determined, returns %G_UNIX_MOUNT_TYPE_UNKNOWN.
1636 * Returns: a #GUnixMountType.
1638 static GUnixMountType
1639 g_unix_mount_guess_type (GUnixMountEntry *mount_entry)
1641 g_return_val_if_fail (mount_entry != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1642 g_return_val_if_fail (mount_entry->mount_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1643 g_return_val_if_fail (mount_entry->device_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1644 g_return_val_if_fail (mount_entry->filesystem_type != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1646 return guess_mount_type (mount_entry->mount_path,
1647 mount_entry->device_path,
1648 mount_entry->filesystem_type);
1652 * g_unix_mount_point_guess_type:
1653 * @mount_point: a #GUnixMountPoint.
1655 * Guesses the type of a unix mount point.
1656 * If the mount type cannot be determined,
1657 * returns %G_UNIX_MOUNT_TYPE_UNKNOWN.
1659 * Returns: a #GUnixMountType.
1661 static GUnixMountType
1662 g_unix_mount_point_guess_type (GUnixMountPoint *mount_point)
1664 g_return_val_if_fail (mount_point != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1665 g_return_val_if_fail (mount_point->mount_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1666 g_return_val_if_fail (mount_point->device_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1667 g_return_val_if_fail (mount_point->filesystem_type != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1669 return guess_mount_type (mount_point->mount_path,
1670 mount_point->device_path,
1671 mount_point->filesystem_type);
1675 type_to_icon (GUnixMountType type, gboolean is_mount_point)
1677 const char *icon_name;
1681 case G_UNIX_MOUNT_TYPE_HD:
1683 icon_name = "drive-removable-media";
1685 icon_name = "drive-harddisk";
1687 case G_UNIX_MOUNT_TYPE_FLOPPY:
1688 case G_UNIX_MOUNT_TYPE_ZIP:
1689 case G_UNIX_MOUNT_TYPE_JAZ:
1691 icon_name = "drive-removable-media";
1693 icon_name = "media-floppy";
1695 case G_UNIX_MOUNT_TYPE_CDROM:
1697 icon_name = "drive-optical";
1699 icon_name = "media-optical";
1701 case G_UNIX_MOUNT_TYPE_NFS:
1702 /* TODO: Would like a better icon here... */
1704 icon_name = "drive-removable-media";
1706 icon_name = "drive-harddisk";
1708 case G_UNIX_MOUNT_TYPE_MEMSTICK:
1710 icon_name = "drive-removable-media";
1712 icon_name = "media-flash";
1714 case G_UNIX_MOUNT_TYPE_CAMERA:
1716 icon_name = "drive-removable-media";
1718 icon_name = "camera-photo";
1720 case G_UNIX_MOUNT_TYPE_IPOD:
1722 icon_name = "drive-removable-media";
1724 icon_name = "multimedia-player";
1726 case G_UNIX_MOUNT_TYPE_UNKNOWN:
1729 icon_name = "drive-removable-media";
1731 icon_name = "drive-harddisk";
1739 * g_unix_mount_guess_name:
1740 * @mount_entry: a #GUnixMountEntry
1742 * Guesses the name of a Unix mount.
1743 * The result is a translated string.
1745 * Returns: A newly allocated string that must
1746 * be freed with g_free()
1749 g_unix_mount_guess_name (GUnixMountEntry *mount_entry)
1753 if (strcmp (mount_entry->mount_path, "/") == 0)
1754 name = g_strdup (_("Filesystem root"));
1756 name = g_filename_display_basename (mount_entry->mount_path);
1762 * g_unix_mount_guess_icon:
1763 * @mount_entry: a #GUnixMountEntry
1765 * Guesses the icon of a Unix mount.
1770 g_unix_mount_guess_icon (GUnixMountEntry *mount_entry)
1772 return g_themed_icon_new_with_default_fallbacks (type_to_icon (g_unix_mount_guess_type (mount_entry), FALSE));
1776 * g_unix_mount_point_guess_name:
1777 * @mount_point: a #GUnixMountPoint
1779 * Guesses the name of a Unix mount point.
1780 * The result is a translated string.
1782 * Returns: A newly allocated string that must
1783 * be freed with g_free()
1786 g_unix_mount_point_guess_name (GUnixMountPoint *mount_point)
1790 if (strcmp (mount_point->mount_path, "/") == 0)
1791 name = g_strdup (_("Filesystem root"));
1793 name = g_filename_display_basename (mount_point->mount_path);
1799 * g_unix_mount_point_guess_icon:
1800 * @mount_point: a #GUnixMountPoint
1802 * Guesses the icon of a Unix mount point.
1807 g_unix_mount_point_guess_icon (GUnixMountPoint *mount_point)
1809 return g_themed_icon_new_with_default_fallbacks (type_to_icon (g_unix_mount_point_guess_type (mount_point), TRUE));
1813 * g_unix_mount_guess_can_eject:
1814 * @mount_entry: a #GUnixMountEntry
1816 * Guesses whether a Unix mount can be ejected.
1818 * Returns: %TRUE if @mount_entry is deemed to be ejectable.
1821 g_unix_mount_guess_can_eject (GUnixMountEntry *mount_entry)
1823 GUnixMountType guessed_type;
1825 guessed_type = g_unix_mount_guess_type (mount_entry);
1826 if (guessed_type == G_UNIX_MOUNT_TYPE_IPOD ||
1827 guessed_type == G_UNIX_MOUNT_TYPE_CDROM)
1834 * g_unix_mount_point_guess_can_eject:
1835 * @mount_point: a #GUnixMountPoint
1837 * Guesses whether a Unix mount point can be ejected.
1839 * Returns: %TRUE if @mount_point is deemed to be ejectable.
1842 g_unix_mount_point_guess_can_eject (GUnixMountPoint *mount_point)
1844 GUnixMountType guessed_type;
1846 guessed_type = g_unix_mount_point_guess_type (mount_point);
1847 if (guessed_type == G_UNIX_MOUNT_TYPE_IPOD ||
1848 guessed_type == G_UNIX_MOUNT_TYPE_CDROM)
1855 /* borrowed from gtk/gtkfilesystemunix.c in GTK+ on 02/23/2006 */
1857 _canonicalize_filename (gchar *filename)
1860 gboolean last_was_slash = FALSE;
1867 if (*p == G_DIR_SEPARATOR)
1869 if (!last_was_slash)
1870 *q++ = G_DIR_SEPARATOR;
1872 last_was_slash = TRUE;
1876 if (last_was_slash && *p == '.')
1878 if (*(p + 1) == G_DIR_SEPARATOR ||
1881 if (*(p + 1) == '\0')
1886 else if (*(p + 1) == '.' &&
1887 (*(p + 2) == G_DIR_SEPARATOR ||
1890 if (q > filename + 1)
1893 while (q > filename + 1 &&
1894 *(q - 1) != G_DIR_SEPARATOR)
1898 if (*(p + 2) == '\0')
1906 last_was_slash = FALSE;
1912 last_was_slash = FALSE;
1919 if (q > filename + 1 && *(q - 1) == G_DIR_SEPARATOR)
1926 _resolve_symlink (const char *file)
1934 f = g_strdup (file);
1936 while (g_file_test (f, G_FILE_TEST_IS_SYMLINK)) {
1937 link = g_file_read_link (f, &error);
1939 g_error_free (error);
1945 dir = g_path_get_dirname (f);
1946 f1 = g_strdup_printf ("%s/%s", dir, link);
1955 _canonicalize_filename (f);
1959 #ifdef HAVE_MNTENT_H
1961 _resolve_dev_root (void)
1963 static gboolean have_real_dev_root = FALSE;
1964 static char real_dev_root[256];
1965 struct stat statbuf;
1967 /* see if it's cached already */
1968 if (have_real_dev_root)
1971 /* otherwise we're going to find it right away.. */
1972 have_real_dev_root = TRUE;
1974 if (stat ("/dev/root", &statbuf) == 0) {
1975 if (! S_ISLNK (statbuf.st_mode)) {
1976 dev_t root_dev = statbuf.st_dev;
1980 /* see if device with similar major:minor as /dev/root is mention
1981 * in /etc/mtab (it usually is)
1983 f = fopen ("/etc/mtab", "r");
1987 while (getmntent_r (f, &ent, buf, sizeof (buf)) != NULL) {
1989 if (stat (ent.mnt_fsname, &statbuf) == 0 &&
1990 statbuf.st_dev == root_dev) {
1991 strncpy (real_dev_root, ent.mnt_fsname, sizeof (real_dev_root) - 1);
1992 real_dev_root[sizeof (real_dev_root) - 1] = '\0';
2000 /* no, that didn't work.. next we could scan /dev ... but I digress.. */
2004 resolved = _resolve_symlink ("/dev/root");
2005 if (resolved != NULL) {
2006 strncpy (real_dev_root, resolved, sizeof (real_dev_root) - 1);
2007 real_dev_root[sizeof (real_dev_root) - 1] = '\0';
2015 strcpy (real_dev_root, "/dev/root");
2018 return real_dev_root;
2022 #define __G_UNIX_MOUNTS_C__
2023 #include "gioaliasdef.c"