gunixmounts.c revision f0749cc896db4174609da7da178d079aaf758845
13ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
23ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
33781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/* GIO - GLib Input, Output and Streaming Library
43781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
53781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * Copyright (C) 2006-2007 Red Hat, Inc.
63781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
73781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * This library is free software; you can redistribute it and/or
83781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * modify it under the terms of the GNU Lesser General Public
93781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * License as published by the Free Software Foundation; either
103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * version 2 of the License, or (at your option) any later version.
113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * This library is distributed in the hope that it will be useful,
133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * but WITHOUT ANY WARRANTY; without even the implied warranty of
143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * Lesser General Public License for more details.
163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * You should have received a copy of the GNU Lesser General
183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * Public License along with this library; if not, write to the
193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * Boston, MA 02111-1307, USA.
213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * Author: Alexander Larsson <alexl@redhat.com>
233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson */
243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <config.h>
263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/types.h>
283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/stat.h>
293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/wait.h>
303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifndef HAVE_SYSCTLBYNAME
313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_PARAM_H
323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/param.h>
333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_POLL_H
353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/poll.h>
363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_POLL_H
393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <poll.h>
403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <stdio.h>
423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <unistd.h>
433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/time.h>
443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <errno.h>
453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <string.h>
463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <signal.h>
473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include "gunixmounts.h"
493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include "gfile.h"
503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include "gfilemonitor.h"
513ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen#include "glibintl.h"
523ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen#include "gthemedicon.h"
533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
547f3280230bc9448a5750fc17a6eabef691ba25f4Alexander Larsson#include "gioalias.h"
557f3280230bc9448a5750fc17a6eabef691ba25f4Alexander Larsson
563ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenstatic const char *_resolve_dev_root (void);
573ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
585247f12f3649726471080440de0d37b78c1cec33Andrew Walton/**
595247f12f3649726471080440de0d37b78c1cec33Andrew Walton * SECTION:gunixmounts
600debd52858ffb4f468e55cd2f3c7e4dec5455b94Matthias Clasen * @include: gio/gunixmounts.h
615247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @short_description: Unix Mounts
625247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
635247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Routines for managing mounted UNIX mount points and paths.
645247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
655247f12f3649726471080440de0d37b78c1cec33Andrew Walton **/
665247f12f3649726471080440de0d37b78c1cec33Andrew Walton
67f5063650794c987868830241a630993e624eabd9Alexander Larsson/*
683ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * GUnixMountType:
693ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_UNKNOWN: Unknown UNIX mount type.
703ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_FLOPPY: Floppy disk UNIX mount type.
713ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_CDROM: CDROM UNIX mount type.
723ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_NFS: Network File System (NFS) UNIX mount type.
733ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_ZIP: ZIP UNIX mount type.
743ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_JAZ: JAZZ UNIX mount type.
753ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_MEMSTICK: Memory Stick UNIX mount type.
763ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_CF: Compact Flash UNIX mount type.
773ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_SM: Smart Media UNIX mount type.
783ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_SDMMC: SD/MMC UNIX mount type.
793ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_IPOD: iPod UNIX mount type.
803ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_CAMERA: Digital camera UNIX mount type.
813ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_HD: Hard drive UNIX mount type.
823ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen *
833ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * Types of UNIX mounts.
843ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen **/
853ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthentypedef enum {
863ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  G_UNIX_MOUNT_TYPE_UNKNOWN,
873ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  G_UNIX_MOUNT_TYPE_FLOPPY,
883ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  G_UNIX_MOUNT_TYPE_CDROM,
893ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  G_UNIX_MOUNT_TYPE_NFS,
903ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  G_UNIX_MOUNT_TYPE_ZIP,
913ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  G_UNIX_MOUNT_TYPE_JAZ,
923ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  G_UNIX_MOUNT_TYPE_MEMSTICK,
933ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  G_UNIX_MOUNT_TYPE_CF,
943ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  G_UNIX_MOUNT_TYPE_SM,
953ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  G_UNIX_MOUNT_TYPE_SDMMC,
963ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  G_UNIX_MOUNT_TYPE_IPOD,
973ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  G_UNIX_MOUNT_TYPE_CAMERA,
983ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  G_UNIX_MOUNT_TYPE_HD
993ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen} GUnixMountType;
1003ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
1013ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenstruct _GUnixMountEntry {
1023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char *mount_path;
1033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char *device_path;
1043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char *filesystem_type;
1053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  gboolean is_read_only;
1063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  gboolean is_system_internal;
1073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson};
1083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1093781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstruct _GUnixMountPoint {
1103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char *mount_path;
1113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char *device_path;
1123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char *filesystem_type;
1133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  gboolean is_read_only;
1143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  gboolean is_user_mountable;
1153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  gboolean is_loopback;
1163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson};
1173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1183781343738de4abddf56982325a77bd70a98cd26Alexander Larssonenum {
1193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  MOUNTS_CHANGED,
1203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  MOUNTPOINTS_CHANGED,
1213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  LAST_SIGNAL
1223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson};
1233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1243781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic guint signals[LAST_SIGNAL];
1253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1263781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstruct _GUnixMountMonitor {
1273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GObject parent;
1283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GFileMonitor *fstab_monitor;
1303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GFileMonitor *mtab_monitor;
1313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson};
1323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1333781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstruct _GUnixMountMonitorClass {
1343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GObjectClass parent_class;
1353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson};
1363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1373781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GUnixMountMonitor *the_mount_monitor = NULL;
1383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1393781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList *_g_get_unix_mounts (void);
1403781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList *_g_get_unix_mount_points (void);
1413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1423781343738de4abddf56982325a77bd70a98cd26Alexander LarssonG_DEFINE_TYPE (GUnixMountMonitor, g_unix_mount_monitor, G_TYPE_OBJECT);
1433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#define MOUNT_POLL_INTERVAL 4000
1453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_MNTTAB_H
1473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#define MNTOPT_RO	"ro"
1483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
1493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_MNTENT_H
1513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <mntent.h>
1523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined (HAVE_SYS_MNTTAB_H)
1533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/mnttab.h>
1543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
1553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_VFSTAB_H
1573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/vfstab.h>
1583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
1593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#if defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
1613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/mntctl.h>
1623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/vfs.h>
1633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/vmount.h>
1643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <fshelp.h>
1653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
1663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#if defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
1683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/ucred.h>
1693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/mount.h>
1703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <fstab.h>
1713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_SYSCTL_H
1723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/sysctl.h>
1733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
1743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
1753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifndef HAVE_SETMNTENT
1773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#define setmntent(f,m) fopen(f,m)
1783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
1793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifndef HAVE_ENDMNTENT
1803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#define endmntent(f) fclose(f)
1813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
1823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1833781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic gboolean
1843781343738de4abddf56982325a77bd70a98cd26Alexander Larssonis_in (const char *value, const char *set[])
1853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
1863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  int i;
1873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  for (i = 0; set[i] != NULL; i++)
1883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
1893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (strcmp (set[i], value) == 0)
1903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	return TRUE;
1913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
1923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return FALSE;
1933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
1943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1953ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen/**
1963ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * g_unix_is_mount_path_system_internal:
197f5d2feddf6311492ea9f7124d73d2997db0ca123Matthias Clasen * @mount_path: a mount path, e.g. <filename>/media/disk</filename>
198f5d2feddf6311492ea9f7124d73d2997db0ca123Matthias Clasen *    or <filename>/usr</filename>
1993ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen *
2003ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * Determines if @mount_path is considered an implementation of the
2013ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * OS. This is primarily used for hiding mountable and mounted volumes
2023ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * that only are used in the OS and has little to no relevance to the
2033ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * casual user.
2043ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen *
205f5d2feddf6311492ea9f7124d73d2997db0ca123Matthias Clasen * Returns: %TRUE if @mount_path is considered an implementation detail
206f5d2feddf6311492ea9f7124d73d2997db0ca123Matthias Clasen *     of the OS.
2073ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen **/
2083ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthengboolean
2093ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_is_mount_path_system_internal (const char *mount_path)
2103ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{
2113ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  const char *ignore_mountpoints[] = {
2123ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    /* Includes all FHS 2.3 toplevel dirs and other specilized
2133ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen     * directories that we want to hide from the user.
2143ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen     */
2153ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/",              /* we already have "Filesystem root" in Nautilus */
2163ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/bin",
2173ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/boot",
2183ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/dev",
2193ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/etc",
2203ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/home",
2213ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/lib",
2223ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/lib64",
2233ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/media",
2243ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/mnt",
2253ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/opt",
2263ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/root",
2273ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/sbin",
2283ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/srv",
2293ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/tmp",
2303ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/usr",
231246e2e71a91f028e0657d8f0dca489928b4f2750Alexander Larsson    "/usr/local",
2323ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/var",
2333ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/var/log/audit", /* https://bugzilla.redhat.com/show_bug.cgi?id=333041 */
2343ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/var/tmp",       /* https://bugzilla.redhat.com/show_bug.cgi?id=335241 */
2353ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/proc",
2363ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/sbin",
2373ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    "/net",
2383ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    NULL
2393ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  };
2403ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
2413ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  if (is_in (mount_path, ignore_mountpoints))
2423ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    return TRUE;
2433ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
2443ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  if (g_str_has_prefix (mount_path, "/dev") ||
2453ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      g_str_has_prefix (mount_path, "/proc") ||
2463ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      g_str_has_prefix (mount_path, "/sys"))
2473ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    return TRUE;
2483ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
2493ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  if (strstr (mount_path, "/.gvfs") != NULL)
2503ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    return TRUE;
2513ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
2523ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  return FALSE;
2533ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen}
2543ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
2553781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic gboolean
2563781343738de4abddf56982325a77bd70a98cd26Alexander Larssonguess_system_internal (const char *mountpoint,
2573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		       const char *fs,
2583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		       const char *device)
2593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
2603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  const char *ignore_fs[] = {
2613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "auto",
2623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "autofs",
2633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "devfs",
2643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "devpts",
2653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "kernfs",
2663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "linprocfs",
2673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "proc",
2683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "procfs",
2693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "ptyfs",
2703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "rootfs",
2713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "selinuxfs",
2723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "sysfs",
2733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "tmpfs",
2743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "usbfs",
2753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "nfsd",
2767fe31089ff6d2885197fa1d0d9e340eabc779be6Frederic Crozat    "rpc_pipefs",
2773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    NULL
2783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  };
2793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  const char *ignore_devices[] = {
2803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "none",
2813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "sunrpc",
2823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "devpts",
2833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "nfsd",
2843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "/dev/loop",
2853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    "/dev/vn",
2863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    NULL
2873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  };
2883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
2893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (is_in (fs, ignore_fs))
2903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return TRUE;
2913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
2923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (is_in (device, ignore_devices))
2933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return TRUE;
2943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
2953ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  if (g_unix_is_mount_path_system_internal (mountpoint))
2963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return TRUE;
2973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
2983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return FALSE;
2993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
3003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_MNTENT_H
3023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3033781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char *
3043781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mtab_read_file (void)
3053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
3063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef _PATH_MOUNTED
3073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson# ifdef __linux__
3083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return "/proc/mounts";
3093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson# else
3103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return _PATH_MOUNTED;
3113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson# endif
3123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#else
3133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return "/etc/mtab";
3143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
3153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
3163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3173781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char *
3183781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mtab_monitor_file (void)
3193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
3203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef _PATH_MOUNTED
3213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return _PATH_MOUNTED;
3223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#else
3233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return "/etc/mtab";
3243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
3253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
3263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3273781343738de4abddf56982325a77bd70a98cd26Alexander LarssonG_LOCK_DEFINE_STATIC(getmntent);
3283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3293781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList *
3303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mounts ()
3313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
3323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  struct mntent *mntent;
3333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  FILE *file;
3343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char *read_file;
3353ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  GUnixMountEntry *mount_entry;
3363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GHashTable *mounts_hash;
3373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GList *return_list;
3383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  read_file = get_mtab_read_file ();
3403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  file = setmntent (read_file, "r");
3423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (file == NULL)
3433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return NULL;
3443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return_list = NULL;
3463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  mounts_hash = g_hash_table_new (g_str_hash, g_str_equal);
3483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  G_LOCK (getmntent);
3503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  while ((mntent = getmntent (file)) != NULL)
3513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
3523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      /* ignore any mnt_fsname that is repeated and begins with a '/'
3533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson       *
3543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson       * We do this to avoid being fooled by --bind mounts, since
3553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson       * these have the same device as the location they bind to.
356f0749cc896db4174609da7da178d079aaf758845Murray Cumming       * Its not an ideal solution to the problem, but it's likely that
3573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson       * the most important mountpoint is first and the --bind ones after
3583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson       * that aren't as important. So it should work.
3593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson       *
3603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson       * The '/' is to handle procfs, tmpfs and other no device mounts.
3613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson       */
3623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (mntent->mnt_fsname != NULL &&
3633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  mntent->mnt_fsname[0] == '/' &&
3643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_hash_table_lookup (mounts_hash, mntent->mnt_fsname))
3653ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        continue;
3663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3673ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      mount_entry = g_new0 (GUnixMountEntry, 1);
3683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->mount_path = g_strdup (mntent->mnt_dir);
3693ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      if (strcmp (mntent->mnt_fsname, "/dev/root") == 0)
3703ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        mount_entry->device_path = g_strdup (_resolve_dev_root ());
3713ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      else
3723ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        mount_entry->device_path = g_strdup (mntent->mnt_fsname);
3733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->filesystem_type = g_strdup (mntent->mnt_type);
3743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#if defined (HAVE_HASMNTOPT)
3763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (hasmntopt (mntent, MNTOPT_RO) != NULL)
3773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	mount_entry->is_read_only = TRUE;
3783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
3793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->is_system_internal =
3813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	guess_system_internal (mount_entry->mount_path,
3823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			       mount_entry->filesystem_type,
3833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			       mount_entry->device_path);
3843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      g_hash_table_insert (mounts_hash,
3863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			   mount_entry->device_path,
3873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			   mount_entry->device_path);
3883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      return_list = g_list_prepend (return_list, mount_entry);
3903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
3913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_hash_table_destroy (mounts_hash);
3923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  endmntent (file);
3943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  G_UNLOCK (getmntent);
3963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
3973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return g_list_reverse (return_list);
3983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
3993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined (HAVE_SYS_MNTTAB_H)
4013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4023781343738de4abddf56982325a77bd70a98cd26Alexander LarssonG_LOCK_DEFINE_STATIC(getmntent);
4033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4043781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char *
4053781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mtab_read_file (void)
4063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
4073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef _PATH_MOUNTED
4083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return _PATH_MOUNTED;
4093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#else
4103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return "/etc/mnttab";
4113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
4123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
4133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4143781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char *
4153781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mtab_monitor_file (void)
4163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
4173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return get_mtab_read_file ();
4183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
4193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4203781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList *
4213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mounts (void)
4223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
4233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  struct mnttab mntent;
4243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  FILE *file;
4253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char *read_file;
4263ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  GUnixMountEntry *mount_entry;
4273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GList *return_list;
4283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  read_file = get_mtab_read_file ();
4303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  file = setmntent (read_file, "r");
4323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (file == NULL)
4333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return NULL;
4343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return_list = NULL;
4363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  G_LOCK (getmntent);
4383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  while (! getmntent (file, &mntent))
4393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
4403ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      mount_entry = g_new0 (GUnixMountEntry, 1);
4413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->mount_path = g_strdup (mntent.mnt_mountp);
4433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->device_path = g_strdup (mntent.mnt_special);
4443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype);
4453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#if defined (HAVE_HASMNTOPT)
4473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (hasmntopt (&mntent, MNTOPT_RO) != NULL)
4483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	mount_entry->is_read_only = TRUE;
4493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
4503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->is_system_internal =
4523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	guess_system_internal (mount_entry->mount_path,
4533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			       mount_entry->filesystem_type,
4543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			       mount_entry->device_path);
4553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      return_list = g_list_prepend (return_list, mount_entry);
4573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
4583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  endmntent (file);
4603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  G_UNLOCK (getmntent);
4623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return g_list_reverse (return_list);
4643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
4653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
4673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4683781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char *
4693781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mtab_monitor_file (void)
4703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
4713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return NULL;
4723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
4733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4743781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList *
4753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mounts (void)
4763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
4773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  struct vfs_ent *fs_info;
4783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  struct vmount *vmount_info;
4793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  int vmount_number;
4803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  unsigned int vmount_size;
4813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  int current;
4823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GList *return_list;
4833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (mntctl (MCTL_QUERY, sizeof (vmount_size), &vmount_size) != 0)
4853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
4863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      g_warning ("Unable to know the number of mounted volumes\n");
4873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      return NULL;
4893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
4903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  vmount_info = (struct vmount*)g_malloc (vmount_size);
4923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  vmount_number = mntctl (MCTL_QUERY, vmount_size, vmount_info);
4943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (vmount_info->vmt_revision != VMT_REVISION)
4963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    g_warning ("Bad vmount structure revision number, want %d, got %d\n", VMT_REVISION, vmount_info->vmt_revision);
4973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
4983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (vmount_number < 0)
4993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
5003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      g_warning ("Unable to recover mounted volumes information\n");
5013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      g_free (vmount_info);
5033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      return NULL;
5043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
5053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return_list = NULL;
5073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  while (vmount_number > 0)
5083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
5093ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      mount_entry = g_new0 (GUnixMountEntry, 1);
5103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->device_path = g_strdup (vmt2dataptr (vmount_info, VMT_OBJECT));
5123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->mount_path = g_strdup (vmt2dataptr (vmount_info, VMT_STUB));
5133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      /* is_removable = (vmount_info->vmt_flags & MNT_REMOVABLE) ? 1 : 0; */
5143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->is_read_only = (vmount_info->vmt_flags & MNT_READONLY) ? 1 : 0;
5153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      fs_info = getvfsbytype (vmount_info->vmt_gfstype);
5173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (fs_info == NULL)
5193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	mount_entry->filesystem_type = g_strdup ("unknown");
5203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else
5213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	mount_entry->filesystem_type = g_strdup (fs_info->vfsent_name);
5223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->is_system_internal =
5243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	guess_system_internal (mount_entry->mount_path,
5253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			       mount_entry->filesystem_type,
5263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			       mount_entry->device_path);
5273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      return_list = g_list_prepend (return_list, mount_entry);
5293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      vmount_info = (struct vmount *)( (char*)vmount_info
5313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson				       + vmount_info->vmt_length);
5323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      vmount_number--;
5333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
5343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_free (vmount_info);
5373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return g_list_reverse (return_list);
5393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
5403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
5423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5433781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char *
5443781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mtab_monitor_file (void)
5453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
5463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return NULL;
5473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
5483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5493781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList *
5503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mounts (void)
5513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
5523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  struct statfs *mntent = NULL;
5533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  int num_mounts, i;
5543ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  GUnixMountEntry *mount_entry;
5553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GList *return_list;
5563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  /* Pass MNT_NOWAIT to avoid blocking trying to update NFS mounts. */
5583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if ((num_mounts = getmntinfo (&mntent, MNT_NOWAIT)) == 0)
5593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return NULL;
5603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return_list = NULL;
5623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  for (i = 0; i < num_mounts; i++)
5643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
5653ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      mount_entry = g_new0 (GUnixMountEntry, 1);
5663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->mount_path = g_strdup (mntent[i].f_mntonname);
5683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->device_path = g_strdup (mntent[i].f_mntfromname);
5693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->filesystem_type = g_strdup (mntent[i].f_fstypename);
5703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (mntent[i].f_flags & MNT_RDONLY)
5713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	mount_entry->is_read_only = TRUE;
5723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->is_system_internal =
5743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	guess_system_internal (mount_entry->mount_path,
5753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			       mount_entry->filesystem_type,
5763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			       mount_entry->device_path);
5773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      return_list = g_list_prepend (return_list, mount_entry);
5793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
5803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return g_list_reverse (return_list);
5823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
5833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#else
5843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#error No _g_get_unix_mounts() implementation for system
5853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
5863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/* _g_get_unix_mount_points():
5883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * read the fstab.
5893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * don't return swap and ignore mounts.
5903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson */
5913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
5923781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char *
5933781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_fstab_file (void)
5943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
5953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#if defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
5963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  /* AIX */
5973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return "/etc/filesystems";
5983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(_PATH_MNTTAB)
5993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return _PATH_MNTTAB;
6003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(VFSTAB)
6013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return VFSTAB;
6023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#else
6033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return "/etc/fstab";
6043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
6053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
6063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_MNTENT_H
6083781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList *
6093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mount_points (void)
6103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
6113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  struct mntent *mntent;
6123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  FILE *file;
6133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char *read_file;
6143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GUnixMountPoint *mount_entry;
6153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GList *return_list;
6163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  read_file = get_fstab_file ();
6183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  file = setmntent (read_file, "r");
6203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (file == NULL)
6213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return NULL;
6223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return_list = NULL;
6243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  G_LOCK (getmntent);
6263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  while ((mntent = getmntent (file)) != NULL)
6273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
6283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if ((strcmp (mntent->mnt_dir, "ignore") == 0) ||
6293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  (strcmp (mntent->mnt_dir, "swap") == 0))
6303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	continue;
6313ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
6323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry = g_new0 (GUnixMountPoint, 1);
6333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->mount_path = g_strdup (mntent->mnt_dir);
6343ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      if (strcmp (mntent->mnt_fsname, "/dev/root") == 0)
6353ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        mount_entry->device_path = g_strdup (_resolve_dev_root ());
6363ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      else
6373ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        mount_entry->device_path = g_strdup (mntent->mnt_fsname);
6383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->filesystem_type = g_strdup (mntent->mnt_type);
6393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_HASMNTOPT
6413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (hasmntopt (mntent, MNTOPT_RO) != NULL)
6423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	mount_entry->is_read_only = TRUE;
6433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (hasmntopt (mntent, "loop") != NULL)
6453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	mount_entry->is_loopback = TRUE;
6463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
6483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if ((mntent->mnt_type != NULL && strcmp ("supermount", mntent->mnt_type) == 0)
6503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_HASMNTOPT
6513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  || (hasmntopt (mntent, "user") != NULL
6523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	      && hasmntopt (mntent, "user") != hasmntopt (mntent, "user_xattr"))
6533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  || hasmntopt (mntent, "pamconsole") != NULL
6543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  || hasmntopt (mntent, "users") != NULL
6553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  || hasmntopt (mntent, "owner") != NULL
6563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
6573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  )
6583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	mount_entry->is_user_mountable = TRUE;
6593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      return_list = g_list_prepend (return_list, mount_entry);
6613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
6623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  endmntent (file);
6643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  G_UNLOCK (getmntent);
6653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return g_list_reverse (return_list);
6673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
6683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined (HAVE_SYS_MNTTAB_H)
6703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6713781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList *
6723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mount_points (void)
6733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
6743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  struct mnttab mntent;
6753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  FILE *file;
6763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char *read_file;
6773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GUnixMountPoint *mount_entry;
6783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GList *return_list;
6793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  read_file = get_fstab_file ();
6813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  file = setmntent (read_file, "r");
6833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (file == NULL)
6843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return NULL;
6853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return_list = NULL;
6873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  G_LOCK (getmntent);
6893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  while (! getmntent (file, &mntent))
6903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
6913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if ((strcmp (mntent.mnt_mountp, "ignore") == 0) ||
6923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  (strcmp (mntent.mnt_mountp, "swap") == 0))
6933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	continue;
6943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry = g_new0 (GUnixMountPoint, 1);
6963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
6973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->mount_path = g_strdup (mntent.mnt_mountp);
6983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->device_path = g_strdup (mntent.mnt_special);
6993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype);
7003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_HASMNTOPT
7023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (hasmntopt (&mntent, MNTOPT_RO) != NULL)
7033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	mount_entry->is_read_only = TRUE;
7043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (hasmntopt (&mntent, "lofs") != NULL)
7063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	mount_entry->is_loopback = TRUE;
7073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
7083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if ((mntent.mnt_fstype != NULL)
7103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_HASMNTOPT
7113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  || (hasmntopt (&mntent, "user") != NULL
7123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	      && hasmntopt (&mntent, "user") != hasmntopt (&mntent, "user_xattr"))
7133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  || hasmntopt (&mntent, "pamconsole") != NULL
7143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  || hasmntopt (&mntent, "users") != NULL
7153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  || hasmntopt (&mntent, "owner") != NULL
7163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
7173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  )
7183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	mount_entry->is_user_mountable = TRUE;
7193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      return_list = g_list_prepend (return_list, mount_entry);
7223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
7233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  endmntent (file);
7253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  G_UNLOCK (getmntent);
7263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return g_list_reverse (return_list);
7283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
7293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H)
7303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/* functions to parse /etc/filesystems on aix */
7323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/* read character, ignoring comments (begin with '*', end with '\n' */
7343781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic int
7353781343738de4abddf56982325a77bd70a98cd26Alexander Larssonaix_fs_getc (FILE *fd)
7363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
7373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  int c;
7383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  while ((c = getc (fd)) == '*')
7403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
7413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      while (((c = getc (fd)) != '\n') && (c != EOF))
7423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	;
7433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
7443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
7453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/* eat all continuous spaces in a file */
7473781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic int
7483781343738de4abddf56982325a77bd70a98cd26Alexander Larssonaix_fs_ignorespace (FILE *fd)
7493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
7503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  int c;
7513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  while ((c = aix_fs_getc (fd)) != EOF)
7533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
7543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (!g_ascii_isspace (c))
7553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	{
7563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  ungetc (c,fd);
7573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  return c;
7583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	}
7593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
7603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return EOF;
7623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
7633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/* read one word from file */
7653781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic int
766a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasenaix_fs_getword (FILE *fd,
767a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen                char *word)
7683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
7693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  int c;
7703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  aix_fs_ignorespace (fd);
7723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  while (((c = aix_fs_getc (fd)) != EOF) && !g_ascii_isspace (c))
7743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
7753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (c == '"')
7763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	{
7773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  while (((c = aix_fs_getc (fd)) != EOF) && (c != '"'))
7783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	    *word++ = c;
7793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  else
7803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	    *word++ = c;
7813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	}
7823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
7833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  *word = 0;
7843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return c;
7863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
7873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7883781343738de4abddf56982325a77bd70a98cd26Alexander Larssontypedef struct {
7893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char mnt_mount[PATH_MAX];
7903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char mnt_special[PATH_MAX];
7913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char mnt_fstype[16];
7923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char mnt_options[128];
7933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} AixMountTableEntry;
7943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
7953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/* read mount points properties */
7963781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic int
797a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasenaix_fs_get (FILE               *fd,
798a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen            AixMountTableEntry *prop)
7993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
8003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  static char word[PATH_MAX] = { 0 };
8013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char value[PATH_MAX];
8023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  /* read stanza */
8043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (word[0] == 0)
8053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
8063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (aix_fs_getword (fd, word) == EOF)
8073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	return EOF;
8083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
8093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  word[strlen(word) - 1] = 0;
8113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  strcpy (prop->mnt_mount, word);
8123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  /* read attributes and value */
8143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  while (aix_fs_getword (fd, word) != EOF)
8163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
8173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      /* test if is attribute or new stanza */
8183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (word[strlen(word) - 1] == ':')
8193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	return 0;
8203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      /* read "=" */
8223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      aix_fs_getword (fd, value);
8233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      /* read value */
8253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      aix_fs_getword (fd, value);
8263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (strcmp (word, "dev") == 0)
8283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	strcpy (prop->mnt_special, value);
8293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (strcmp (word, "vfs") == 0)
8303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	strcpy (prop->mnt_fstype, value);
8313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (strcmp (word, "options") == 0)
8323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	strcpy(prop->mnt_options, value);
8333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
8343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return 0;
8363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
8373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8383781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList *
8393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mount_points (void)
8403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
8413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  struct mntent *mntent;
8423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  FILE *file;
8433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char *read_file;
8443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GUnixMountPoint *mount_entry;
8453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  AixMountTableEntry mntent;
8463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GList *return_list;
8473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  read_file = get_fstab_file ();
8493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  file = setmntent (read_file, "r");
8513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (file == NULL)
8523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return NULL;
8533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return_list = NULL;
8553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  while (!aix_fs_get (file, &mntent))
8573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
8583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (strcmp ("cdrfs", mntent.mnt_fstype) == 0)
8593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	{
8603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  mount_entry = g_new0 (GUnixMountPoint, 1);
8613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  mount_entry->mount_path = g_strdup (mntent.mnt_mount);
8643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  mount_entry->device_path = g_strdup (mntent.mnt_special);
8653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype);
8663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  mount_entry->is_read_only = TRUE;
8673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  mount_entry->is_user_mountable = TRUE;
8683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  return_list = g_list_prepend (return_list, mount_entry);
8703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	}
8713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
8723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  endmntent (file);
8743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return g_list_reverse (return_list);
8763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
8773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H)
8793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8803781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList *
8813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mount_points (void)
8823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
8833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  struct fstab *fstab = NULL;
8843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GUnixMountPoint *mount_entry;
8853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GList *return_list;
8863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_SYSCTL_H
8873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  int usermnt = 0;
8883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  size_t len = sizeof(usermnt);
8893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  struct stat sb;
8903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
8913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (!setfsent ())
8933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return NULL;
8943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return_list = NULL;
8963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
8973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_SYSCTL_H
8983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#if defined(HAVE_SYSCTLBYNAME)
8993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  sysctlbyname ("vfs.usermount", &usermnt, &len, NULL, 0);
9003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(CTL_VFS) && defined(VFS_USERMOUNT)
9013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  {
9023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    int mib[2];
9033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    mib[0] = CTL_VFS;
9053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    mib[1] = VFS_USERMOUNT;
9063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    sysctl (mib, 2, &usermnt, &len, NULL, 0);
9073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  }
9083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(CTL_KERN) && defined(KERN_USERMOUNT)
9093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  {
9103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    int mib[2];
9113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    mib[0] = CTL_KERN;
9133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    mib[1] = KERN_USERMOUNT;
9143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    sysctl (mib, 2, &usermnt, &len, NULL, 0);
9153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  }
9163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
9173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
9183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  while ((fstab = getfsent ()) != NULL)
9203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
9213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (strcmp (fstab->fs_vfstype, "swap") == 0)
9223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	continue;
9233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry = g_new0 (GUnixMountPoint, 1);
9253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->mount_path = g_strdup (fstab->fs_file);
9273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->device_path = g_strdup (fstab->fs_spec);
9283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry->filesystem_type = g_strdup (fstab->fs_vfstype);
9293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (strcmp (fstab->fs_type, "ro") == 0)
9313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	mount_entry->is_read_only = TRUE;
9323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_SYSCTL_H
9343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (usermnt != 0)
9353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	{
9363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  uid_t uid = getuid ();
9373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  if (stat (fstab->fs_file, &sb) == 0)
9383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	    {
9393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	      if (uid == 0 || sb.st_uid == uid)
9403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		mount_entry->is_user_mountable = TRUE;
9413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	    }
9423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	}
9433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
9443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      return_list = g_list_prepend (return_list, mount_entry);
9463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
9473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  endfsent ();
9493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return g_list_reverse (return_list);
9513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
9523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#else
9533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#error No g_get_mount_table() implementation for system
9543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif
9553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9563781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic guint64
9573781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mounts_timestamp (void)
9583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
9593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  const char *monitor_file;
9603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  struct stat buf;
9613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  monitor_file = get_mtab_monitor_file ();
9633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (monitor_file)
9643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
9653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (stat (monitor_file, &buf) == 0)
9663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	return (guint64)buf.st_mtime;
9673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
9683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return 0;
9693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
9703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9713781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic guint64
9723781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mount_points_timestamp (void)
9733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
9743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  const char *monitor_file;
9753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  struct stat buf;
9763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  monitor_file = get_fstab_file ();
9783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (monitor_file)
9793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
9803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (stat (monitor_file, &buf) == 0)
9813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	return (guint64)buf.st_mtime;
9823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
9833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return 0;
9843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
9853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
9863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
987feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Clasen * g_unix_mounts_get:
9883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @time_read: guint64 to contain a timestamp.
9893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
990442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * Gets a #GList of strings containing the unix mounts.
991442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * If @time_read is set, it will be filled with the mount
992442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * timestamp, allowing for checking if the mounts have changed
993442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * with g_unix_mounts_changed_since().
9945247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
9955247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a #GList of the UNIX mounts.
9963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
9973781343738de4abddf56982325a77bd70a98cd26Alexander LarssonGList *
998feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Claseng_unix_mounts_get (guint64 *time_read)
9993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
10003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (time_read)
10013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    *time_read = get_mounts_timestamp ();
10023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
10033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return _g_get_unix_mounts ();
10043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
10053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
10063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
1007feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Clasen * g_unix_mount_at:
10085247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_path: path for a possible unix mount.
10093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @time_read: guint64 to contain a timestamp.
10103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
10113ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * Gets a #GUnixMountEntry for a given mount path. If @time_read
10125247f12f3649726471080440de0d37b78c1cec33Andrew Walton * is set, it will be filled with a unix timestamp for checking
10135247f12f3649726471080440de0d37b78c1cec33Andrew Walton * if the mounts have changed since with g_unix_mounts_changed_since().
10145247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
10155247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a #GUnixMount.
10163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
10173ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid ZeuthenGUnixMountEntry *
1018feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Claseng_unix_mount_at (const char *mount_path,
1019feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Clasen		 guint64    *time_read)
10203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
10213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GList *mounts, *l;
10223ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  GUnixMountEntry *mount_entry, *found;
10233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1024feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Clasen  mounts = g_unix_mounts_get (time_read);
10253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
10263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  found = NULL;
10273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  for (l = mounts; l != NULL; l = l->next)
10283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
10293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      mount_entry = l->data;
10303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
10313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (strcmp (mount_path, mount_entry->mount_path) == 0)
10323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	found = mount_entry;
10333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else
10343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	g_unix_mount_free (mount_entry);
10353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
10363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
10373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_list_free (mounts);
10383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
10393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return found;
10403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
10413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
10423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
1043feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Clasen * g_unix_mount_points_get:
10443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @time_read: guint64 to contain a timestamp.
10453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
10465247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets a #GList of strings containing the unix mount points.
10475247f12f3649726471080440de0d37b78c1cec33Andrew Walton * If @time_read is set, it will be filled with the mount timestamp,
10485247f12f3649726471080440de0d37b78c1cec33Andrew Walton * allowing for checking if the mounts have changed with
10495247f12f3649726471080440de0d37b78c1cec33Andrew Walton * g_unix_mounts_points_changed_since().
10505247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
1051442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * Returns: a #GList of the UNIX mountpoints.
10523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
10533781343738de4abddf56982325a77bd70a98cd26Alexander LarssonGList *
1054feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Claseng_unix_mount_points_get (guint64 *time_read)
10553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
10563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (time_read)
10573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    *time_read = get_mount_points_timestamp ();
10583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
10593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return _g_get_unix_mount_points ();
10603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
10613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
10623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
10635247f12f3649726471080440de0d37b78c1cec33Andrew Walton * g_unix_mounts_changed_since:
10643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @time: guint64 to contain a timestamp.
10653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
10665247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if the unix mounts have changed since a given unix time.
10675247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
1068442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * Returns: %TRUE if the mounts have changed since @time.
10693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
10703781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean
10713781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mounts_changed_since (guint64 time)
10723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
10733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return get_mounts_timestamp () != time;
10743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
10753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
10763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
10775247f12f3649726471080440de0d37b78c1cec33Andrew Walton * g_unix_mount_points_changed_since:
10783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @time: guint64 to contain a timestamp.
10793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
10805247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if the unix mount points have changed since a given unix time.
10815247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
1082442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * Returns: %TRUE if the mount points have changed since @time.
10833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
10843781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean
10853781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_points_changed_since (guint64 time)
10863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
10873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return get_mount_points_timestamp () != time;
10883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
10893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
10903781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic void
10913781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_monitor_finalize (GObject *object)
10923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
10933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GUnixMountMonitor *monitor;
10943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
10953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  monitor = G_UNIX_MOUNT_MONITOR (object);
10963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
10973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (monitor->fstab_monitor)
10983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
10993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      g_file_monitor_cancel (monitor->fstab_monitor);
11003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      g_object_unref (monitor->fstab_monitor);
11013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
11023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (monitor->mtab_monitor)
11043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
11053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      g_file_monitor_cancel (monitor->mtab_monitor);
11063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      g_object_unref (monitor->mtab_monitor);
11073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
11083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  the_mount_monitor = NULL;
11103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (G_OBJECT_CLASS (g_unix_mount_monitor_parent_class)->finalize)
11123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    (*G_OBJECT_CLASS (g_unix_mount_monitor_parent_class)->finalize) (object);
11133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
11143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11163781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic void
11173781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_monitor_class_init (GUnixMountMonitorClass *klass)
11183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
11193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
11203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  gobject_class->finalize = g_unix_mount_monitor_finalize;
11225247f12f3649726471080440de0d37b78c1cec33Andrew Walton  /**
11235247f12f3649726471080440de0d37b78c1cec33Andrew Walton   * GUnixMountMonitor::mounts-changed:
11245247f12f3649726471080440de0d37b78c1cec33Andrew Walton   *
11255247f12f3649726471080440de0d37b78c1cec33Andrew Walton   * Emitted when the unix mounts have changed.
11265247f12f3649726471080440de0d37b78c1cec33Andrew Walton   **/
11273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  signals[MOUNTS_CHANGED] =
11283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    g_signal_new ("mounts_changed",
11293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  G_TYPE_FROM_CLASS (klass),
11303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  G_SIGNAL_RUN_LAST,
11313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  0,
11323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  NULL, NULL,
11333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  g_cclosure_marshal_VOID__VOID,
11343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  G_TYPE_NONE, 0);
11355247f12f3649726471080440de0d37b78c1cec33Andrew Walton  /**
11365247f12f3649726471080440de0d37b78c1cec33Andrew Walton   * GUnixMountMonitor::mountpoints-changed:
11375247f12f3649726471080440de0d37b78c1cec33Andrew Walton   *
11385247f12f3649726471080440de0d37b78c1cec33Andrew Walton   * Emitted when the unix mount points have changed.
11395247f12f3649726471080440de0d37b78c1cec33Andrew Walton   **/
11403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  signals[MOUNTPOINTS_CHANGED] =
11413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    g_signal_new ("mountpoints_changed",
11423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  G_TYPE_FROM_CLASS (klass),
11433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  G_SIGNAL_RUN_LAST,
11443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  0,
11453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  NULL, NULL,
11463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  g_cclosure_marshal_VOID__VOID,
11473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  G_TYPE_NONE, 0);
11483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
11493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11503781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic void
1151a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasenfstab_file_changed (GFileMonitor      *monitor,
1152a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen		    GFile             *file,
1153a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen		    GFile             *other_file,
1154a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen		    GFileMonitorEvent  event_type,
1155a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen		    gpointer           user_data)
11563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
11573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GUnixMountMonitor *mount_monitor;
11583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (event_type != G_FILE_MONITOR_EVENT_CHANGED &&
11603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      event_type != G_FILE_MONITOR_EVENT_CREATED &&
11613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      event_type != G_FILE_MONITOR_EVENT_DELETED)
11623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return;
11633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  mount_monitor = user_data;
11653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_signal_emit (mount_monitor, signals[MOUNTPOINTS_CHANGED], 0);
11663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
11673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11683781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic void
1169a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasenmtab_file_changed (GFileMonitor      *monitor,
1170a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen		   GFile             *file,
1171a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen		   GFile             *other_file,
1172a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen		   GFileMonitorEvent  event_type,
1173a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen		   gpointer           user_data)
11743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
11753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GUnixMountMonitor *mount_monitor;
11763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (event_type != G_FILE_MONITOR_EVENT_CHANGED &&
11783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      event_type != G_FILE_MONITOR_EVENT_CREATED &&
11793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      event_type != G_FILE_MONITOR_EVENT_DELETED)
11803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return;
11813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  mount_monitor = user_data;
11833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_signal_emit (mount_monitor, signals[MOUNTS_CHANGED], 0);
11843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
11853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11863781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic void
11873781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_monitor_init (GUnixMountMonitor *monitor)
11883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
11893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GFile *file;
11903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (get_fstab_file () != NULL)
11923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
11933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      file = g_file_new_for_path (get_fstab_file ());
11943690cb75a67377a169264e226655d8fa3a5d003aAlexander Larsson      monitor->fstab_monitor = g_file_monitor_file (file, 0, NULL, NULL);
11953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      g_object_unref (file);
11963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
11973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      g_signal_connect (monitor->fstab_monitor, "changed", (GCallback)fstab_file_changed, monitor);
11983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
11993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
12003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (get_mtab_monitor_file () != NULL)
12013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
12023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      file = g_file_new_for_path (get_mtab_monitor_file ());
12033690cb75a67377a169264e226655d8fa3a5d003aAlexander Larsson      monitor->mtab_monitor = g_file_monitor_file (file, 0, NULL, NULL);
12043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      g_object_unref (file);
12053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
12063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      g_signal_connect (monitor->mtab_monitor, "changed", (GCallback)mtab_file_changed, monitor);
12073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
12083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
12093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
12103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
12113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_monitor_new:
12123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
12135247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets a new #GUnixMountMonitor.
12145247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
12155247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a #GUnixMountMonitor.
12163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
12173781343738de4abddf56982325a77bd70a98cd26Alexander LarssonGUnixMountMonitor *
12183781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_monitor_new (void)
12193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
12203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (the_mount_monitor == NULL)
12213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
12223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      the_mount_monitor = g_object_new (G_TYPE_UNIX_MOUNT_MONITOR, NULL);
12233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      return the_mount_monitor;
12243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
12253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
12263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return g_object_ref (the_mount_monitor);
12273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
12283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
12293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
12303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_free:
12313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount_entry: a #GUnixMount.
12323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
12335247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Frees a unix mount.
12343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
12353781343738de4abddf56982325a77bd70a98cd26Alexander Larssonvoid
12363ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_free (GUnixMountEntry *mount_entry)
12373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
12383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_if_fail (mount_entry != NULL);
12393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
12403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_free (mount_entry->mount_path);
12413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_free (mount_entry->device_path);
12423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_free (mount_entry->filesystem_type);
12433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_free (mount_entry);
12443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
12453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
12463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
12473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_free:
12485247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: unix mount point to free.
12493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
12505247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Frees a unix mount point.
12513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
12523781343738de4abddf56982325a77bd70a98cd26Alexander Larssonvoid
12533781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_free (GUnixMountPoint *mount_point)
12543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
12553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_if_fail (mount_point != NULL);
12563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
12573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_free (mount_point->mount_path);
12583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_free (mount_point->device_path);
12593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_free (mount_point->filesystem_type);
12603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_free (mount_point);
12613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
12623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
12633781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic int
12643781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstrcmp_null (const char *str1,
12653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	     const char *str2)
12663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
12673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (str1 == str2)
12683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return 0;
12693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (str1 == NULL && str2 != NULL)
12703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return -1;
12713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (str1 != NULL && str2 == NULL)
12723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return 1;
12733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return strcmp (str1, str2);
12743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
12753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
12763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
12773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_compare:
12783ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @mount1: first #GUnixMountEntry to compare.
12793ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @mount2: second #GUnixMountEntry to compare.
12803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
12815247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Compares two unix mounts.
12825247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
1283442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * Returns: 1, 0 or -1 if @mount1 is greater than, equal to,
12843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * or less than @mount2, respectively.
12853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
12863781343738de4abddf56982325a77bd70a98cd26Alexander Larssongint
12873ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_compare (GUnixMountEntry *mount1,
12883ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen		      GUnixMountEntry *mount2)
12893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
12903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  int res;
12913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
12923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount1 != NULL && mount2 != NULL, 0);
12933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
12943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  res = strcmp_null (mount1->mount_path, mount2->mount_path);
12953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (res != 0)
12963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return res;
12973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
12983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  res = strcmp_null (mount1->device_path, mount2->device_path);
12993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (res != 0)
13003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return res;
13013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  res = strcmp_null (mount1->filesystem_type, mount2->filesystem_type);
13033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (res != 0)
13043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return res;
13053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  res =  mount1->is_read_only - mount2->is_read_only;
13073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (res != 0)
13083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return res;
13093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return 0;
13113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
13123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
13143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_get_mount_path:
13153ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @mount_entry: input #GUnixMountEntry to get the mount path for.
13163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
13175247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets the mount path for a unix mount.
13183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
13195247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: the mount path for @mount_entry.
13203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
13213781343738de4abddf56982325a77bd70a98cd26Alexander Larssonconst char *
13223ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_get_mount_path (GUnixMountEntry *mount_entry)
13233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
13243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_entry != NULL, NULL);
13253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return mount_entry->mount_path;
13273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
13283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
13303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_get_device_path:
13313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount_entry: a #GUnixMount.
13323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
13335247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets the device path for a unix mount.
13345247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
13355247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a string containing the device path.
13363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
13373781343738de4abddf56982325a77bd70a98cd26Alexander Larssonconst char *
13383ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_get_device_path (GUnixMountEntry *mount_entry)
13393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
13403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_entry != NULL, NULL);
13413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return mount_entry->device_path;
13433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
13443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
13463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_get_fs_type:
13473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount_entry: a #GUnixMount.
13483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
13495247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets the filesystem type for the unix mount.
13505247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
13515247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a string containing the file system type.
13523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
13533781343738de4abddf56982325a77bd70a98cd26Alexander Larssonconst char *
13543ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_get_fs_type (GUnixMountEntry *mount_entry)
13553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
13563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_entry != NULL, NULL);
13573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return mount_entry->filesystem_type;
13593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
13603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
13623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_is_readonly:
13633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount_entry: a #GUnixMount.
13643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
13655247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if a unix mount is mounted read only.
13663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
13675247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: %TRUE if @mount_entry is read only.
13683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
13693781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean
13703ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_is_readonly (GUnixMountEntry *mount_entry)
13713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
13723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_entry != NULL, FALSE);
13733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return mount_entry->is_read_only;
13753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
13763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
13783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_is_system_internal:
13793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount_entry: a #GUnixMount.
13803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
13815247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if a unix mount is a system path.
13825247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
13835247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: %TRUE if the unix mount is for a system path.
13843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
13853781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean
13863ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_is_system_internal (GUnixMountEntry *mount_entry)
13873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
13883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_entry != NULL, FALSE);
13893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return mount_entry->is_system_internal;
13913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
13923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
13933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
13943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_compare:
13953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount1: a #GUnixMount.
13963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount2: a #GUnixMount.
13973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
13985247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Compares two unix mount points.
13995247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
1400442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * Returns: 1, 0 or -1 if @mount1 is greater than, equal to,
14013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * or less than @mount2, respectively.
14023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
14033781343738de4abddf56982325a77bd70a98cd26Alexander Larssongint
14043781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_compare (GUnixMountPoint *mount1,
14053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			    GUnixMountPoint *mount2)
14063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
14073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  int res;
14083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount1 != NULL && mount2 != NULL, 0);
14103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  res = strcmp_null (mount1->mount_path, mount2->mount_path);
14123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (res != 0)
14133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return res;
14143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  res = strcmp_null (mount1->device_path, mount2->device_path);
14163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (res != 0)
14173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return res;
14183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  res = strcmp_null (mount1->filesystem_type, mount2->filesystem_type);
14203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (res != 0)
14213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return res;
14223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  res =  mount1->is_read_only - mount2->is_read_only;
14243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (res != 0)
14253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return res;
14263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  res = mount1->is_user_mountable - mount2->is_user_mountable;
14283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (res != 0)
14293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return res;
14303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  res = mount1->is_loopback - mount2->is_loopback;
14323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (res != 0)
14333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    return res;
14343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return 0;
14363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
14373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
14393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_get_mount_path:
14405247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint.
14415247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
14425247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets the mount path for a unix mount point.
14433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
14445247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a string containing the mount path.
14453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
14463781343738de4abddf56982325a77bd70a98cd26Alexander Larssonconst char *
14473781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_get_mount_path (GUnixMountPoint *mount_point)
14483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
14493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_point != NULL, NULL);
14503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return mount_point->mount_path;
14523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
14533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
14553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_get_device_path:
14565247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint.
14575247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
14585247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets the device path for a unix mount point.
14593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
14605247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a string containing the device path.
14613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
14623781343738de4abddf56982325a77bd70a98cd26Alexander Larssonconst char *
14633781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_get_device_path (GUnixMountPoint *mount_point)
14643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
14653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_point != NULL, NULL);
14663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return mount_point->device_path;
14683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
14693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
14713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_get_fs_type:
14725247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint.
14733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
14745247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets the file system type for the mount point.
14755247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
14765247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a string containing the file system type.
14773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
14783781343738de4abddf56982325a77bd70a98cd26Alexander Larssonconst char *
14793781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_get_fs_type (GUnixMountPoint *mount_point)
14803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
14813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_point != NULL, NULL);
14823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return mount_point->filesystem_type;
14843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
14853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
14873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_is_readonly:
14885247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint.
14895247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
14905247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if a unix mount point is read only.
14913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
14925247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: %TRUE if a mount point is read only.
14933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
14943781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean
14953781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_is_readonly (GUnixMountPoint *mount_point)
14963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
14973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_point != NULL, FALSE);
14983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
14993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return mount_point->is_read_only;
15003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
15013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
15023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
15033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_is_user_mountable:
15045247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint.
15055247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
15065247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if a unix mount point is mountable by the user.
15073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
15085247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: %TRUE if the mount point is user mountable.
15093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
15103781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean
15113781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_is_user_mountable (GUnixMountPoint *mount_point)
15123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
15133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_point != NULL, FALSE);
15143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
15153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return mount_point->is_user_mountable;
15163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
15173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
15183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/**
15193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_is_loopback:
15205247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint.
15213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
15225247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if a unix mount point is a loopback device.
15235247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
15245247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: %TRUE if the mount point is a loopback. %FALSE otherwise.
15253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
15263781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean
15273781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_is_loopback (GUnixMountPoint *mount_point)
15283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
15293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_point != NULL, FALSE);
15303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
15313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return mount_point->is_loopback;
15323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
15333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
15343781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GUnixMountType
15353781343738de4abddf56982325a77bd70a98cd26Alexander Larssonguess_mount_type (const char *mount_path,
15363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  const char *device_path,
15373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson		  const char *filesystem_type)
15383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
15393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  GUnixMountType type;
15403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  char *basename;
15413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
15423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  type = G_UNIX_MOUNT_TYPE_UNKNOWN;
15433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
15443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if ((strcmp (filesystem_type, "udf") == 0) ||
15453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      (strcmp (filesystem_type, "iso9660") == 0) ||
15463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      (strcmp (filesystem_type, "cd9660") == 0))
15473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    type = G_UNIX_MOUNT_TYPE_CDROM;
15483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  else if (strcmp (filesystem_type, "nfs") == 0)
15493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    type = G_UNIX_MOUNT_TYPE_NFS;
15503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  else if (g_str_has_prefix (device_path, "/vol/dev/diskette/") ||
15513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	   g_str_has_prefix (device_path, "/dev/fd") ||
15523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	   g_str_has_prefix (device_path, "/dev/floppy"))
15533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    type = G_UNIX_MOUNT_TYPE_FLOPPY;
15543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  else if (g_str_has_prefix (device_path, "/dev/cdrom") ||
15553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	   g_str_has_prefix (device_path, "/dev/acd") ||
15563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	   g_str_has_prefix (device_path, "/dev/cd"))
15573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    type = G_UNIX_MOUNT_TYPE_CDROM;
15583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  else if (g_str_has_prefix (device_path, "/vol/"))
15593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
15603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      const char *name = mount_path + strlen ("/");
15613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
15623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (g_str_has_prefix (name, "cdrom"))
15633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_CDROM;
15643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (g_str_has_prefix (name, "floppy") ||
15653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	       g_str_has_prefix (device_path, "/vol/dev/diskette/"))
15663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_FLOPPY;
15673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (g_str_has_prefix (name, "rmdisk"))
15683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_ZIP;
15693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (g_str_has_prefix (name, "jaz"))
15703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_JAZ;
15713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (g_str_has_prefix (name, "memstick"))
15723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_MEMSTICK;
15733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
15743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  else
15753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    {
15763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      basename = g_path_get_basename (mount_path);
15773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
15783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      if (g_str_has_prefix (basename, "cdrom") ||
15793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdwriter") ||
15803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "burn") ||
15813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdr") ||
15823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdrw") ||
15833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "dvdrom") ||
15843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "dvdram") ||
15853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "dvdr") ||
15863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "dvdrw") ||
15873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdrom_dvdrom") ||
15883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdrom_dvdram") ||
15893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdrom_dvdr") ||
15903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdrom_dvdrw") ||
15913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdr_dvdrom") ||
15923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdr_dvdram") ||
15933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdr_dvdr") ||
15943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdr_dvdrw") ||
15953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdrw_dvdrom") ||
15963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdrw_dvdram") ||
15973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdrw_dvdr") ||
15983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	  g_str_has_prefix (basename, "cdrw_dvdrw"))
15993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_CDROM;
16003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (g_str_has_prefix (basename, "floppy"))
16013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_FLOPPY;
16023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (g_str_has_prefix (basename, "zip"))
16033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_ZIP;
16043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (g_str_has_prefix (basename, "jaz"))
16053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_JAZ;
16063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (g_str_has_prefix (basename, "camera"))
16073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_CAMERA;
16083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (g_str_has_prefix (basename, "memstick") ||
16093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	       g_str_has_prefix (basename, "memory_stick") ||
16103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	       g_str_has_prefix (basename, "ram"))
16113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_MEMSTICK;
16123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (g_str_has_prefix (basename, "compact_flash"))
16133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_CF;
16143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (g_str_has_prefix (basename, "smart_media"))
16153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_SM;
16163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (g_str_has_prefix (basename, "sd_mmc"))
16173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_SDMMC;
16183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      else if (g_str_has_prefix (basename, "ipod"))
16193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson	type = G_UNIX_MOUNT_TYPE_IPOD;
16203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
16213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson      g_free (basename);
16223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    }
16233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
16243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  if (type == G_UNIX_MOUNT_TYPE_UNKNOWN)
16253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson    type = G_UNIX_MOUNT_TYPE_HD;
16263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
16273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return type;
16283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
16293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1630f5063650794c987868830241a630993e624eabd9Alexander Larsson/*
16313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_guess_type:
16323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount_entry: a #GUnixMount.
16333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
16345247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Guesses the type of a unix mount. If the mount type cannot be
16355247f12f3649726471080440de0d37b78c1cec33Andrew Walton * determined, returns %G_UNIX_MOUNT_TYPE_UNKNOWN.
16365247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
16375247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a #GUnixMountType.
16383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
1639f5063650794c987868830241a630993e624eabd9Alexander Larssonstatic GUnixMountType
16403ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_guess_type (GUnixMountEntry *mount_entry)
16413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
16423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_entry != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
16433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_entry->mount_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
16443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_entry->device_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
16453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_entry->filesystem_type != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
16463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
16473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return guess_mount_type (mount_entry->mount_path,
16483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			   mount_entry->device_path,
16493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			   mount_entry->filesystem_type);
16503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
16513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
1652f5063650794c987868830241a630993e624eabd9Alexander Larsson/*
16533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_guess_type:
16545247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint.
16555247f12f3649726471080440de0d37b78c1cec33Andrew Walton *
16562e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Guesses the type of a unix mount point.
16572e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * If the mount type cannot be determined,
16582e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * returns %G_UNIX_MOUNT_TYPE_UNKNOWN.
16593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *
16605247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a #GUnixMountType.
16613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/
1662f5063650794c987868830241a630993e624eabd9Alexander Larssonstatic GUnixMountType
16633781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_guess_type (GUnixMountPoint *mount_point)
16643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{
16653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_point != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
16663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_point->mount_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
16673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_point->device_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
16683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  g_return_val_if_fail (mount_point->filesystem_type != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN);
16693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson
16703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson  return guess_mount_type (mount_point->mount_path,
16713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			   mount_point->device_path,
16723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson			   mount_point->filesystem_type);
16733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}
16747f3280230bc9448a5750fc17a6eabef691ba25f4Alexander Larsson
16753ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenstatic const char *
16763ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthentype_to_icon (GUnixMountType type, gboolean is_mount_point)
16773ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{
16783ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  const char *icon_name;
16793ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
16803ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  switch (type)
16813ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    {
16823ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    case G_UNIX_MOUNT_TYPE_HD:
16833ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      if (is_mount_point)
16843ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "drive-removable-media";
16853ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      else
16863ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "drive-harddisk";
16873ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      break;
16883ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    case G_UNIX_MOUNT_TYPE_FLOPPY:
16893ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    case G_UNIX_MOUNT_TYPE_ZIP:
16903ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    case G_UNIX_MOUNT_TYPE_JAZ:
16913ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      if (is_mount_point)
16923ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "drive-removable-media";
16933ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      else
16943ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "media-floppy";
16953ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      break;
16963ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    case G_UNIX_MOUNT_TYPE_CDROM:
16973ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      if (is_mount_point)
16983ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "drive-optical";
16993ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      else
17003ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "media-optical";
17013ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      break;
17023ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    case G_UNIX_MOUNT_TYPE_NFS:
17033ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      /* TODO: Would like a better icon here... */
17043ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      if (is_mount_point)
17053ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "drive-removable-media";
17063ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      else
17073ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "drive-harddisk";
17083ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      break;
17093ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    case G_UNIX_MOUNT_TYPE_MEMSTICK:
17103ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      if (is_mount_point)
17113ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "drive-removable-media";
17123ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      else
17133ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "media-flash";
17143ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      break;
17153ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    case G_UNIX_MOUNT_TYPE_CAMERA:
17163ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      if (is_mount_point)
17173ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "drive-removable-media";
17183ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      else
17193ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "camera-photo";
17203ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      break;
17213ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    case G_UNIX_MOUNT_TYPE_IPOD:
17223ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      if (is_mount_point)
17233ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "drive-removable-media";
17243ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      else
17253ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "multimedia-player";
17263ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      break;
17273ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    case G_UNIX_MOUNT_TYPE_UNKNOWN:
17283ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    default:
17293ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      if (is_mount_point)
17303ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "drive-removable-media";
17313ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      else
17323ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        icon_name = "drive-harddisk";
17333ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      break;
17343ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    }
17353ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
17363ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  return icon_name;
17373ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen}
17383ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
17392e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen/**
17402e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * g_unix_mount_guess_name:
17412e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * @mount_entry: a #GUnixMountEntry
17422e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen *
17432e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Guesses the name of a Unix mount.
17442e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * The result is a translated string.
17452e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen *
17462e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Returns: A newly allocated string that must
17472e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen *     be freed with g_free()
17482e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen */
17493ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenchar *
17503ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_guess_name (GUnixMountEntry *mount_entry)
17513ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{
17523ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  char *name;
17533ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
17543ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  if (strcmp (mount_entry->mount_path, "/") == 0)
17553ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    name = g_strdup (_("Filesystem root"));
17563ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  else
17573ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    name = g_filename_display_basename (mount_entry->mount_path);
17583ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
17593ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  return name;
17603ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen}
17613ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
17622e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen/**
17632e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * g_unix_mount_guess_icon:
17642e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * @mount_entry: a #GUnixMountEntry
17652e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen *
17662e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Guesses the icon of a Unix mount.
17672e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen *
17682e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Returns: a #GIcon
17692e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen */
17703ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid ZeuthenGIcon *
17713ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_guess_icon (GUnixMountEntry *mount_entry)
17723ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{
177347b8809e176f4bc7f22768cb45fec47280c4242fAlexander Larsson  return g_themed_icon_new_with_default_fallbacks (type_to_icon (g_unix_mount_guess_type (mount_entry), FALSE));
17743ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen}
17753ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
17762e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen/**
17772e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * g_unix_mount_point_guess_name:
17782e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * @mount_point: a #GUnixMountPoint
17792e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen *
17802e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Guesses the name of a Unix mount point.
17812e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * The result is a translated string.
17822e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen *
17832e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Returns: A newly allocated string that must
17842e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen *     be freed with g_free()
17852e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen */
17863ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenchar *
17873ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_point_guess_name (GUnixMountPoint *mount_point)
17883ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{
17893ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  char *name;
17903ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
17913ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  if (strcmp (mount_point->mount_path, "/") == 0)
17923ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    name = g_strdup (_("Filesystem root"));
17933ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  else
17943ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    name = g_filename_display_basename (mount_point->mount_path);
17953ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
17963ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  return name;
17973ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen}
17983ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
17992e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen/**
18002e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * g_unix_mount_point_guess_icon:
18012e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * @mount_point: a #GUnixMountPoint
18022e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen *
18032e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Guesses the icon of a Unix mount point.
18042e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen *
18052e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Returns: a #GIcon
18062e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen */
18073ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid ZeuthenGIcon *
18083ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_point_guess_icon (GUnixMountPoint *mount_point)
18093ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{
181047b8809e176f4bc7f22768cb45fec47280c4242fAlexander Larsson  return g_themed_icon_new_with_default_fallbacks (type_to_icon (g_unix_mount_point_guess_type (mount_point), TRUE));
18113ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen}
18123ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
1813c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen/**
1814c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * g_unix_mount_guess_can_eject:
1815c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * @mount_entry: a #GUnixMountEntry
1816c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen *
1817c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * Guesses whether a Unix mount can be ejected.
1818c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen *
1819c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * Returns: %TRUE if @mount_entry is deemed to be ejectable.
1820c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen */
1821f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthengboolean
1822f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeutheng_unix_mount_guess_can_eject (GUnixMountEntry *mount_entry)
1823f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen{
1824f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen  GUnixMountType guessed_type;
1825f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen
1826f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen  guessed_type = g_unix_mount_guess_type (mount_entry);
1827f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen  if (guessed_type == G_UNIX_MOUNT_TYPE_IPOD ||
1828f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen      guessed_type == G_UNIX_MOUNT_TYPE_CDROM)
1829f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen    return TRUE;
1830f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen
1831f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen  return FALSE;
1832f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen}
1833f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen
1834c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen/**
1835896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson * g_unix_mount_guess_should_display:
1836896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson * @mount_entry: a #GUnixMountEntry
1837896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson *
1838896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson * Guesses whether a Unix mount should be displayed in the UI.
1839896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson *
1840896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson * Returns: %TRUE if @mount_entry is deemed to be displayable.
1841896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson */
1842896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larssongboolean
1843896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larssong_unix_mount_guess_should_display (GUnixMountEntry *mount_entry)
1844896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson{
1845896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson  GUnixMountType guessed_type;
1846896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson
1847896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson  /* Never display internal mountpoints */
1848896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson  if (g_unix_mount_is_system_internal (mount_entry))
1849896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson    return FALSE;
1850896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson
1851896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson  /* Only display things that look "removable" or
1852896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson     things in /media (which are generally user mountable) */
1853896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson  guessed_type = g_unix_mount_guess_type (mount_entry);
1854896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson  if (guessed_type == G_UNIX_MOUNT_TYPE_IPOD ||
1855896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson      guessed_type == G_UNIX_MOUNT_TYPE_CDROM ||
1856896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson      guessed_type == G_UNIX_MOUNT_TYPE_FLOPPY ||
1857896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson      guessed_type == G_UNIX_MOUNT_TYPE_ZIP ||
1858896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson      guessed_type == G_UNIX_MOUNT_TYPE_JAZ ||
1859896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson      guessed_type == G_UNIX_MOUNT_TYPE_CAMERA ||
1860896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson      guessed_type == G_UNIX_MOUNT_TYPE_MEMSTICK ||
1861896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson      (mount_entry->mount_path != NULL &&
1862896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson       g_str_has_prefix (mount_entry->mount_path, "/media")))
1863896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson    return TRUE;
1864896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson
1865896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson  return FALSE;
1866896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson}
1867896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson
1868896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson/**
1869c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * g_unix_mount_point_guess_can_eject:
1870c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * @mount_point: a #GUnixMountPoint
1871c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen *
1872c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * Guesses whether a Unix mount point can be ejected.
1873c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen *
1874c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * Returns: %TRUE if @mount_point is deemed to be ejectable.
1875c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen */
1876f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthengboolean
1877f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeutheng_unix_mount_point_guess_can_eject (GUnixMountPoint *mount_point)
1878f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen{
1879f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen  GUnixMountType guessed_type;
1880f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen
1881f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen  guessed_type = g_unix_mount_point_guess_type (mount_point);
1882f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen  if (guessed_type == G_UNIX_MOUNT_TYPE_IPOD ||
1883f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen      guessed_type == G_UNIX_MOUNT_TYPE_CDROM)
1884f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen    return TRUE;
1885f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen
1886f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen  return FALSE;
1887f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen}
1888f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen
18893ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
18903ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen/* borrowed from gtk/gtkfilesystemunix.c in GTK+ on 02/23/2006 */
18913ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenstatic void
18923ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen_canonicalize_filename (gchar *filename)
18933ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{
18943ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  gchar *p, *q;
18953ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  gboolean last_was_slash = FALSE;
18963ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
18973ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  p = filename;
18983ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  q = filename;
18993ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19003ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  while (*p)
19013ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    {
19023ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      if (*p == G_DIR_SEPARATOR)
19033ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        {
19043ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen          if (!last_was_slash)
19053ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen            *q++ = G_DIR_SEPARATOR;
19063ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19073ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen          last_was_slash = TRUE;
19083ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        }
19093ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      else
19103ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        {
19113ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen          if (last_was_slash && *p == '.')
19123ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen            {
19133ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen              if (*(p + 1) == G_DIR_SEPARATOR ||
19143ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                  *(p + 1) == '\0')
19153ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                {
19163ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                  if (*(p + 1) == '\0')
19173ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                    break;
19183ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19193ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                  p += 1;
19203ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                }
19213ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen              else if (*(p + 1) == '.' &&
19223ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                       (*(p + 2) == G_DIR_SEPARATOR ||
19233ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                        *(p + 2) == '\0'))
19243ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                {
19253ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                  if (q > filename + 1)
19263ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                    {
19273ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                      q--;
19283ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                      while (q > filename + 1 &&
19293ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                             *(q - 1) != G_DIR_SEPARATOR)
19303ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                        q--;
19313ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                    }
19323ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19333ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                  if (*(p + 2) == '\0')
19343ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                    break;
19353ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19363ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                  p += 2;
19373ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                }
19383ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen              else
19393ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                {
19403ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                  *q++ = *p;
19413ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                  last_was_slash = FALSE;
19423ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen                }
19433ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen            }
19443ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen          else
19453ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen            {
19463ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen              *q++ = *p;
19473ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen              last_was_slash = FALSE;
19483ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen            }
19493ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        }
19503ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19513ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      p++;
19523ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    }
19533ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19543ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  if (q > filename + 1 && *(q - 1) == G_DIR_SEPARATOR)
19553ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    q--;
19563ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19573ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  *q = '\0';
19583ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen}
19593ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19603ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenstatic char *
19613ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen_resolve_symlink (const char *file)
19623ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{
19633ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  GError *error;
19643ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  char *dir;
19653ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  char *link;
19663ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  char *f;
19673ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  char *f1;
19683ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19693ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  f = g_strdup (file);
19703ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19713ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  while (g_file_test (f, G_FILE_TEST_IS_SYMLINK)) {
19723ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    link = g_file_read_link (f, &error);
19733ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    if (link == NULL) {
19743ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      g_error_free (error);
19753ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      g_free (f);
19763ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      f = NULL;
19773ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      goto out;
19783ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    }
19793ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19803ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    dir = g_path_get_dirname (f);
19813ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    f1 = g_strdup_printf ("%s/%s", dir, link);
19823ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    g_free (dir);
19833ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    g_free (link);
19843ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    g_free (f);
19853ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    f = f1;
19863ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  }
19873ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19883ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen out:
19893ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  if (f != NULL)
19903ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    _canonicalize_filename (f);
19913ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  return f;
19923ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen}
19933ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
19946ad96b367793557d0a02c1bff75cc60befcd59a6Alexander Larsson#ifdef HAVE_MNTENT_H
19953ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenstatic const char *
19963ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen_resolve_dev_root (void)
19973ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{
19983ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  static gboolean have_real_dev_root = FALSE;
19993ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  static char real_dev_root[256];
20003ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  struct stat statbuf;
20013ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
20023ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  /* see if it's cached already */
20033ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  if (have_real_dev_root)
20043ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    goto found;
20053ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
20063ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  /* otherwise we're going to find it right away.. */
20073ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  have_real_dev_root = TRUE;
20083ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
20093ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  if (stat ("/dev/root", &statbuf) == 0) {
20103ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    if (! S_ISLNK (statbuf.st_mode)) {
20113ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      dev_t root_dev = statbuf.st_dev;
20123ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      FILE *f;
20133ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      char buf[1024];
20143ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
20153ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      /* see if device with similar major:minor as /dev/root is mention
20163ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen       * in /etc/mtab (it usually is)
20173ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen       */
20183ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      f = fopen ("/etc/mtab", "r");
20193ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      if (f != NULL) {
20203ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        struct mntent ent;
20213ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
20223ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        while (getmntent_r (f, &ent, buf, sizeof (buf)) != NULL) {
20233ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
20243ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen          if (stat (ent.mnt_fsname, &statbuf) == 0 &&
20253ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen              statbuf.st_dev == root_dev) {
20263ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen            strncpy (real_dev_root, ent.mnt_fsname, sizeof (real_dev_root) - 1);
20273ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen            real_dev_root[sizeof (real_dev_root) - 1] = '\0';
20283ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen            fclose (f);
20293ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen            goto found;
20303ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen          }
20313ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        }
20323ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        fclose (f);
20333ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      }
20343ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
20353ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      /* no, that didn't work.. next we could scan /dev ... but I digress.. */
20363ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
20373ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    } else {
20383ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      char *resolved;
20393ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      resolved = _resolve_symlink ("/dev/root");
20403ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      if (resolved != NULL) {
20413ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        strncpy (real_dev_root, resolved, sizeof (real_dev_root) - 1);
20423ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        real_dev_root[sizeof (real_dev_root) - 1] = '\0';
20433ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        g_free (resolved);
20443ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen        goto found;
20453ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen      }
20463ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen    }
20473ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  }
20483ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
20493ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  /* bah sucks.. */
20503ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  strcpy (real_dev_root, "/dev/root");
20513ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
20523ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen found:
20533ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen  return real_dev_root;
20543ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen}
20556ad96b367793557d0a02c1bff75cc60befcd59a6Alexander Larsson#endif
20563ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen
20577f3280230bc9448a5750fc17a6eabef691ba25f4Alexander Larsson#define __G_UNIX_MOUNTS_C__
20587f3280230bc9448a5750fc17a6eabef691ba25f4Alexander Larsson#include "gioaliasdef.c"
2059