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[] = {
279 const char *ignore_devices[] = {
289 if (is_in (fs, ignore_fs))
292 if (is_in (device, ignore_devices))
295 if (g_unix_is_mount_path_system_internal (mountpoint))
304 get_mtab_read_file (void)
308 return "/proc/mounts";
310 return _PATH_MOUNTED;
318 get_mtab_monitor_file (void)
321 return _PATH_MOUNTED;
327 G_LOCK_DEFINE_STATIC(getmntent);
330 _g_get_unix_mounts ()
332 struct mntent *mntent;
335 GUnixMountEntry *mount_entry;
336 GHashTable *mounts_hash;
339 read_file = get_mtab_read_file ();
341 file = setmntent (read_file, "r");
347 mounts_hash = g_hash_table_new (g_str_hash, g_str_equal);
350 while ((mntent = getmntent (file)) != NULL)
352 /* ignore any mnt_fsname that is repeated and begins with a '/'
354 * We do this to avoid being fooled by --bind mounts, since
355 * these have the same device as the location they bind to.
356 * Its not an ideal solution to the problem, but its likely that
357 * the most important mountpoint is first and the --bind ones after
358 * that aren't as important. So it should work.
360 * The '/' is to handle procfs, tmpfs and other no device mounts.
362 if (mntent->mnt_fsname != NULL &&
363 mntent->mnt_fsname[0] == '/' &&
364 g_hash_table_lookup (mounts_hash, mntent->mnt_fsname))
367 mount_entry = g_new0 (GUnixMountEntry, 1);
368 mount_entry->mount_path = g_strdup (mntent->mnt_dir);
369 if (strcmp (mntent->mnt_fsname, "/dev/root") == 0)
370 mount_entry->device_path = g_strdup (_resolve_dev_root ());
372 mount_entry->device_path = g_strdup (mntent->mnt_fsname);
373 mount_entry->filesystem_type = g_strdup (mntent->mnt_type);
375 #if defined (HAVE_HASMNTOPT)
376 if (hasmntopt (mntent, MNTOPT_RO) != NULL)
377 mount_entry->is_read_only = TRUE;
380 mount_entry->is_system_internal =
381 guess_system_internal (mount_entry->mount_path,
382 mount_entry->filesystem_type,
383 mount_entry->device_path);
385 g_hash_table_insert (mounts_hash,
386 mount_entry->device_path,
387 mount_entry->device_path);
389 return_list = g_list_prepend (return_list, mount_entry);
391 g_hash_table_destroy (mounts_hash);
395 G_UNLOCK (getmntent);
397 return g_list_reverse (return_list);
400 #elif defined (HAVE_SYS_MNTTAB_H)
402 G_LOCK_DEFINE_STATIC(getmntent);
405 get_mtab_read_file (void)
408 return _PATH_MOUNTED;
410 return "/etc/mnttab";
415 get_mtab_monitor_file (void)
417 return get_mtab_read_file ();
421 _g_get_unix_mounts (void)
423 struct mnttab mntent;
426 GUnixMountEntry *mount_entry;
429 read_file = get_mtab_read_file ();
431 file = setmntent (read_file, "r");
438 while (! getmntent (file, &mntent))
440 mount_entry = g_new0 (GUnixMountEntry, 1);
442 mount_entry->mount_path = g_strdup (mntent.mnt_mountp);
443 mount_entry->device_path = g_strdup (mntent.mnt_special);
444 mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype);
446 #if defined (HAVE_HASMNTOPT)
447 if (hasmntopt (&mntent, MNTOPT_RO) != NULL)
448 mount_entry->is_read_only = TRUE;
451 mount_entry->is_system_internal =
452 guess_system_internal (mount_entry->mount_path,
453 mount_entry->filesystem_type,
454 mount_entry->device_path);
456 return_list = g_list_prepend (return_list, mount_entry);
461 G_UNLOCK (getmntent);
463 return g_list_reverse (return_list);
466 #elif defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
469 get_mtab_monitor_file (void)
475 _g_get_unix_mounts (void)
477 struct vfs_ent *fs_info;
478 struct vmount *vmount_info;
480 unsigned int vmount_size;
484 if (mntctl (MCTL_QUERY, sizeof (vmount_size), &vmount_size) != 0)
486 g_warning ("Unable to know the number of mounted volumes\n");
491 vmount_info = (struct vmount*)g_malloc (vmount_size);
493 vmount_number = mntctl (MCTL_QUERY, vmount_size, vmount_info);
495 if (vmount_info->vmt_revision != VMT_REVISION)
496 g_warning ("Bad vmount structure revision number, want %d, got %d\n", VMT_REVISION, vmount_info->vmt_revision);
498 if (vmount_number < 0)
500 g_warning ("Unable to recover mounted volumes information\n");
502 g_free (vmount_info);
507 while (vmount_number > 0)
509 mount_entry = g_new0 (GUnixMountEntry, 1);
511 mount_entry->device_path = g_strdup (vmt2dataptr (vmount_info, VMT_OBJECT));
512 mount_entry->mount_path = g_strdup (vmt2dataptr (vmount_info, VMT_STUB));
513 /* is_removable = (vmount_info->vmt_flags & MNT_REMOVABLE) ? 1 : 0; */
514 mount_entry->is_read_only = (vmount_info->vmt_flags & MNT_READONLY) ? 1 : 0;
516 fs_info = getvfsbytype (vmount_info->vmt_gfstype);
519 mount_entry->filesystem_type = g_strdup ("unknown");
521 mount_entry->filesystem_type = g_strdup (fs_info->vfsent_name);
523 mount_entry->is_system_internal =
524 guess_system_internal (mount_entry->mount_path,
525 mount_entry->filesystem_type,
526 mount_entry->device_path);
528 return_list = g_list_prepend (return_list, mount_entry);
530 vmount_info = (struct vmount *)( (char*)vmount_info
531 + vmount_info->vmt_length);
536 g_free (vmount_info);
538 return g_list_reverse (return_list);
541 #elif defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
544 get_mtab_monitor_file (void)
550 _g_get_unix_mounts (void)
552 struct statfs *mntent = NULL;
554 GUnixMountEntry *mount_entry;
557 /* Pass MNT_NOWAIT to avoid blocking trying to update NFS mounts. */
558 if ((num_mounts = getmntinfo (&mntent, MNT_NOWAIT)) == 0)
563 for (i = 0; i < num_mounts; i++)
565 mount_entry = g_new0 (GUnixMountEntry, 1);
567 mount_entry->mount_path = g_strdup (mntent[i].f_mntonname);
568 mount_entry->device_path = g_strdup (mntent[i].f_mntfromname);
569 mount_entry->filesystem_type = g_strdup (mntent[i].f_fstypename);
570 if (mntent[i].f_flags & MNT_RDONLY)
571 mount_entry->is_read_only = TRUE;
573 mount_entry->is_system_internal =
574 guess_system_internal (mount_entry->mount_path,
575 mount_entry->filesystem_type,
576 mount_entry->device_path);
578 return_list = g_list_prepend (return_list, mount_entry);
581 return g_list_reverse (return_list);
584 #error No _g_get_unix_mounts() implementation for system
587 /* _g_get_unix_mount_points():
589 * don't return swap and ignore mounts.
593 get_fstab_file (void)
595 #if defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
597 return "/etc/filesystems";
598 #elif defined(_PATH_MNTTAB)
600 #elif defined(VFSTAB)
609 _g_get_unix_mount_points (void)
611 struct mntent *mntent;
614 GUnixMountPoint *mount_entry;
617 read_file = get_fstab_file ();
619 file = setmntent (read_file, "r");
626 while ((mntent = getmntent (file)) != NULL)
628 if ((strcmp (mntent->mnt_dir, "ignore") == 0) ||
629 (strcmp (mntent->mnt_dir, "swap") == 0))
632 mount_entry = g_new0 (GUnixMountPoint, 1);
633 mount_entry->mount_path = g_strdup (mntent->mnt_dir);
634 if (strcmp (mntent->mnt_fsname, "/dev/root") == 0)
635 mount_entry->device_path = g_strdup (_resolve_dev_root ());
637 mount_entry->device_path = g_strdup (mntent->mnt_fsname);
638 mount_entry->filesystem_type = g_strdup (mntent->mnt_type);
640 #ifdef HAVE_HASMNTOPT
641 if (hasmntopt (mntent, MNTOPT_RO) != NULL)
642 mount_entry->is_read_only = TRUE;
644 if (hasmntopt (mntent, "loop") != NULL)
645 mount_entry->is_loopback = TRUE;
649 if ((mntent->mnt_type != NULL && strcmp ("supermount", mntent->mnt_type) == 0)
650 #ifdef HAVE_HASMNTOPT
651 || (hasmntopt (mntent, "user") != NULL
652 && hasmntopt (mntent, "user") != hasmntopt (mntent, "user_xattr"))
653 || hasmntopt (mntent, "pamconsole") != NULL
654 || hasmntopt (mntent, "users") != NULL
655 || hasmntopt (mntent, "owner") != NULL
658 mount_entry->is_user_mountable = TRUE;
660 return_list = g_list_prepend (return_list, mount_entry);
664 G_UNLOCK (getmntent);
666 return g_list_reverse (return_list);
669 #elif defined (HAVE_SYS_MNTTAB_H)
672 _g_get_unix_mount_points (void)
674 struct mnttab mntent;
677 GUnixMountPoint *mount_entry;
680 read_file = get_fstab_file ();
682 file = setmntent (read_file, "r");
689 while (! getmntent (file, &mntent))
691 if ((strcmp (mntent.mnt_mountp, "ignore") == 0) ||
692 (strcmp (mntent.mnt_mountp, "swap") == 0))
695 mount_entry = g_new0 (GUnixMountPoint, 1);
697 mount_entry->mount_path = g_strdup (mntent.mnt_mountp);
698 mount_entry->device_path = g_strdup (mntent.mnt_special);
699 mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype);
701 #ifdef HAVE_HASMNTOPT
702 if (hasmntopt (&mntent, MNTOPT_RO) != NULL)
703 mount_entry->is_read_only = TRUE;
705 if (hasmntopt (&mntent, "lofs") != NULL)
706 mount_entry->is_loopback = TRUE;
709 if ((mntent.mnt_fstype != NULL)
710 #ifdef HAVE_HASMNTOPT
711 || (hasmntopt (&mntent, "user") != NULL
712 && hasmntopt (&mntent, "user") != hasmntopt (&mntent, "user_xattr"))
713 || hasmntopt (&mntent, "pamconsole") != NULL
714 || hasmntopt (&mntent, "users") != NULL
715 || hasmntopt (&mntent, "owner") != NULL
718 mount_entry->is_user_mountable = TRUE;
721 return_list = g_list_prepend (return_list, mount_entry);
725 G_UNLOCK (getmntent);
727 return g_list_reverse (return_list);
729 #elif defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
731 /* functions to parse /etc/filesystems on aix */
733 /* read character, ignoring comments (begin with '*', end with '\n' */
735 aix_fs_getc (FILE *fd)
739 while ((c = getc (fd)) == '*')
741 while (((c = getc (fd)) != '\n') && (c != EOF))
746 /* eat all continuous spaces in a file */
748 aix_fs_ignorespace (FILE *fd)
752 while ((c = aix_fs_getc (fd)) != EOF)
754 if (!g_ascii_isspace (c))
764 /* read one word from file */
766 aix_fs_getword (FILE *fd,
771 aix_fs_ignorespace (fd);
773 while (((c = aix_fs_getc (fd)) != EOF) && !g_ascii_isspace (c))
777 while (((c = aix_fs_getc (fd)) != EOF) && (c != '"'))
789 char mnt_mount[PATH_MAX];
790 char mnt_special[PATH_MAX];
792 char mnt_options[128];
793 } AixMountTableEntry;
795 /* read mount points properties */
797 aix_fs_get (FILE *fd,
798 AixMountTableEntry *prop)
800 static char word[PATH_MAX] = { 0 };
801 char value[PATH_MAX];
806 if (aix_fs_getword (fd, word) == EOF)
810 word[strlen(word) - 1] = 0;
811 strcpy (prop->mnt_mount, word);
813 /* read attributes and value */
815 while (aix_fs_getword (fd, word) != EOF)
817 /* test if is attribute or new stanza */
818 if (word[strlen(word) - 1] == ':')
822 aix_fs_getword (fd, value);
825 aix_fs_getword (fd, value);
827 if (strcmp (word, "dev") == 0)
828 strcpy (prop->mnt_special, value);
829 else if (strcmp (word, "vfs") == 0)
830 strcpy (prop->mnt_fstype, value);
831 else if (strcmp (word, "options") == 0)
832 strcpy(prop->mnt_options, value);
839 _g_get_unix_mount_points (void)
841 struct mntent *mntent;
844 GUnixMountPoint *mount_entry;
845 AixMountTableEntry mntent;
848 read_file = get_fstab_file ();
850 file = setmntent (read_file, "r");
856 while (!aix_fs_get (file, &mntent))
858 if (strcmp ("cdrfs", mntent.mnt_fstype) == 0)
860 mount_entry = g_new0 (GUnixMountPoint, 1);
863 mount_entry->mount_path = g_strdup (mntent.mnt_mount);
864 mount_entry->device_path = g_strdup (mntent.mnt_special);
865 mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype);
866 mount_entry->is_read_only = TRUE;
867 mount_entry->is_user_mountable = TRUE;
869 return_list = g_list_prepend (return_list, mount_entry);
875 return g_list_reverse (return_list);
878 #elif defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
881 _g_get_unix_mount_points (void)
883 struct fstab *fstab = NULL;
884 GUnixMountPoint *mount_entry;
886 #ifdef HAVE_SYS_SYSCTL_H
888 size_t len = sizeof(usermnt);
897 #ifdef HAVE_SYS_SYSCTL_H
898 #if defined(HAVE_SYSCTLBYNAME)
899 sysctlbyname ("vfs.usermount", &usermnt, &len, NULL, 0);
900 #elif defined(CTL_VFS) && defined(VFS_USERMOUNT)
905 mib[1] = VFS_USERMOUNT;
906 sysctl (mib, 2, &usermnt, &len, NULL, 0);
908 #elif defined(CTL_KERN) && defined(KERN_USERMOUNT)
913 mib[1] = KERN_USERMOUNT;
914 sysctl (mib, 2, &usermnt, &len, NULL, 0);
919 while ((fstab = getfsent ()) != NULL)
921 if (strcmp (fstab->fs_vfstype, "swap") == 0)
924 mount_entry = g_new0 (GUnixMountPoint, 1);
926 mount_entry->mount_path = g_strdup (fstab->fs_file);
927 mount_entry->device_path = g_strdup (fstab->fs_spec);
928 mount_entry->filesystem_type = g_strdup (fstab->fs_vfstype);
930 if (strcmp (fstab->fs_type, "ro") == 0)
931 mount_entry->is_read_only = TRUE;
933 #ifdef HAVE_SYS_SYSCTL_H
936 uid_t uid = getuid ();
937 if (stat (fstab->fs_file, &sb) == 0)
939 if (uid == 0 || sb.st_uid == uid)
940 mount_entry->is_user_mountable = TRUE;
945 return_list = g_list_prepend (return_list, mount_entry);
950 return g_list_reverse (return_list);
953 #error No g_get_mount_table() implementation for system
957 get_mounts_timestamp (void)
959 const char *monitor_file;
962 monitor_file = get_mtab_monitor_file ();
965 if (stat (monitor_file, &buf) == 0)
966 return (guint64)buf.st_mtime;
972 get_mount_points_timestamp (void)
974 const char *monitor_file;
977 monitor_file = get_fstab_file ();
980 if (stat (monitor_file, &buf) == 0)
981 return (guint64)buf.st_mtime;
988 * @time_read: guint64 to contain a timestamp.
990 * Gets a #GList of strings containing the unix mounts.
991 * If @time_read is set, it will be filled with the mount
992 * timestamp, allowing for checking if the mounts have changed
993 * with g_unix_mounts_changed_since().
995 * Returns: a #GList of the UNIX mounts.
998 g_unix_mounts_get (guint64 *time_read)
1001 *time_read = get_mounts_timestamp ();
1003 return _g_get_unix_mounts ();
1008 * @mount_path: path for a possible unix mount.
1009 * @time_read: guint64 to contain a timestamp.
1011 * Gets a #GUnixMountEntry for a given mount path. If @time_read
1012 * is set, it will be filled with a unix timestamp for checking
1013 * if the mounts have changed since with g_unix_mounts_changed_since().
1015 * Returns: a #GUnixMount.
1018 g_unix_mount_at (const char *mount_path,
1022 GUnixMountEntry *mount_entry, *found;
1024 mounts = g_unix_mounts_get (time_read);
1027 for (l = mounts; l != NULL; l = l->next)
1029 mount_entry = l->data;
1031 if (strcmp (mount_path, mount_entry->mount_path) == 0)
1032 found = mount_entry;
1034 g_unix_mount_free (mount_entry);
1037 g_list_free (mounts);
1043 * g_unix_mount_points_get:
1044 * @time_read: guint64 to contain a timestamp.
1046 * Gets a #GList of strings containing the unix mount points.
1047 * If @time_read is set, it will be filled with the mount timestamp,
1048 * allowing for checking if the mounts have changed with
1049 * g_unix_mounts_points_changed_since().
1051 * Returns: a #GList of the UNIX mountpoints.
1054 g_unix_mount_points_get (guint64 *time_read)
1057 *time_read = get_mount_points_timestamp ();
1059 return _g_get_unix_mount_points ();
1063 * g_unix_mounts_changed_since:
1064 * @time: guint64 to contain a timestamp.
1066 * Checks if the unix mounts have changed since a given unix time.
1068 * Returns: %TRUE if the mounts have changed since @time.
1071 g_unix_mounts_changed_since (guint64 time)
1073 return get_mounts_timestamp () != time;
1077 * g_unix_mount_points_changed_since:
1078 * @time: guint64 to contain a timestamp.
1080 * Checks if the unix mount points have changed since a given unix time.
1082 * Returns: %TRUE if the mount points have changed since @time.
1085 g_unix_mount_points_changed_since (guint64 time)
1087 return get_mount_points_timestamp () != time;
1091 g_unix_mount_monitor_finalize (GObject *object)
1093 GUnixMountMonitor *monitor;
1095 monitor = G_UNIX_MOUNT_MONITOR (object);
1097 if (monitor->fstab_monitor)
1099 g_file_monitor_cancel (monitor->fstab_monitor);
1100 g_object_unref (monitor->fstab_monitor);
1103 if (monitor->mtab_monitor)
1105 g_file_monitor_cancel (monitor->mtab_monitor);
1106 g_object_unref (monitor->mtab_monitor);
1109 the_mount_monitor = NULL;
1111 if (G_OBJECT_CLASS (g_unix_mount_monitor_parent_class)->finalize)
1112 (*G_OBJECT_CLASS (g_unix_mount_monitor_parent_class)->finalize) (object);
1117 g_unix_mount_monitor_class_init (GUnixMountMonitorClass *klass)
1119 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
1121 gobject_class->finalize = g_unix_mount_monitor_finalize;
1123 * GUnixMountMonitor::mounts-changed:
1125 * Emitted when the unix mounts have changed.
1127 signals[MOUNTS_CHANGED] =
1128 g_signal_new ("mounts_changed",
1129 G_TYPE_FROM_CLASS (klass),
1133 g_cclosure_marshal_VOID__VOID,
1136 * GUnixMountMonitor::mountpoints-changed:
1138 * Emitted when the unix mount points have changed.
1140 signals[MOUNTPOINTS_CHANGED] =
1141 g_signal_new ("mountpoints_changed",
1142 G_TYPE_FROM_CLASS (klass),
1146 g_cclosure_marshal_VOID__VOID,
1151 fstab_file_changed (GFileMonitor *monitor,
1154 GFileMonitorEvent event_type,
1157 GUnixMountMonitor *mount_monitor;
1159 if (event_type != G_FILE_MONITOR_EVENT_CHANGED &&
1160 event_type != G_FILE_MONITOR_EVENT_CREATED &&
1161 event_type != G_FILE_MONITOR_EVENT_DELETED)
1164 mount_monitor = user_data;
1165 g_signal_emit (mount_monitor, signals[MOUNTPOINTS_CHANGED], 0);
1169 mtab_file_changed (GFileMonitor *monitor,
1172 GFileMonitorEvent event_type,
1175 GUnixMountMonitor *mount_monitor;
1177 if (event_type != G_FILE_MONITOR_EVENT_CHANGED &&
1178 event_type != G_FILE_MONITOR_EVENT_CREATED &&
1179 event_type != G_FILE_MONITOR_EVENT_DELETED)
1182 mount_monitor = user_data;
1183 g_signal_emit (mount_monitor, signals[MOUNTS_CHANGED], 0);
1187 g_unix_mount_monitor_init (GUnixMountMonitor *monitor)
1191 if (get_fstab_file () != NULL)
1193 file = g_file_new_for_path (get_fstab_file ());
1194 monitor->fstab_monitor = g_file_monitor_file (file, 0, NULL);
1195 g_object_unref (file);
1197 g_signal_connect (monitor->fstab_monitor, "changed", (GCallback)fstab_file_changed, monitor);
1200 if (get_mtab_monitor_file () != NULL)
1202 file = g_file_new_for_path (get_mtab_monitor_file ());
1203 monitor->mtab_monitor = g_file_monitor_file (file, 0, NULL);
1204 g_object_unref (file);
1206 g_signal_connect (monitor->mtab_monitor, "changed", (GCallback)mtab_file_changed, monitor);
1211 * g_unix_mount_monitor_new:
1213 * Gets a new #GUnixMountMonitor.
1215 * Returns: a #GUnixMountMonitor.
1218 g_unix_mount_monitor_new (void)
1220 if (the_mount_monitor == NULL)
1222 the_mount_monitor = g_object_new (G_TYPE_UNIX_MOUNT_MONITOR, NULL);
1223 return the_mount_monitor;
1226 return g_object_ref (the_mount_monitor);
1230 * g_unix_mount_free:
1231 * @mount_entry: a #GUnixMount.
1233 * Frees a unix mount.
1236 g_unix_mount_free (GUnixMountEntry *mount_entry)
1238 g_return_if_fail (mount_entry != NULL);
1240 g_free (mount_entry->mount_path);
1241 g_free (mount_entry->device_path);
1242 g_free (mount_entry->filesystem_type);
1243 g_free (mount_entry);
1247 * g_unix_mount_point_free:
1248 * @mount_point: unix mount point to free.
1250 * Frees a unix mount point.
1253 g_unix_mount_point_free (GUnixMountPoint *mount_point)
1255 g_return_if_fail (mount_point != NULL);
1257 g_free (mount_point->mount_path);
1258 g_free (mount_point->device_path);
1259 g_free (mount_point->filesystem_type);
1260 g_free (mount_point);
1264 strcmp_null (const char *str1,
1269 if (str1 == NULL && str2 != NULL)
1271 if (str1 != NULL && str2 == NULL)
1273 return strcmp (str1, str2);
1277 * g_unix_mount_compare:
1278 * @mount1: first #GUnixMountEntry to compare.
1279 * @mount2: second #GUnixMountEntry to compare.
1281 * Compares two unix mounts.
1283 * Returns: 1, 0 or -1 if @mount1 is greater than, equal to,
1284 * or less than @mount2, respectively.
1287 g_unix_mount_compare (GUnixMountEntry *mount1,
1288 GUnixMountEntry *mount2)
1292 g_return_val_if_fail (mount1 != NULL && mount2 != NULL, 0);
1294 res = strcmp_null (mount1->mount_path, mount2->mount_path);
1298 res = strcmp_null (mount1->device_path, mount2->device_path);
1302 res = strcmp_null (mount1->filesystem_type, mount2->filesystem_type);
1306 res = mount1->is_read_only - mount2->is_read_only;
1314 * g_unix_mount_get_mount_path:
1315 * @mount_entry: input #GUnixMountEntry to get the mount path for.
1317 * Gets the mount path for a unix mount.
1319 * Returns: the mount path for @mount_entry.
1322 g_unix_mount_get_mount_path (GUnixMountEntry *mount_entry)
1324 g_return_val_if_fail (mount_entry != NULL, NULL);
1326 return mount_entry->mount_path;
1330 * g_unix_mount_get_device_path:
1331 * @mount_entry: a #GUnixMount.
1333 * Gets the device path for a unix mount.
1335 * Returns: a string containing the device path.
1338 g_unix_mount_get_device_path (GUnixMountEntry *mount_entry)
1340 g_return_val_if_fail (mount_entry != NULL, NULL);
1342 return mount_entry->device_path;
1346 * g_unix_mount_get_fs_type:
1347 * @mount_entry: a #GUnixMount.
1349 * Gets the filesystem type for the unix mount.
1351 * Returns: a string containing the file system type.
1354 g_unix_mount_get_fs_type (GUnixMountEntry *mount_entry)
1356 g_return_val_if_fail (mount_entry != NULL, NULL);
1358 return mount_entry->filesystem_type;
1362 * g_unix_mount_is_readonly:
1363 * @mount_entry: a #GUnixMount.
1365 * Checks if a unix mount is mounted read only.
1367 * Returns: %TRUE if @mount_entry is read only.
1370 g_unix_mount_is_readonly (GUnixMountEntry *mount_entry)
1372 g_return_val_if_fail (mount_entry != NULL, FALSE);
1374 return mount_entry->is_read_only;
1378 * g_unix_mount_is_system_internal:
1379 * @mount_entry: a #GUnixMount.
1381 * Checks if a unix mount is a system path.
1383 * Returns: %TRUE if the unix mount is for a system path.
1386 g_unix_mount_is_system_internal (GUnixMountEntry *mount_entry)
1388 g_return_val_if_fail (mount_entry != NULL, FALSE);
1390 return mount_entry->is_system_internal;
1394 * g_unix_mount_point_compare:
1395 * @mount1: a #GUnixMount.
1396 * @mount2: a #GUnixMount.
1398 * Compares two unix mount points.
1400 * Returns: 1, 0 or -1 if @mount1 is greater than, equal to,
1401 * or less than @mount2, respectively.
1404 g_unix_mount_point_compare (GUnixMountPoint *mount1,
1405 GUnixMountPoint *mount2)
1409 g_return_val_if_fail (mount1 != NULL && mount2 != NULL, 0);
1411 res = strcmp_null (mount1->mount_path, mount2->mount_path);
1415 res = strcmp_null (mount1->device_path, mount2->device_path);
1419 res = strcmp_null (mount1->filesystem_type, mount2->filesystem_type);
1423 res = mount1->is_read_only - mount2->is_read_only;
1427 res = mount1->is_user_mountable - mount2->is_user_mountable;
1431 res = mount1->is_loopback - mount2->is_loopback;
1439 * g_unix_mount_point_get_mount_path:
1440 * @mount_point: a #GUnixMountPoint.
1442 * Gets the mount path for a unix mount point.
1444 * Returns: a string containing the mount path.
1447 g_unix_mount_point_get_mount_path (GUnixMountPoint *mount_point)
1449 g_return_val_if_fail (mount_point != NULL, NULL);
1451 return mount_point->mount_path;
1455 * g_unix_mount_point_get_device_path:
1456 * @mount_point: a #GUnixMountPoint.
1458 * Gets the device path for a unix mount point.
1460 * Returns: a string containing the device path.
1463 g_unix_mount_point_get_device_path (GUnixMountPoint *mount_point)
1465 g_return_val_if_fail (mount_point != NULL, NULL);
1467 return mount_point->device_path;
1471 * g_unix_mount_point_get_fs_type:
1472 * @mount_point: a #GUnixMountPoint.
1474 * Gets the file system type for the mount point.
1476 * Returns: a string containing the file system type.
1479 g_unix_mount_point_get_fs_type (GUnixMountPoint *mount_point)
1481 g_return_val_if_fail (mount_point != NULL, NULL);
1483 return mount_point->filesystem_type;
1487 * g_unix_mount_point_is_readonly:
1488 * @mount_point: a #GUnixMountPoint.
1490 * Checks if a unix mount point is read only.
1492 * Returns: %TRUE if a mount point is read only.
1495 g_unix_mount_point_is_readonly (GUnixMountPoint *mount_point)
1497 g_return_val_if_fail (mount_point != NULL, FALSE);
1499 return mount_point->is_read_only;
1503 * g_unix_mount_point_is_user_mountable:
1504 * @mount_point: a #GUnixMountPoint.
1506 * Checks if a unix mount point is mountable by the user.
1508 * Returns: %TRUE if the mount point is user mountable.
1511 g_unix_mount_point_is_user_mountable (GUnixMountPoint *mount_point)
1513 g_return_val_if_fail (mount_point != NULL, FALSE);
1515 return mount_point->is_user_mountable;
1519 * g_unix_mount_point_is_loopback:
1520 * @mount_point: a #GUnixMountPoint.
1522 * Checks if a unix mount point is a loopback device.
1524 * Returns: %TRUE if the mount point is a loopback. %FALSE otherwise.
1527 g_unix_mount_point_is_loopback (GUnixMountPoint *mount_point)
1529 g_return_val_if_fail (mount_point != NULL, FALSE);
1531 return mount_point->is_loopback;
1534 static GUnixMountType
1535 guess_mount_type (const char *mount_path,
1536 const char *device_path,
1537 const char *filesystem_type)
1539 GUnixMountType type;
1542 type = G_UNIX_MOUNT_TYPE_UNKNOWN;
1544 if ((strcmp (filesystem_type, "udf") == 0) ||
1545 (strcmp (filesystem_type, "iso9660") == 0) ||
1546 (strcmp (filesystem_type, "cd9660") == 0))
1547 type = G_UNIX_MOUNT_TYPE_CDROM;
1548 else if (strcmp (filesystem_type, "nfs") == 0)
1549 type = G_UNIX_MOUNT_TYPE_NFS;
1550 else if (g_str_has_prefix (device_path, "/vol/dev/diskette/") ||
1551 g_str_has_prefix (device_path, "/dev/fd") ||
1552 g_str_has_prefix (device_path, "/dev/floppy"))
1553 type = G_UNIX_MOUNT_TYPE_FLOPPY;
1554 else if (g_str_has_prefix (device_path, "/dev/cdrom") ||
1555 g_str_has_prefix (device_path, "/dev/acd") ||
1556 g_str_has_prefix (device_path, "/dev/cd"))
1557 type = G_UNIX_MOUNT_TYPE_CDROM;
1558 else if (g_str_has_prefix (device_path, "/vol/"))
1560 const char *name = mount_path + strlen ("/");
1562 if (g_str_has_prefix (name, "cdrom"))
1563 type = G_UNIX_MOUNT_TYPE_CDROM;
1564 else if (g_str_has_prefix (name, "floppy") ||
1565 g_str_has_prefix (device_path, "/vol/dev/diskette/"))
1566 type = G_UNIX_MOUNT_TYPE_FLOPPY;
1567 else if (g_str_has_prefix (name, "rmdisk"))
1568 type = G_UNIX_MOUNT_TYPE_ZIP;
1569 else if (g_str_has_prefix (name, "jaz"))
1570 type = G_UNIX_MOUNT_TYPE_JAZ;
1571 else if (g_str_has_prefix (name, "memstick"))
1572 type = G_UNIX_MOUNT_TYPE_MEMSTICK;
1576 basename = g_path_get_basename (mount_path);
1578 if (g_str_has_prefix (basename, "cdrom") ||
1579 g_str_has_prefix (basename, "cdwriter") ||
1580 g_str_has_prefix (basename, "burn") ||
1581 g_str_has_prefix (basename, "cdr") ||
1582 g_str_has_prefix (basename, "cdrw") ||
1583 g_str_has_prefix (basename, "dvdrom") ||
1584 g_str_has_prefix (basename, "dvdram") ||
1585 g_str_has_prefix (basename, "dvdr") ||
1586 g_str_has_prefix (basename, "dvdrw") ||
1587 g_str_has_prefix (basename, "cdrom_dvdrom") ||
1588 g_str_has_prefix (basename, "cdrom_dvdram") ||
1589 g_str_has_prefix (basename, "cdrom_dvdr") ||
1590 g_str_has_prefix (basename, "cdrom_dvdrw") ||
1591 g_str_has_prefix (basename, "cdr_dvdrom") ||
1592 g_str_has_prefix (basename, "cdr_dvdram") ||
1593 g_str_has_prefix (basename, "cdr_dvdr") ||
1594 g_str_has_prefix (basename, "cdr_dvdrw") ||
1595 g_str_has_prefix (basename, "cdrw_dvdrom") ||
1596 g_str_has_prefix (basename, "cdrw_dvdram") ||
1597 g_str_has_prefix (basename, "cdrw_dvdr") ||
1598 g_str_has_prefix (basename, "cdrw_dvdrw"))
1599 type = G_UNIX_MOUNT_TYPE_CDROM;
1600 else if (g_str_has_prefix (basename, "floppy"))
1601 type = G_UNIX_MOUNT_TYPE_FLOPPY;
1602 else if (g_str_has_prefix (basename, "zip"))
1603 type = G_UNIX_MOUNT_TYPE_ZIP;
1604 else if (g_str_has_prefix (basename, "jaz"))
1605 type = G_UNIX_MOUNT_TYPE_JAZ;
1606 else if (g_str_has_prefix (basename, "camera"))
1607 type = G_UNIX_MOUNT_TYPE_CAMERA;
1608 else if (g_str_has_prefix (basename, "memstick") ||
1609 g_str_has_prefix (basename, "memory_stick") ||
1610 g_str_has_prefix (basename, "ram"))
1611 type = G_UNIX_MOUNT_TYPE_MEMSTICK;
1612 else if (g_str_has_prefix (basename, "compact_flash"))
1613 type = G_UNIX_MOUNT_TYPE_CF;
1614 else if (g_str_has_prefix (basename, "smart_media"))
1615 type = G_UNIX_MOUNT_TYPE_SM;
1616 else if (g_str_has_prefix (basename, "sd_mmc"))
1617 type = G_UNIX_MOUNT_TYPE_SDMMC;
1618 else if (g_str_has_prefix (basename, "ipod"))
1619 type = G_UNIX_MOUNT_TYPE_IPOD;
1624 if (type == G_UNIX_MOUNT_TYPE_UNKNOWN)
1625 type = G_UNIX_MOUNT_TYPE_HD;
1631 * g_unix_mount_guess_type:
1632 * @mount_entry: a #GUnixMount.
1634 * Guesses the type of a unix mount. If the mount type cannot be
1635 * determined, returns %G_UNIX_MOUNT_TYPE_UNKNOWN.
1637 * Returns: a #GUnixMountType.
1639 static GUnixMountType
1640 g_unix_mount_guess_type (GUnixMountEntry *mount_entry)
1642 g_return_val_if_fail (mount_entry != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1643 g_return_val_if_fail (mount_entry->mount_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1644 g_return_val_if_fail (mount_entry->device_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1645 g_return_val_if_fail (mount_entry->filesystem_type != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1647 return guess_mount_type (mount_entry->mount_path,
1648 mount_entry->device_path,
1649 mount_entry->filesystem_type);
1653 * g_unix_mount_point_guess_type:
1654 * @mount_point: a #GUnixMountPoint.
1656 * Guesses the type of a unix mount point.
1657 * If the mount type cannot be determined,
1658 * returns %G_UNIX_MOUNT_TYPE_UNKNOWN.
1660 * Returns: a #GUnixMountType.
1662 static GUnixMountType
1663 g_unix_mount_point_guess_type (GUnixMountPoint *mount_point)
1665 g_return_val_if_fail (mount_point != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1666 g_return_val_if_fail (mount_point->mount_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1667 g_return_val_if_fail (mount_point->device_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1668 g_return_val_if_fail (mount_point->filesystem_type != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
1670 return guess_mount_type (mount_point->mount_path,
1671 mount_point->device_path,
1672 mount_point->filesystem_type);
1676 type_to_icon (GUnixMountType type, gboolean is_mount_point)
1678 const char *icon_name;
1682 case G_UNIX_MOUNT_TYPE_HD:
1684 icon_name = "drive-removable-media";
1686 icon_name = "drive-harddisk";
1688 case G_UNIX_MOUNT_TYPE_FLOPPY:
1689 case G_UNIX_MOUNT_TYPE_ZIP:
1690 case G_UNIX_MOUNT_TYPE_JAZ:
1692 icon_name = "drive-removable-media";
1694 icon_name = "media-floppy";
1696 case G_UNIX_MOUNT_TYPE_CDROM:
1698 icon_name = "drive-optical";
1700 icon_name = "media-optical";
1702 case G_UNIX_MOUNT_TYPE_NFS:
1703 /* TODO: Would like a better icon here... */
1705 icon_name = "drive-removable-media";
1707 icon_name = "drive-harddisk";
1709 case G_UNIX_MOUNT_TYPE_MEMSTICK:
1711 icon_name = "drive-removable-media";
1713 icon_name = "media-flash";
1715 case G_UNIX_MOUNT_TYPE_CAMERA:
1717 icon_name = "drive-removable-media";
1719 icon_name = "camera-photo";
1721 case G_UNIX_MOUNT_TYPE_IPOD:
1723 icon_name = "drive-removable-media";
1725 icon_name = "multimedia-player";
1727 case G_UNIX_MOUNT_TYPE_UNKNOWN:
1730 icon_name = "drive-removable-media";
1732 icon_name = "drive-harddisk";
1740 * g_unix_mount_guess_name:
1741 * @mount_entry: a #GUnixMountEntry
1743 * Guesses the name of a Unix mount.
1744 * The result is a translated string.
1746 * Returns: A newly allocated string that must
1747 * be freed with g_free()
1750 g_unix_mount_guess_name (GUnixMountEntry *mount_entry)
1754 if (strcmp (mount_entry->mount_path, "/") == 0)
1755 name = g_strdup (_("Filesystem root"));
1757 name = g_filename_display_basename (mount_entry->mount_path);
1763 * g_unix_mount_guess_icon:
1764 * @mount_entry: a #GUnixMountEntry
1766 * Guesses the icon of a Unix mount.
1771 g_unix_mount_guess_icon (GUnixMountEntry *mount_entry)
1773 return g_themed_icon_new_with_default_fallbacks (type_to_icon (g_unix_mount_guess_type (mount_entry), FALSE));
1777 * g_unix_mount_point_guess_name:
1778 * @mount_point: a #GUnixMountPoint
1780 * Guesses the name of a Unix mount point.
1781 * The result is a translated string.
1783 * Returns: A newly allocated string that must
1784 * be freed with g_free()
1787 g_unix_mount_point_guess_name (GUnixMountPoint *mount_point)
1791 if (strcmp (mount_point->mount_path, "/") == 0)
1792 name = g_strdup (_("Filesystem root"));
1794 name = g_filename_display_basename (mount_point->mount_path);
1800 * g_unix_mount_point_guess_icon:
1801 * @mount_point: a #GUnixMountPoint
1803 * Guesses the icon of a Unix mount point.
1808 g_unix_mount_point_guess_icon (GUnixMountPoint *mount_point)
1810 return g_themed_icon_new_with_default_fallbacks (type_to_icon (g_unix_mount_point_guess_type (mount_point), TRUE));
1814 * g_unix_mount_guess_can_eject:
1815 * @mount_entry: a #GUnixMountEntry
1817 * Guesses whether a Unix mount can be ejected.
1819 * Returns: %TRUE if @mount_entry is deemed to be ejectable.
1822 g_unix_mount_guess_can_eject (GUnixMountEntry *mount_entry)
1824 GUnixMountType guessed_type;
1826 guessed_type = g_unix_mount_guess_type (mount_entry);
1827 if (guessed_type == G_UNIX_MOUNT_TYPE_IPOD ||
1828 guessed_type == G_UNIX_MOUNT_TYPE_CDROM)
1835 * g_unix_mount_guess_should_display:
1836 * @mount_entry: a #GUnixMountEntry
1838 * Guesses whether a Unix mount should be displayed in the UI.
1840 * Returns: %TRUE if @mount_entry is deemed to be displayable.
1843 g_unix_mount_guess_should_display (GUnixMountEntry *mount_entry)
1845 GUnixMountType guessed_type;
1847 /* Never display internal mountpoints */
1848 if (g_unix_mount_is_system_internal (mount_entry))
1851 /* Only display things that look "removable" or
1852 things in /media (which are generally user mountable) */
1853 guessed_type = g_unix_mount_guess_type (mount_entry);
1854 if (guessed_type == G_UNIX_MOUNT_TYPE_IPOD ||
1855 guessed_type == G_UNIX_MOUNT_TYPE_CDROM ||
1856 guessed_type == G_UNIX_MOUNT_TYPE_FLOPPY ||
1857 guessed_type == G_UNIX_MOUNT_TYPE_ZIP ||
1858 guessed_type == G_UNIX_MOUNT_TYPE_JAZ ||
1859 guessed_type == G_UNIX_MOUNT_TYPE_CAMERA ||
1860 guessed_type == G_UNIX_MOUNT_TYPE_MEMSTICK ||
1861 (mount_entry->mount_path != NULL &&
1862 g_str_has_prefix (mount_entry->mount_path, "/media")))
1869 * g_unix_mount_point_guess_can_eject:
1870 * @mount_point: a #GUnixMountPoint
1872 * Guesses whether a Unix mount point can be ejected.
1874 * Returns: %TRUE if @mount_point is deemed to be ejectable.
1877 g_unix_mount_point_guess_can_eject (GUnixMountPoint *mount_point)
1879 GUnixMountType guessed_type;
1881 guessed_type = g_unix_mount_point_guess_type (mount_point);
1882 if (guessed_type == G_UNIX_MOUNT_TYPE_IPOD ||
1883 guessed_type == G_UNIX_MOUNT_TYPE_CDROM)
1890 /* borrowed from gtk/gtkfilesystemunix.c in GTK+ on 02/23/2006 */
1892 _canonicalize_filename (gchar *filename)
1895 gboolean last_was_slash = FALSE;
1902 if (*p == G_DIR_SEPARATOR)
1904 if (!last_was_slash)
1905 *q++ = G_DIR_SEPARATOR;
1907 last_was_slash = TRUE;
1911 if (last_was_slash && *p == '.')
1913 if (*(p + 1) == G_DIR_SEPARATOR ||
1916 if (*(p + 1) == '\0')
1921 else if (*(p + 1) == '.' &&
1922 (*(p + 2) == G_DIR_SEPARATOR ||
1925 if (q > filename + 1)
1928 while (q > filename + 1 &&
1929 *(q - 1) != G_DIR_SEPARATOR)
1933 if (*(p + 2) == '\0')
1941 last_was_slash = FALSE;
1947 last_was_slash = FALSE;
1954 if (q > filename + 1 && *(q - 1) == G_DIR_SEPARATOR)
1961 _resolve_symlink (const char *file)
1969 f = g_strdup (file);
1971 while (g_file_test (f, G_FILE_TEST_IS_SYMLINK)) {
1972 link = g_file_read_link (f, &error);
1974 g_error_free (error);
1980 dir = g_path_get_dirname (f);
1981 f1 = g_strdup_printf ("%s/%s", dir, link);
1990 _canonicalize_filename (f);
1994 #ifdef HAVE_MNTENT_H
1996 _resolve_dev_root (void)
1998 static gboolean have_real_dev_root = FALSE;
1999 static char real_dev_root[256];
2000 struct stat statbuf;
2002 /* see if it's cached already */
2003 if (have_real_dev_root)
2006 /* otherwise we're going to find it right away.. */
2007 have_real_dev_root = TRUE;
2009 if (stat ("/dev/root", &statbuf) == 0) {
2010 if (! S_ISLNK (statbuf.st_mode)) {
2011 dev_t root_dev = statbuf.st_dev;
2015 /* see if device with similar major:minor as /dev/root is mention
2016 * in /etc/mtab (it usually is)
2018 f = fopen ("/etc/mtab", "r");
2022 while (getmntent_r (f, &ent, buf, sizeof (buf)) != NULL) {
2024 if (stat (ent.mnt_fsname, &statbuf) == 0 &&
2025 statbuf.st_dev == root_dev) {
2026 strncpy (real_dev_root, ent.mnt_fsname, sizeof (real_dev_root) - 1);
2027 real_dev_root[sizeof (real_dev_root) - 1] = '\0';
2035 /* no, that didn't work.. next we could scan /dev ... but I digress.. */
2039 resolved = _resolve_symlink ("/dev/root");
2040 if (resolved != NULL) {
2041 strncpy (real_dev_root, resolved, sizeof (real_dev_root) - 1);
2042 real_dev_root[sizeof (real_dev_root) - 1] = '\0';
2050 strcpy (real_dev_root, "/dev/root");
2053 return real_dev_root;
2057 #define __G_UNIX_MOUNTS_C__
2058 #include "gioaliasdef.c"