gunixmounts.c revision a28d87bfc987d8b0aa27c6f9d996a31894fedf4a
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 25761424465aaad736916b029383483b6ac419d831Johan Dahlin#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> 4727dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen#include <gstdio.h> 483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include "gunixmounts.h" 503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include "gfile.h" 513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include "gfilemonitor.h" 523ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen#include "glibintl.h" 533ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen#include "gthemedicon.h" 543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 557f3280230bc9448a5750fc17a6eabef691ba25f4Alexander Larsson#include "gioalias.h" 567f3280230bc9448a5750fc17a6eabef691ba25f4Alexander Larsson 573ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenstatic const char *_resolve_dev_root (void); 583ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 595247f12f3649726471080440de0d37b78c1cec33Andrew Walton/** 605247f12f3649726471080440de0d37b78c1cec33Andrew Walton * SECTION:gunixmounts 610debd52858ffb4f468e55cd2f3c7e4dec5455b94Matthias Clasen * @include: gio/gunixmounts.h 625247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @short_description: Unix Mounts 635247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 645247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Routines for managing mounted UNIX mount points and paths. 655247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 665247f12f3649726471080440de0d37b78c1cec33Andrew Walton **/ 675247f12f3649726471080440de0d37b78c1cec33Andrew Walton 68f5063650794c987868830241a630993e624eabd9Alexander Larsson/* 693ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * GUnixMountType: 703ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_UNKNOWN: Unknown UNIX mount type. 713ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_FLOPPY: Floppy disk UNIX mount type. 723ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_CDROM: CDROM UNIX mount type. 733ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_NFS: Network File System (NFS) UNIX mount type. 743ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_ZIP: ZIP UNIX mount type. 753ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_JAZ: JAZZ UNIX mount type. 763ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_MEMSTICK: Memory Stick UNIX mount type. 773ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_CF: Compact Flash UNIX mount type. 783ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_SM: Smart Media UNIX mount type. 793ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_SDMMC: SD/MMC UNIX mount type. 803ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_IPOD: iPod UNIX mount type. 813ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_CAMERA: Digital camera UNIX mount type. 823ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @G_UNIX_MOUNT_TYPE_HD: Hard drive UNIX mount type. 833ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * 843ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * Types of UNIX mounts. 853ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen **/ 863ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthentypedef enum { 873ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen G_UNIX_MOUNT_TYPE_UNKNOWN, 883ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen G_UNIX_MOUNT_TYPE_FLOPPY, 893ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen G_UNIX_MOUNT_TYPE_CDROM, 903ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen G_UNIX_MOUNT_TYPE_NFS, 913ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen G_UNIX_MOUNT_TYPE_ZIP, 923ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen G_UNIX_MOUNT_TYPE_JAZ, 933ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen G_UNIX_MOUNT_TYPE_MEMSTICK, 943ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen G_UNIX_MOUNT_TYPE_CF, 953ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen G_UNIX_MOUNT_TYPE_SM, 963ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen G_UNIX_MOUNT_TYPE_SDMMC, 973ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen G_UNIX_MOUNT_TYPE_IPOD, 983ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen G_UNIX_MOUNT_TYPE_CAMERA, 993ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen G_UNIX_MOUNT_TYPE_HD 1003ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen} GUnixMountType; 1013ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 1023ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenstruct _GUnixMountEntry { 1033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char *mount_path; 1043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char *device_path; 1053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char *filesystem_type; 1063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson gboolean is_read_only; 1073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson gboolean is_system_internal; 1083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}; 1093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1103781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstruct _GUnixMountPoint { 1113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char *mount_path; 1123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char *device_path; 1133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char *filesystem_type; 1143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson gboolean is_read_only; 1153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson gboolean is_user_mountable; 1163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson gboolean is_loopback; 1173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}; 1183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1193781343738de4abddf56982325a77bd70a98cd26Alexander Larssonenum { 1203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson MOUNTS_CHANGED, 1213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson MOUNTPOINTS_CHANGED, 1223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson LAST_SIGNAL 1233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}; 1243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1253781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic guint signals[LAST_SIGNAL]; 1263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1273781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstruct _GUnixMountMonitor { 1283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GObject parent; 1293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GFileMonitor *fstab_monitor; 1313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GFileMonitor *mtab_monitor; 1323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}; 1333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1343781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstruct _GUnixMountMonitorClass { 1353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GObjectClass parent_class; 1363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson}; 1373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1383781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GUnixMountMonitor *the_mount_monitor = NULL; 1393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1403781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList *_g_get_unix_mounts (void); 1413781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList *_g_get_unix_mount_points (void); 1423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1433781343738de4abddf56982325a77bd70a98cd26Alexander LarssonG_DEFINE_TYPE (GUnixMountMonitor, g_unix_mount_monitor, G_TYPE_OBJECT); 1443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#define MOUNT_POLL_INTERVAL 4000 1463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_MNTTAB_H 1483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#define MNTOPT_RO "ro" 1493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 1503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_MNTENT_H 1523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <mntent.h> 1533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined (HAVE_SYS_MNTTAB_H) 1543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/mnttab.h> 1553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 1563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_VFSTAB_H 1583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/vfstab.h> 1593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 1603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#if defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H) 1623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/mntctl.h> 1633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/vfs.h> 1643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/vmount.h> 1653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <fshelp.h> 1663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 1673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#if defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H) 1693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/ucred.h> 1703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/mount.h> 1713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <fstab.h> 1723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_SYSCTL_H 1733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#include <sys/sysctl.h> 1743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 1753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 1763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifndef HAVE_SETMNTENT 1783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#define setmntent(f,m) fopen(f,m) 1793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 1803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifndef HAVE_ENDMNTENT 1813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#define endmntent(f) fclose(f) 1823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 1833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1843781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic gboolean 1853781343738de4abddf56982325a77bd70a98cd26Alexander Larssonis_in (const char *value, const char *set[]) 1863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 1873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson int i; 1883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson for (i = 0; set[i] != NULL; i++) 1893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 1903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (strcmp (set[i], value) == 0) 1913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return TRUE; 1923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 1933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return FALSE; 1943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 1953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1963ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen/** 1973ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * g_unix_is_mount_path_system_internal: 198f5d2feddf6311492ea9f7124d73d2997db0ca123Matthias Clasen * @mount_path: a mount path, e.g. <filename>/media/disk</filename> 199f5d2feddf6311492ea9f7124d73d2997db0ca123Matthias Clasen * or <filename>/usr</filename> 2003ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * 2013ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * Determines if @mount_path is considered an implementation of the 2023ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * OS. This is primarily used for hiding mountable and mounted volumes 2033ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * that only are used in the OS and has little to no relevance to the 2043ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * casual user. 2053ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * 206f5d2feddf6311492ea9f7124d73d2997db0ca123Matthias Clasen * Returns: %TRUE if @mount_path is considered an implementation detail 207f5d2feddf6311492ea9f7124d73d2997db0ca123Matthias Clasen * of the OS. 2083ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen **/ 2093ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthengboolean 2103ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_is_mount_path_system_internal (const char *mount_path) 2113ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{ 2123ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen const char *ignore_mountpoints[] = { 2133ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen /* Includes all FHS 2.3 toplevel dirs and other specilized 2143ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * directories that we want to hide from the user. 2153ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen */ 2163ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/", /* we already have "Filesystem root" in Nautilus */ 2173ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/bin", 2183ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/boot", 2193ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/dev", 2203ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/etc", 2213ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/home", 2223ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/lib", 2233ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/lib64", 2243ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/media", 2253ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/mnt", 2263ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/opt", 2273ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/root", 2283ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/sbin", 2293ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/srv", 2303ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/tmp", 2313ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/usr", 232246e2e71a91f028e0657d8f0dca489928b4f2750Alexander Larsson "/usr/local", 2333ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/var", 2343ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/var/log/audit", /* https://bugzilla.redhat.com/show_bug.cgi?id=333041 */ 2353ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/var/tmp", /* https://bugzilla.redhat.com/show_bug.cgi?id=335241 */ 2363ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/proc", 2373ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/sbin", 2383ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen "/net", 2393ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen NULL 2403ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen }; 2413ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 2423ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (is_in (mount_path, ignore_mountpoints)) 2433ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen return TRUE; 2443ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 2453ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (g_str_has_prefix (mount_path, "/dev") || 2463ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen g_str_has_prefix (mount_path, "/proc") || 2473ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen g_str_has_prefix (mount_path, "/sys")) 2483ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen return TRUE; 2493ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 2503ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (strstr (mount_path, "/.gvfs") != NULL) 2513ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen return TRUE; 2523ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 2533ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen return FALSE; 2543ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen} 2553ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 2563781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic gboolean 2573781343738de4abddf56982325a77bd70a98cd26Alexander Larssonguess_system_internal (const char *mountpoint, 2583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson const char *fs, 2593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson const char *device) 2603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 2613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson const char *ignore_fs[] = { 2623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "auto", 2633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "autofs", 2643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "devfs", 2653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "devpts", 266c7d37fca345edb23c3b258041140834d80b534a3Matthias Clasen "ecryptfs", 2673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "kernfs", 2683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "linprocfs", 2693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "proc", 2703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "procfs", 2713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "ptyfs", 2723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "rootfs", 2733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "selinuxfs", 2743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "sysfs", 2753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "tmpfs", 2763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "usbfs", 2773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "nfsd", 2787fe31089ff6d2885197fa1d0d9e340eabc779be6Frederic Crozat "rpc_pipefs", 2794cafadc955d1c37118ca269ea22bbd37f8f2a2cePadraig O'Briain "zfs", 2803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson NULL 2813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson }; 2823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson const char *ignore_devices[] = { 2833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "none", 2843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "sunrpc", 2853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "devpts", 2863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "nfsd", 2873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "/dev/loop", 2883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson "/dev/vn", 2893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson NULL 2903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson }; 2913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 2923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (is_in (fs, ignore_fs)) 2933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return TRUE; 2943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 2953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (is_in (device, ignore_devices)) 2963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return TRUE; 2973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 2983ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (g_unix_is_mount_path_system_internal (mountpoint)) 2993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return TRUE; 3003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return FALSE; 3023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 3033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_MNTENT_H 3053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3063781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char * 3073781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mtab_read_file (void) 3083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 3093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef _PATH_MOUNTED 3103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson# ifdef __linux__ 3113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return "/proc/mounts"; 3123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson# else 3133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return _PATH_MOUNTED; 3143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson# endif 3153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#else 3163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return "/etc/mtab"; 3173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 3183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 3193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3203781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char * 3213781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mtab_monitor_file (void) 3223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 3233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef _PATH_MOUNTED 3243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return _PATH_MOUNTED; 3253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#else 3263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return "/etc/mtab"; 3273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 3283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 3293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3300766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#ifndef HAVE_GETMNTENT_R 3313781343738de4abddf56982325a77bd70a98cd26Alexander LarssonG_LOCK_DEFINE_STATIC(getmntent); 3320766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#endif 3333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3343781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList * 3353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mounts () 3363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 3370766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#ifdef HAVE_GETMNTENT_R 3380766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen struct mntent ent; 3390766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen char buf[1024]; 3400766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#endif 3413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson struct mntent *mntent; 3423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson FILE *file; 3433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char *read_file; 3443ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen GUnixMountEntry *mount_entry; 3453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GHashTable *mounts_hash; 3463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GList *return_list; 3473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson read_file = get_mtab_read_file (); 3493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson file = setmntent (read_file, "r"); 3513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (file == NULL) 3523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return NULL; 3533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = NULL; 3553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mounts_hash = g_hash_table_new (g_str_hash, g_str_equal); 3573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3580766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#ifdef HAVE_GETMNTENT_R 3590766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen while ((mntent = getmntent_r (file, &ent, buf, sizeof (buf))) != NULL) 3600766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#else 3613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_LOCK (getmntent); 3623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson while ((mntent = getmntent (file)) != NULL) 3630766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#endif 3643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 3653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson /* ignore any mnt_fsname that is repeated and begins with a '/' 3663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 3673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * We do this to avoid being fooled by --bind mounts, since 3683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * these have the same device as the location they bind to. 369f0749cc896db4174609da7da178d079aaf758845Murray Cumming * Its not an ideal solution to the problem, but it's likely that 3703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * the most important mountpoint is first and the --bind ones after 3713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * that aren't as important. So it should work. 3723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 3733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * The '/' is to handle procfs, tmpfs and other no device mounts. 3743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson */ 3753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (mntent->mnt_fsname != NULL && 3763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mntent->mnt_fsname[0] == '/' && 3773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_hash_table_lookup (mounts_hash, mntent->mnt_fsname)) 3783ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen continue; 3793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3803ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen mount_entry = g_new0 (GUnixMountEntry, 1); 3813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->mount_path = g_strdup (mntent->mnt_dir); 3823ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (strcmp (mntent->mnt_fsname, "/dev/root") == 0) 3833ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen mount_entry->device_path = g_strdup (_resolve_dev_root ()); 3843ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 3853ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen mount_entry->device_path = g_strdup (mntent->mnt_fsname); 3863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type = g_strdup (mntent->mnt_type); 3873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#if defined (HAVE_HASMNTOPT) 3893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (hasmntopt (mntent, MNTOPT_RO) != NULL) 3903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_read_only = TRUE; 3913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 3923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_system_internal = 3943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson guess_system_internal (mount_entry->mount_path, 3953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type, 3963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->device_path); 3973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 3983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_hash_table_insert (mounts_hash, 3993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->device_path, 4003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->device_path); 4013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = g_list_prepend (return_list, mount_entry); 4033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 4043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_hash_table_destroy (mounts_hash); 4053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson endmntent (file); 4073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4080766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#ifndef HAVE_GETMNTENT_R 4093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_UNLOCK (getmntent); 4100766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#endif 4113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return g_list_reverse (return_list); 4133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 4143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined (HAVE_SYS_MNTTAB_H) 4163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4173781343738de4abddf56982325a77bd70a98cd26Alexander LarssonG_LOCK_DEFINE_STATIC(getmntent); 4183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4193781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char * 4203781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mtab_read_file (void) 4213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 4223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef _PATH_MOUNTED 4233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return _PATH_MOUNTED; 4243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#else 4253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return "/etc/mnttab"; 4263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 4273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 4283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4293781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char * 4303781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mtab_monitor_file (void) 4313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 4323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return get_mtab_read_file (); 4333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 4343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4353781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList * 4363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mounts (void) 4373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 4383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson struct mnttab mntent; 4393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson FILE *file; 4403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char *read_file; 4413ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen GUnixMountEntry *mount_entry; 4423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GList *return_list; 4433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson read_file = get_mtab_read_file (); 4453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson file = setmntent (read_file, "r"); 4473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (file == NULL) 4483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return NULL; 4493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = NULL; 4513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_LOCK (getmntent); 4533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson while (! getmntent (file, &mntent)) 4543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 4553ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen mount_entry = g_new0 (GUnixMountEntry, 1); 4563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->mount_path = g_strdup (mntent.mnt_mountp); 4583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->device_path = g_strdup (mntent.mnt_special); 4593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype); 4603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#if defined (HAVE_HASMNTOPT) 4623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (hasmntopt (&mntent, MNTOPT_RO) != NULL) 4633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_read_only = TRUE; 4643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 4653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_system_internal = 4673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson guess_system_internal (mount_entry->mount_path, 4683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type, 4693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->device_path); 4703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = g_list_prepend (return_list, mount_entry); 4723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 4733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson endmntent (file); 4753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_UNLOCK (getmntent); 4773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return g_list_reverse (return_list); 4793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 4803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H) 4823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4833781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char * 4843781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mtab_monitor_file (void) 4853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 4863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return NULL; 4873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 4883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4893781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList * 4903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mounts (void) 4913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 4923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson struct vfs_ent *fs_info; 4933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson struct vmount *vmount_info; 4943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson int vmount_number; 4953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson unsigned int vmount_size; 4963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson int current; 4973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GList *return_list; 4983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 4993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (mntctl (MCTL_QUERY, sizeof (vmount_size), &vmount_size) != 0) 5003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 5013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_warning ("Unable to know the number of mounted volumes\n"); 5023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return NULL; 5043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 5053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson vmount_info = (struct vmount*)g_malloc (vmount_size); 5073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson vmount_number = mntctl (MCTL_QUERY, vmount_size, vmount_info); 5093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (vmount_info->vmt_revision != VMT_REVISION) 5113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_warning ("Bad vmount structure revision number, want %d, got %d\n", VMT_REVISION, vmount_info->vmt_revision); 5123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (vmount_number < 0) 5143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 5153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_warning ("Unable to recover mounted volumes information\n"); 5163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_free (vmount_info); 5183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return NULL; 5193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 5203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = NULL; 5223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson while (vmount_number > 0) 5233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 5243ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen mount_entry = g_new0 (GUnixMountEntry, 1); 5253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->device_path = g_strdup (vmt2dataptr (vmount_info, VMT_OBJECT)); 5273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->mount_path = g_strdup (vmt2dataptr (vmount_info, VMT_STUB)); 5283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson /* is_removable = (vmount_info->vmt_flags & MNT_REMOVABLE) ? 1 : 0; */ 5293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_read_only = (vmount_info->vmt_flags & MNT_READONLY) ? 1 : 0; 5303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson fs_info = getvfsbytype (vmount_info->vmt_gfstype); 5323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (fs_info == NULL) 5343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type = g_strdup ("unknown"); 5353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else 5363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type = g_strdup (fs_info->vfsent_name); 5373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_system_internal = 5393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson guess_system_internal (mount_entry->mount_path, 5403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type, 5413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->device_path); 5423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = g_list_prepend (return_list, mount_entry); 5443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson vmount_info = (struct vmount *)( (char*)vmount_info 5463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson + vmount_info->vmt_length); 5473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson vmount_number--; 5483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 5493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_free (vmount_info); 5523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return g_list_reverse (return_list); 5543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 5553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H) 5573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5583781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char * 5593781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mtab_monitor_file (void) 5603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 5613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return NULL; 5623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 5633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5643781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList * 5653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mounts (void) 5663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 5673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson struct statfs *mntent = NULL; 5683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson int num_mounts, i; 5693ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen GUnixMountEntry *mount_entry; 5703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GList *return_list; 5713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson /* Pass MNT_NOWAIT to avoid blocking trying to update NFS mounts. */ 5733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if ((num_mounts = getmntinfo (&mntent, MNT_NOWAIT)) == 0) 5743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return NULL; 5753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = NULL; 5773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson for (i = 0; i < num_mounts; i++) 5793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 5803ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen mount_entry = g_new0 (GUnixMountEntry, 1); 5813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->mount_path = g_strdup (mntent[i].f_mntonname); 5833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->device_path = g_strdup (mntent[i].f_mntfromname); 5843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type = g_strdup (mntent[i].f_fstypename); 5853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (mntent[i].f_flags & MNT_RDONLY) 5863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_read_only = TRUE; 5873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_system_internal = 5893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson guess_system_internal (mount_entry->mount_path, 5903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type, 5913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->device_path); 5923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = g_list_prepend (return_list, mount_entry); 5943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 5953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 5963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return g_list_reverse (return_list); 5973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 5983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#else 5993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#error No _g_get_unix_mounts() implementation for system 6003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 6013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/* _g_get_unix_mount_points(): 6033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * read the fstab. 6043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * don't return swap and ignore mounts. 6053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson */ 6063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6073781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic char * 6083781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_fstab_file (void) 6093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 6103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#if defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H) 6113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson /* AIX */ 6123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return "/etc/filesystems"; 6133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(_PATH_MNTTAB) 6143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return _PATH_MNTTAB; 6153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(VFSTAB) 6163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return VFSTAB; 6173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#else 6183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return "/etc/fstab"; 6193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 6203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 6213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_MNTENT_H 6233781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList * 6243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mount_points (void) 6253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 6260766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#ifdef HAVE_GETMNTENT_R 6270766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen struct mntent ent; 6280766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen char buf[1024]; 6290766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#endif 6303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson struct mntent *mntent; 6313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson FILE *file; 6323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char *read_file; 6333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GUnixMountPoint *mount_entry; 6343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GList *return_list; 6353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson read_file = get_fstab_file (); 6373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson file = setmntent (read_file, "r"); 6393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (file == NULL) 6403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return NULL; 6413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = NULL; 6433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6440766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#ifdef HAVE_GETMNTENT_R 6450766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen while ((mntent = getmntent_r (file, &ent, buf, sizeof (buf))) != NULL) 6460766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#else 6473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_LOCK (getmntent); 6483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson while ((mntent = getmntent (file)) != NULL) 6490766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#endif 6503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 6513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if ((strcmp (mntent->mnt_dir, "ignore") == 0) || 6523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson (strcmp (mntent->mnt_dir, "swap") == 0)) 6533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson continue; 6543ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 6553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry = g_new0 (GUnixMountPoint, 1); 6563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->mount_path = g_strdup (mntent->mnt_dir); 6573ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (strcmp (mntent->mnt_fsname, "/dev/root") == 0) 6583ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen mount_entry->device_path = g_strdup (_resolve_dev_root ()); 6593ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 6603ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen mount_entry->device_path = g_strdup (mntent->mnt_fsname); 6613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type = g_strdup (mntent->mnt_type); 6623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_HASMNTOPT 6643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (hasmntopt (mntent, MNTOPT_RO) != NULL) 6653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_read_only = TRUE; 6663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (hasmntopt (mntent, "loop") != NULL) 6683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_loopback = TRUE; 6693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 6713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if ((mntent->mnt_type != NULL && strcmp ("supermount", mntent->mnt_type) == 0) 6733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_HASMNTOPT 6743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson || (hasmntopt (mntent, "user") != NULL 6753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson && hasmntopt (mntent, "user") != hasmntopt (mntent, "user_xattr")) 6763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson || hasmntopt (mntent, "pamconsole") != NULL 6773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson || hasmntopt (mntent, "users") != NULL 6783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson || hasmntopt (mntent, "owner") != NULL 6793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 6803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson ) 6813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_user_mountable = TRUE; 6823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = g_list_prepend (return_list, mount_entry); 6843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 6853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson endmntent (file); 6870766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen 6880766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#ifndef HAVE_GETMNTENT_R 6893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_UNLOCK (getmntent); 6900766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#endif 6913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return g_list_reverse (return_list); 6933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 6943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined (HAVE_SYS_MNTTAB_H) 6963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 6973781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList * 6983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mount_points (void) 6993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 7003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson struct mnttab mntent; 7013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson FILE *file; 7023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char *read_file; 7033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GUnixMountPoint *mount_entry; 7043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GList *return_list; 7053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson read_file = get_fstab_file (); 7073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson file = setmntent (read_file, "r"); 7093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (file == NULL) 7103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return NULL; 7113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = NULL; 7133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_LOCK (getmntent); 7153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson while (! getmntent (file, &mntent)) 7163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 7173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if ((strcmp (mntent.mnt_mountp, "ignore") == 0) || 7183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson (strcmp (mntent.mnt_mountp, "swap") == 0)) 7193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson continue; 7203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry = g_new0 (GUnixMountPoint, 1); 7223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->mount_path = g_strdup (mntent.mnt_mountp); 7243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->device_path = g_strdup (mntent.mnt_special); 7253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype); 7263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_HASMNTOPT 7283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (hasmntopt (&mntent, MNTOPT_RO) != NULL) 7293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_read_only = TRUE; 7303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (hasmntopt (&mntent, "lofs") != NULL) 7323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_loopback = TRUE; 7333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 7343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if ((mntent.mnt_fstype != NULL) 7363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_HASMNTOPT 7373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson || (hasmntopt (&mntent, "user") != NULL 7383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson && hasmntopt (&mntent, "user") != hasmntopt (&mntent, "user_xattr")) 7393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson || hasmntopt (&mntent, "pamconsole") != NULL 7403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson || hasmntopt (&mntent, "users") != NULL 7413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson || hasmntopt (&mntent, "owner") != NULL 7423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 7433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson ) 7443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_user_mountable = TRUE; 7453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = g_list_prepend (return_list, mount_entry); 7483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 7493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson endmntent (file); 7513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_UNLOCK (getmntent); 7523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return g_list_reverse (return_list); 7543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 7553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(HAVE_SYS_MNTCTL_H) && defined(HAVE_SYS_VMOUNT_H) && defined(HAVE_SYS_VFS_H) 7563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/* functions to parse /etc/filesystems on aix */ 7583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/* read character, ignoring comments (begin with '*', end with '\n' */ 7603781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic int 7613781343738de4abddf56982325a77bd70a98cd26Alexander Larssonaix_fs_getc (FILE *fd) 7623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 7633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson int c; 7643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson while ((c = getc (fd)) == '*') 7663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 7673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson while (((c = getc (fd)) != '\n') && (c != EOF)) 7683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson ; 7693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 7703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 7713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/* eat all continuous spaces in a file */ 7733781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic int 7743781343738de4abddf56982325a77bd70a98cd26Alexander Larssonaix_fs_ignorespace (FILE *fd) 7753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 7763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson int c; 7773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson while ((c = aix_fs_getc (fd)) != EOF) 7793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 7803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (!g_ascii_isspace (c)) 7813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 7823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson ungetc (c,fd); 7833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return c; 7843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 7853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 7863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return EOF; 7883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 7893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/* read one word from file */ 7913781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic int 792a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasenaix_fs_getword (FILE *fd, 793a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen char *word) 7943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 7953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson int c; 7963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson aix_fs_ignorespace (fd); 7983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 7993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson while (((c = aix_fs_getc (fd)) != EOF) && !g_ascii_isspace (c)) 8003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 8013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (c == '"') 8023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 8033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson while (((c = aix_fs_getc (fd)) != EOF) && (c != '"')) 8043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *word++ = c; 8053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else 8063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *word++ = c; 8073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 8083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 8093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *word = 0; 8103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return c; 8123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 8133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8143781343738de4abddf56982325a77bd70a98cd26Alexander Larssontypedef struct { 8153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char mnt_mount[PATH_MAX]; 8163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char mnt_special[PATH_MAX]; 8173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char mnt_fstype[16]; 8183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char mnt_options[128]; 8193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} AixMountTableEntry; 8203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/* read mount points properties */ 8223781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic int 823a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasenaix_fs_get (FILE *fd, 824a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen AixMountTableEntry *prop) 8253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 8263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson static char word[PATH_MAX] = { 0 }; 8273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char value[PATH_MAX]; 8283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson /* read stanza */ 8303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (word[0] == 0) 8313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 8323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (aix_fs_getword (fd, word) == EOF) 8333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return EOF; 8343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 8353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson word[strlen(word) - 1] = 0; 8373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson strcpy (prop->mnt_mount, word); 8383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson /* read attributes and value */ 8403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson while (aix_fs_getword (fd, word) != EOF) 8423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 8433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson /* test if is attribute or new stanza */ 8443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (word[strlen(word) - 1] == ':') 8453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return 0; 8463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson /* read "=" */ 8483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson aix_fs_getword (fd, value); 8493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson /* read value */ 8513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson aix_fs_getword (fd, value); 8523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (strcmp (word, "dev") == 0) 8543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson strcpy (prop->mnt_special, value); 8553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (strcmp (word, "vfs") == 0) 8563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson strcpy (prop->mnt_fstype, value); 8573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (strcmp (word, "options") == 0) 8583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson strcpy(prop->mnt_options, value); 8593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 8603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return 0; 8623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 8633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8643781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList * 8653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mount_points (void) 8663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 8673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson struct mntent *mntent; 8683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson FILE *file; 8693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char *read_file; 8703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GUnixMountPoint *mount_entry; 8713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson AixMountTableEntry mntent; 8723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GList *return_list; 8733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson read_file = get_fstab_file (); 8753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson file = setmntent (read_file, "r"); 8773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (file == NULL) 8783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return NULL; 8793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = NULL; 8813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson while (!aix_fs_get (file, &mntent)) 8833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 8843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (strcmp ("cdrfs", mntent.mnt_fstype) == 0) 8853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 8863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry = g_new0 (GUnixMountPoint, 1); 8873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->mount_path = g_strdup (mntent.mnt_mount); 8903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->device_path = g_strdup (mntent.mnt_special); 8913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type = g_strdup (mntent.mnt_fstype); 8923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_read_only = TRUE; 8933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_user_mountable = TRUE; 8943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = g_list_prepend (return_list, mount_entry); 8963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 8973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 8983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 8993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson endmntent (file); 9003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return g_list_reverse (return_list); 9023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 9033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(HAVE_GETMNTINFO) && defined(HAVE_FSTAB_H) && defined(HAVE_SYS_MOUNT_H) 9053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9063781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GList * 9073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson_g_get_unix_mount_points (void) 9083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 9093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson struct fstab *fstab = NULL; 9103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GUnixMountPoint *mount_entry; 9113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GList *return_list; 9123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_SYSCTL_H 9133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson int usermnt = 0; 9143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson size_t len = sizeof(usermnt); 9153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson struct stat sb; 9163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 9173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (!setfsent ()) 9193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return NULL; 9203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = NULL; 9223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_SYSCTL_H 9243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#if defined(HAVE_SYSCTLBYNAME) 9253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson sysctlbyname ("vfs.usermount", &usermnt, &len, NULL, 0); 9263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(CTL_VFS) && defined(VFS_USERMOUNT) 9273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 9283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson int mib[2]; 9293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mib[0] = CTL_VFS; 9313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mib[1] = VFS_USERMOUNT; 9323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson sysctl (mib, 2, &usermnt, &len, NULL, 0); 9333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 9343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#elif defined(CTL_KERN) && defined(KERN_USERMOUNT) 9353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 9363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson int mib[2]; 9373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mib[0] = CTL_KERN; 9393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mib[1] = KERN_USERMOUNT; 9403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson sysctl (mib, 2, &usermnt, &len, NULL, 0); 9413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 9423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 9433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 9443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson while ((fstab = getfsent ()) != NULL) 9463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 9473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (strcmp (fstab->fs_vfstype, "swap") == 0) 9483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson continue; 9493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry = g_new0 (GUnixMountPoint, 1); 9513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->mount_path = g_strdup (fstab->fs_file); 9533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->device_path = g_strdup (fstab->fs_spec); 9543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type = g_strdup (fstab->fs_vfstype); 9553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (strcmp (fstab->fs_type, "ro") == 0) 9573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_read_only = TRUE; 9583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#ifdef HAVE_SYS_SYSCTL_H 9603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (usermnt != 0) 9613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 9623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson uid_t uid = getuid (); 9633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (stat (fstab->fs_file, &sb) == 0) 9643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 9653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (uid == 0 || sb.st_uid == uid) 9663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->is_user_mountable = TRUE; 9673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 9683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 9693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 9703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return_list = g_list_prepend (return_list, mount_entry); 9723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 9733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson endfsent (); 9753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return g_list_reverse (return_list); 9773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 9783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#else 9793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#error No g_get_mount_table() implementation for system 9803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson#endif 9813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9823781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic guint64 9833781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mounts_timestamp (void) 9843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 9853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson const char *monitor_file; 9863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson struct stat buf; 9873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson monitor_file = get_mtab_monitor_file (); 9893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (monitor_file) 9903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 9913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (stat (monitor_file, &buf) == 0) 9923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return (guint64)buf.st_mtime; 9933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 9943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return 0; 9953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 9963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 9973781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic guint64 9983781343738de4abddf56982325a77bd70a98cd26Alexander Larssonget_mount_points_timestamp (void) 9993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 10003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson const char *monitor_file; 10013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson struct stat buf; 10023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 10033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson monitor_file = get_fstab_file (); 10043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (monitor_file) 10053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 10063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (stat (monitor_file, &buf) == 0) 10073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return (guint64)buf.st_mtime; 10083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 10093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return 0; 10103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 10113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 10123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 1013feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Clasen * g_unix_mounts_get: 10143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @time_read: guint64 to contain a timestamp. 10153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 1016442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * Gets a #GList of strings containing the unix mounts. 1017442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * If @time_read is set, it will be filled with the mount 1018442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * timestamp, allowing for checking if the mounts have changed 1019442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * with g_unix_mounts_changed_since(). 10205247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 10215247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a #GList of the UNIX mounts. 10223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 10233781343738de4abddf56982325a77bd70a98cd26Alexander LarssonGList * 1024feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Claseng_unix_mounts_get (guint64 *time_read) 10253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 10263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (time_read) 10273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *time_read = get_mounts_timestamp (); 10283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 10293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return _g_get_unix_mounts (); 10303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 10313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 10323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 1033feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Clasen * g_unix_mount_at: 10345247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_path: path for a possible unix mount. 10353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @time_read: guint64 to contain a timestamp. 10363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 10373ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * Gets a #GUnixMountEntry for a given mount path. If @time_read 10385247f12f3649726471080440de0d37b78c1cec33Andrew Walton * is set, it will be filled with a unix timestamp for checking 10395247f12f3649726471080440de0d37b78c1cec33Andrew Walton * if the mounts have changed since with g_unix_mounts_changed_since(). 10405247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 10415247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a #GUnixMount. 10423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 10433ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid ZeuthenGUnixMountEntry * 1044feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Claseng_unix_mount_at (const char *mount_path, 1045feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Clasen guint64 *time_read) 10463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 10473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GList *mounts, *l; 10483ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen GUnixMountEntry *mount_entry, *found; 10493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1050feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Clasen mounts = g_unix_mounts_get (time_read); 10513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 10523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson found = NULL; 10533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson for (l = mounts; l != NULL; l = l->next) 10543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 10553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry = l->data; 10563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1057a28d87bfc987d8b0aa27c6f9d996a31894fedf4aRyan Lortie if (!found && strcmp (mount_path, mount_entry->mount_path) == 0) 10583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson found = mount_entry; 10593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else 10603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_unix_mount_free (mount_entry); 10613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 10623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 10633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_list_free (mounts); 10643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 10653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return found; 10663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 10673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 10683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 1069feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Clasen * g_unix_mount_points_get: 10703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @time_read: guint64 to contain a timestamp. 10713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 10725247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets a #GList of strings containing the unix mount points. 10735247f12f3649726471080440de0d37b78c1cec33Andrew Walton * If @time_read is set, it will be filled with the mount timestamp, 10745247f12f3649726471080440de0d37b78c1cec33Andrew Walton * allowing for checking if the mounts have changed with 10755247f12f3649726471080440de0d37b78c1cec33Andrew Walton * g_unix_mounts_points_changed_since(). 10765247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 1077442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * Returns: a #GList of the UNIX mountpoints. 10783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 10793781343738de4abddf56982325a77bd70a98cd26Alexander LarssonGList * 1080feb5258cf9ca9c3b3d9a58a98b1c6c75c822855aMatthias Claseng_unix_mount_points_get (guint64 *time_read) 10813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 10823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (time_read) 10833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson *time_read = get_mount_points_timestamp (); 10843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 10853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return _g_get_unix_mount_points (); 10863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 10873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 10883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 10895247f12f3649726471080440de0d37b78c1cec33Andrew Walton * g_unix_mounts_changed_since: 10903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @time: guint64 to contain a timestamp. 10913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 10925247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if the unix mounts have changed since a given unix time. 10935247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 1094442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * Returns: %TRUE if the mounts have changed since @time. 10953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 10963781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean 10973781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mounts_changed_since (guint64 time) 10983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 10993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return get_mounts_timestamp () != time; 11003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 11013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 11023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 11035247f12f3649726471080440de0d37b78c1cec33Andrew Walton * g_unix_mount_points_changed_since: 11043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @time: guint64 to contain a timestamp. 11053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 11065247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if the unix mount points have changed since a given unix time. 11075247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 1108442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * Returns: %TRUE if the mount points have changed since @time. 11093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 11103781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean 11113781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_points_changed_since (guint64 time) 11123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 11133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return get_mount_points_timestamp () != time; 11143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 11153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 11163781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic void 11173781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_monitor_finalize (GObject *object) 11183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 11193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GUnixMountMonitor *monitor; 11203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 11213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson monitor = G_UNIX_MOUNT_MONITOR (object); 11223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 11233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (monitor->fstab_monitor) 11243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 11253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_file_monitor_cancel (monitor->fstab_monitor); 11263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_object_unref (monitor->fstab_monitor); 11273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 11283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 11293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (monitor->mtab_monitor) 11303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 11313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_file_monitor_cancel (monitor->mtab_monitor); 11323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_object_unref (monitor->mtab_monitor); 11333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 11343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 11353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson the_mount_monitor = NULL; 1136a4427bfff5d31499dc0b46fa3f734bc92f7d0dd5Michael Natterer 1137a4427bfff5d31499dc0b46fa3f734bc92f7d0dd5Michael Natterer G_OBJECT_CLASS (g_unix_mount_monitor_parent_class)->finalize (object); 11383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 11393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 11403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 11413781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic void 11423781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_monitor_class_init (GUnixMountMonitorClass *klass) 11433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 11443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GObjectClass *gobject_class = G_OBJECT_CLASS (klass); 11453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 11463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson gobject_class->finalize = g_unix_mount_monitor_finalize; 11475247f12f3649726471080440de0d37b78c1cec33Andrew Walton /** 11485247f12f3649726471080440de0d37b78c1cec33Andrew Walton * GUnixMountMonitor::mounts-changed: 1149c723669198d1848f553a8e7fdb130ba8cf0e0253Matthias Clasen * @monitor: the object on which the signal is emitted 11505247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 11515247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Emitted when the unix mounts have changed. 11525247f12f3649726471080440de0d37b78c1cec33Andrew Walton **/ 11533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson signals[MOUNTS_CHANGED] = 11548d37a7964d3b41de330aa581b61eda374b093e71Sven Neumann g_signal_new ("mounts-changed", 11553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_TYPE_FROM_CLASS (klass), 11563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_SIGNAL_RUN_LAST, 11573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 0, 11583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson NULL, NULL, 11593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_cclosure_marshal_VOID__VOID, 11603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_TYPE_NONE, 0); 11615247f12f3649726471080440de0d37b78c1cec33Andrew Walton /** 11625247f12f3649726471080440de0d37b78c1cec33Andrew Walton * GUnixMountMonitor::mountpoints-changed: 1163c723669198d1848f553a8e7fdb130ba8cf0e0253Matthias Clasen * @monitor: the object on which the signal is emitted 11645247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 11655247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Emitted when the unix mount points have changed. 11665247f12f3649726471080440de0d37b78c1cec33Andrew Walton **/ 11673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson signals[MOUNTPOINTS_CHANGED] = 11688d37a7964d3b41de330aa581b61eda374b093e71Sven Neumann g_signal_new ("mountpoints-changed", 11693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_TYPE_FROM_CLASS (klass), 11703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_SIGNAL_RUN_LAST, 11713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 0, 11723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson NULL, NULL, 11733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_cclosure_marshal_VOID__VOID, 11743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson G_TYPE_NONE, 0); 11753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 11763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 11773781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic void 1178a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasenfstab_file_changed (GFileMonitor *monitor, 1179a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen GFile *file, 1180a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen GFile *other_file, 1181a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen GFileMonitorEvent event_type, 1182a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen gpointer user_data) 11833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 11843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GUnixMountMonitor *mount_monitor; 11853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 11863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (event_type != G_FILE_MONITOR_EVENT_CHANGED && 11873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson event_type != G_FILE_MONITOR_EVENT_CREATED && 11883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson event_type != G_FILE_MONITOR_EVENT_DELETED) 11893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return; 11903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 11913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_monitor = user_data; 11923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_signal_emit (mount_monitor, signals[MOUNTPOINTS_CHANGED], 0); 11933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 11943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 11953781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic void 1196a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasenmtab_file_changed (GFileMonitor *monitor, 1197a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen GFile *file, 1198a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen GFile *other_file, 1199a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen GFileMonitorEvent event_type, 1200a2ca589703273fca80cb126430a8b058aba3eb52Matthias Clasen gpointer user_data) 12013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 12023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GUnixMountMonitor *mount_monitor; 12033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 12043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (event_type != G_FILE_MONITOR_EVENT_CHANGED && 12053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson event_type != G_FILE_MONITOR_EVENT_CREATED && 12063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson event_type != G_FILE_MONITOR_EVENT_DELETED) 12073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return; 12083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 12093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_monitor = user_data; 12103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_signal_emit (mount_monitor, signals[MOUNTS_CHANGED], 0); 12113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 12123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 12133781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic void 12143781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_monitor_init (GUnixMountMonitor *monitor) 12153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 12163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GFile *file; 12173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 12183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (get_fstab_file () != NULL) 12193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 12203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson file = g_file_new_for_path (get_fstab_file ()); 12213690cb75a67377a169264e226655d8fa3a5d003aAlexander Larsson monitor->fstab_monitor = g_file_monitor_file (file, 0, NULL, NULL); 12223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_object_unref (file); 12233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 12243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_signal_connect (monitor->fstab_monitor, "changed", (GCallback)fstab_file_changed, monitor); 12253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 12263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 12273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (get_mtab_monitor_file () != NULL) 12283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 12293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson file = g_file_new_for_path (get_mtab_monitor_file ()); 12303690cb75a67377a169264e226655d8fa3a5d003aAlexander Larsson monitor->mtab_monitor = g_file_monitor_file (file, 0, NULL, NULL); 12313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_object_unref (file); 12323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 12333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_signal_connect (monitor->mtab_monitor, "changed", (GCallback)mtab_file_changed, monitor); 12343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 12353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 12363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 12373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 123851d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen * g_unix_mount_monitor_set_rate_limit: 1239ee96535cec0c02bbe15688489654e816dd5c1e7aMatthias Clasen * @mount_monitor: a #GUnixMountMonitor 1240ee96535cec0c02bbe15688489654e816dd5c1e7aMatthias Clasen * @limit_msec: a integer with the limit in milliseconds to 1241ee96535cec0c02bbe15688489654e816dd5c1e7aMatthias Clasen * poll for changes. 124251d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen * 124351d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen * Sets the rate limit to which the @mount_monitor will report 124451d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen * consecutive change events to the mount and mount point entry files. 124551d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen * 124651d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen * Since: 2.18 124751d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen **/ 124851d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthenvoid 124951d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeutheng_unix_mount_monitor_set_rate_limit (GUnixMountMonitor *mount_monitor, 125051d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen int limit_msec) 125151d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen{ 125251d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen g_return_if_fail (G_IS_UNIX_MOUNT_MONITOR (mount_monitor)); 125351d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen 125451d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen if (mount_monitor->fstab_monitor != NULL) 125551d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen g_file_monitor_set_rate_limit (mount_monitor->fstab_monitor, limit_msec); 125651d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen 125751d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen if (mount_monitor->mtab_monitor != NULL) 125851d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen g_file_monitor_set_rate_limit (mount_monitor->mtab_monitor, limit_msec); 125951d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen} 126051d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen 126151d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen/** 12623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_monitor_new: 12633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 126451d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen * Gets a new #GUnixMountMonitor. The default rate limit for which the 126551d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen * monitor will report consecutive changes for the mount and mount 126651d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen * point entry files is the default for a #GFileMonitor. Use 126751d7fc9e965c64da40597d007756d330b5e3cc5fDavid Zeuthen * g_unix_mount_monitor_set_rate_limit() to change this. 12685247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 12695247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a #GUnixMountMonitor. 12703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 12713781343738de4abddf56982325a77bd70a98cd26Alexander LarssonGUnixMountMonitor * 12723781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_monitor_new (void) 12733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 12743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (the_mount_monitor == NULL) 12753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 12763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson the_mount_monitor = g_object_new (G_TYPE_UNIX_MOUNT_MONITOR, NULL); 12773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return the_mount_monitor; 12783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 12793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 12803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return g_object_ref (the_mount_monitor); 12813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 12823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 12833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 12843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_free: 12853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount_entry: a #GUnixMount. 12863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 12875247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Frees a unix mount. 12883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 12893781343738de4abddf56982325a77bd70a98cd26Alexander Larssonvoid 12903ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_free (GUnixMountEntry *mount_entry) 12913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 12923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_if_fail (mount_entry != NULL); 12933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 12943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_free (mount_entry->mount_path); 12953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_free (mount_entry->device_path); 12963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_free (mount_entry->filesystem_type); 12973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_free (mount_entry); 12983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 12993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 13003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 13013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_free: 13025247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: unix mount point to free. 13033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 13045247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Frees a unix mount point. 13053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 13063781343738de4abddf56982325a77bd70a98cd26Alexander Larssonvoid 13073781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_free (GUnixMountPoint *mount_point) 13083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 13093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_if_fail (mount_point != NULL); 13103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 13113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_free (mount_point->mount_path); 13123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_free (mount_point->device_path); 13133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_free (mount_point->filesystem_type); 13143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_free (mount_point); 13153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 13163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 13173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 13183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_compare: 13193ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @mount1: first #GUnixMountEntry to compare. 13203ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @mount2: second #GUnixMountEntry to compare. 13213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 13225247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Compares two unix mounts. 13235247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 1324442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * Returns: 1, 0 or -1 if @mount1 is greater than, equal to, 13253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * or less than @mount2, respectively. 13263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 13273781343738de4abddf56982325a77bd70a98cd26Alexander Larssongint 13283ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_compare (GUnixMountEntry *mount1, 13293ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen GUnixMountEntry *mount2) 13303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 13313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson int res; 13323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 13333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount1 != NULL && mount2 != NULL, 0); 13343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 133520174898b5b1014f5f125811d1d92f1b017bdbbcMatthias Clasen res = g_strcmp0 (mount1->mount_path, mount2->mount_path); 13363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (res != 0) 13373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return res; 13383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 133920174898b5b1014f5f125811d1d92f1b017bdbbcMatthias Clasen res = g_strcmp0 (mount1->device_path, mount2->device_path); 13403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (res != 0) 13413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return res; 13423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 134320174898b5b1014f5f125811d1d92f1b017bdbbcMatthias Clasen res = g_strcmp0 (mount1->filesystem_type, mount2->filesystem_type); 13443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (res != 0) 13453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return res; 13463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 13473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson res = mount1->is_read_only - mount2->is_read_only; 13483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (res != 0) 13493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return res; 13503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 13513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return 0; 13523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 13533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 13543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 13553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_get_mount_path: 13563ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * @mount_entry: input #GUnixMountEntry to get the mount path for. 13573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 13585247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets the mount path for a unix mount. 13593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 13605247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: the mount path for @mount_entry. 13613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 13623781343738de4abddf56982325a77bd70a98cd26Alexander Larssonconst char * 13633ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_get_mount_path (GUnixMountEntry *mount_entry) 13643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 13653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_entry != NULL, NULL); 13663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 13673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return mount_entry->mount_path; 13683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 13693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 13703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 13713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_get_device_path: 13723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount_entry: a #GUnixMount. 13733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 13745247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets the device path for a unix mount. 13755247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 13765247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a string containing the device path. 13773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 13783781343738de4abddf56982325a77bd70a98cd26Alexander Larssonconst char * 13793ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_get_device_path (GUnixMountEntry *mount_entry) 13803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 13813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_entry != NULL, NULL); 13823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 13833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return mount_entry->device_path; 13843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 13853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 13863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 13873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_get_fs_type: 13883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount_entry: a #GUnixMount. 13893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 13905247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets the filesystem type for the unix mount. 13915247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 13925247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a string containing the file system type. 13933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 13943781343738de4abddf56982325a77bd70a98cd26Alexander Larssonconst char * 13953ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_get_fs_type (GUnixMountEntry *mount_entry) 13963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 13973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_entry != NULL, NULL); 13983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 13993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return mount_entry->filesystem_type; 14003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 14013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 14023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 14033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_is_readonly: 14043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount_entry: a #GUnixMount. 14053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 14065247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if a unix mount is mounted read only. 14073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 14085247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: %TRUE if @mount_entry is read only. 14093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 14103781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean 14113ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_is_readonly (GUnixMountEntry *mount_entry) 14123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 14133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_entry != NULL, FALSE); 14143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 14153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return mount_entry->is_read_only; 14163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 14173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 14183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 14193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_is_system_internal: 14203781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount_entry: a #GUnixMount. 14213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 14225247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if a unix mount is a system path. 14235247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 14245247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: %TRUE if the unix mount is for a system path. 14253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 14263781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean 14273ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_is_system_internal (GUnixMountEntry *mount_entry) 14283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 14293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_entry != NULL, FALSE); 14303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 14313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return mount_entry->is_system_internal; 14323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 14333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 14343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 14353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_compare: 14363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount1: a #GUnixMount. 14373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount2: a #GUnixMount. 14383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 14395247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Compares two unix mount points. 14405247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 1441442e8df1b833e3311a214ae1bf02337b0c831544Matthias Clasen * Returns: 1, 0 or -1 if @mount1 is greater than, equal to, 14423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * or less than @mount2, respectively. 14433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 14443781343738de4abddf56982325a77bd70a98cd26Alexander Larssongint 14453781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_compare (GUnixMountPoint *mount1, 14463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GUnixMountPoint *mount2) 14473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 14483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson int res; 14493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 14503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount1 != NULL && mount2 != NULL, 0); 14513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 145220174898b5b1014f5f125811d1d92f1b017bdbbcMatthias Clasen res = g_strcmp0 (mount1->mount_path, mount2->mount_path); 14533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (res != 0) 14543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return res; 14553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 145620174898b5b1014f5f125811d1d92f1b017bdbbcMatthias Clasen res = g_strcmp0 (mount1->device_path, mount2->device_path); 14573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (res != 0) 14583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return res; 14593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 146020174898b5b1014f5f125811d1d92f1b017bdbbcMatthias Clasen res = g_strcmp0 (mount1->filesystem_type, mount2->filesystem_type); 14613781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (res != 0) 14623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return res; 14633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 14643781343738de4abddf56982325a77bd70a98cd26Alexander Larsson res = mount1->is_read_only - mount2->is_read_only; 14653781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (res != 0) 14663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return res; 14673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 14683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson res = mount1->is_user_mountable - mount2->is_user_mountable; 14693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (res != 0) 14703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return res; 14713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 14723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson res = mount1->is_loopback - mount2->is_loopback; 14733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (res != 0) 14743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return res; 14753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 14763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return 0; 14773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 14783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 14793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 14803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_get_mount_path: 14815247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint. 14825247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 14835247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets the mount path for a unix mount point. 14843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 14855247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a string containing the mount path. 14863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 14873781343738de4abddf56982325a77bd70a98cd26Alexander Larssonconst char * 14883781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_get_mount_path (GUnixMountPoint *mount_point) 14893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 14903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_point != NULL, NULL); 14913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 14923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return mount_point->mount_path; 14933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 14943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 14953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 14963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_get_device_path: 14975247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint. 14985247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 14995247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets the device path for a unix mount point. 15003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 15015247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a string containing the device path. 15023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 15033781343738de4abddf56982325a77bd70a98cd26Alexander Larssonconst char * 15043781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_get_device_path (GUnixMountPoint *mount_point) 15053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 15063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_point != NULL, NULL); 15073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 15083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return mount_point->device_path; 15093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 15103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 15113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 15123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_get_fs_type: 15135247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint. 15143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 15155247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Gets the file system type for the mount point. 15165247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 15175247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a string containing the file system type. 15183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 15193781343738de4abddf56982325a77bd70a98cd26Alexander Larssonconst char * 15203781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_get_fs_type (GUnixMountPoint *mount_point) 15213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 15223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_point != NULL, NULL); 15233781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 15243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return mount_point->filesystem_type; 15253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 15263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 15273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 15283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_is_readonly: 15295247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint. 15305247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 15315247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if a unix mount point is read only. 15323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 15335247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: %TRUE if a mount point is read only. 15343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 15353781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean 15363781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_is_readonly (GUnixMountPoint *mount_point) 15373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 15383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_point != NULL, FALSE); 15393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 15403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return mount_point->is_read_only; 15413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 15423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 15433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 15443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_is_user_mountable: 15455247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint. 15465247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 15475247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if a unix mount point is mountable by the user. 15483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 15495247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: %TRUE if the mount point is user mountable. 15503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 15513781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean 15523781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_is_user_mountable (GUnixMountPoint *mount_point) 15533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 15543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_point != NULL, FALSE); 15553781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 15563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return mount_point->is_user_mountable; 15573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 15583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 15593781343738de4abddf56982325a77bd70a98cd26Alexander Larsson/** 15603781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_is_loopback: 15615247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint. 15623781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 15635247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Checks if a unix mount point is a loopback device. 15645247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 15655247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: %TRUE if the mount point is a loopback. %FALSE otherwise. 15663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 15673781343738de4abddf56982325a77bd70a98cd26Alexander Larssongboolean 15683781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_is_loopback (GUnixMountPoint *mount_point) 15693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 15703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_point != NULL, FALSE); 15713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 15723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return mount_point->is_loopback; 15733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 15743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 15753781343738de4abddf56982325a77bd70a98cd26Alexander Larssonstatic GUnixMountType 15763781343738de4abddf56982325a77bd70a98cd26Alexander Larssonguess_mount_type (const char *mount_path, 15773781343738de4abddf56982325a77bd70a98cd26Alexander Larsson const char *device_path, 15783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson const char *filesystem_type) 15793781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 15803781343738de4abddf56982325a77bd70a98cd26Alexander Larsson GUnixMountType type; 15813781343738de4abddf56982325a77bd70a98cd26Alexander Larsson char *basename; 15823781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 15833781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_UNKNOWN; 15843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 15853781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if ((strcmp (filesystem_type, "udf") == 0) || 15863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson (strcmp (filesystem_type, "iso9660") == 0) || 15873781343738de4abddf56982325a77bd70a98cd26Alexander Larsson (strcmp (filesystem_type, "cd9660") == 0)) 15883781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_CDROM; 1589864b0d690edd5ba945571bb3715e71b5e5b1f65bSebastien Bacher else if ((strcmp (filesystem_type, "nfs") == 0) || 1590864b0d690edd5ba945571bb3715e71b5e5b1f65bSebastien Bacher (strcmp (filesystem_type, "nfs4") == 0)) 15913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_NFS; 15923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (device_path, "/vol/dev/diskette/") || 15933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_str_has_prefix (device_path, "/dev/fd") || 15943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_str_has_prefix (device_path, "/dev/floppy")) 15953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_FLOPPY; 15963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (device_path, "/dev/cdrom") || 15973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_str_has_prefix (device_path, "/dev/acd") || 15983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_str_has_prefix (device_path, "/dev/cd")) 15993781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_CDROM; 16003781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (device_path, "/vol/")) 16013781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 16023781343738de4abddf56982325a77bd70a98cd26Alexander Larsson const char *name = mount_path + strlen ("/"); 16033781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 16043781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (g_str_has_prefix (name, "cdrom")) 16053781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_CDROM; 16063781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (name, "floppy") || 16073781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_str_has_prefix (device_path, "/vol/dev/diskette/")) 16083781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_FLOPPY; 16093781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (name, "rmdisk")) 16103781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_ZIP; 16113781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (name, "jaz")) 16123781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_JAZ; 16133781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (name, "memstick")) 16143781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_MEMSTICK; 16153781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 16163781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else 16173781343738de4abddf56982325a77bd70a98cd26Alexander Larsson { 16183781343738de4abddf56982325a77bd70a98cd26Alexander Larsson basename = g_path_get_basename (mount_path); 16193781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1620240ba02786e2ce0fe17327e1901d8e6fe06e812eAlexander Larsson if (g_str_has_prefix (basename, "cdr") || 16213781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_str_has_prefix (basename, "cdwriter") || 16223781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_str_has_prefix (basename, "burn") || 1623240ba02786e2ce0fe17327e1901d8e6fe06e812eAlexander Larsson g_str_has_prefix (basename, "dvdr")) 16243781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_CDROM; 16253781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (basename, "floppy")) 16263781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_FLOPPY; 16273781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (basename, "zip")) 16283781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_ZIP; 16293781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (basename, "jaz")) 16303781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_JAZ; 16313781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (basename, "camera")) 16323781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_CAMERA; 16333781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (basename, "memstick") || 16343781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_str_has_prefix (basename, "memory_stick") || 16353781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_str_has_prefix (basename, "ram")) 16363781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_MEMSTICK; 16373781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (basename, "compact_flash")) 16383781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_CF; 16393781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (basename, "smart_media")) 16403781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_SM; 16413781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (basename, "sd_mmc")) 16423781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_SDMMC; 16433781343738de4abddf56982325a77bd70a98cd26Alexander Larsson else if (g_str_has_prefix (basename, "ipod")) 16443781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_IPOD; 16453781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 16463781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_free (basename); 16473781343738de4abddf56982325a77bd70a98cd26Alexander Larsson } 16483781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 16493781343738de4abddf56982325a77bd70a98cd26Alexander Larsson if (type == G_UNIX_MOUNT_TYPE_UNKNOWN) 16503781343738de4abddf56982325a77bd70a98cd26Alexander Larsson type = G_UNIX_MOUNT_TYPE_HD; 16513781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 16523781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return type; 16533781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 16543781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1655f5063650794c987868830241a630993e624eabd9Alexander Larsson/* 16563781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_guess_type: 16573781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * @mount_entry: a #GUnixMount. 16583781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 16595247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Guesses the type of a unix mount. If the mount type cannot be 16605247f12f3649726471080440de0d37b78c1cec33Andrew Walton * determined, returns %G_UNIX_MOUNT_TYPE_UNKNOWN. 16615247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 16625247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a #GUnixMountType. 16633781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 1664f5063650794c987868830241a630993e624eabd9Alexander Larssonstatic GUnixMountType 16653ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_guess_type (GUnixMountEntry *mount_entry) 16663781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 16673781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_entry != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN); 16683781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_entry->mount_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN); 16693781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_entry->device_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN); 16703781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_entry->filesystem_type != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN); 16713781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 16723781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return guess_mount_type (mount_entry->mount_path, 16733781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->device_path, 16743781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_entry->filesystem_type); 16753781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 16763781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 1677f5063650794c987868830241a630993e624eabd9Alexander Larsson/* 16783781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * g_unix_mount_point_guess_type: 16795247f12f3649726471080440de0d37b78c1cec33Andrew Walton * @mount_point: a #GUnixMountPoint. 16805247f12f3649726471080440de0d37b78c1cec33Andrew Walton * 16812e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Guesses the type of a unix mount point. 16822e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * If the mount type cannot be determined, 16832e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * returns %G_UNIX_MOUNT_TYPE_UNKNOWN. 16843781343738de4abddf56982325a77bd70a98cd26Alexander Larsson * 16855247f12f3649726471080440de0d37b78c1cec33Andrew Walton * Returns: a #GUnixMountType. 16863781343738de4abddf56982325a77bd70a98cd26Alexander Larsson **/ 1687f5063650794c987868830241a630993e624eabd9Alexander Larssonstatic GUnixMountType 16883781343738de4abddf56982325a77bd70a98cd26Alexander Larssong_unix_mount_point_guess_type (GUnixMountPoint *mount_point) 16893781343738de4abddf56982325a77bd70a98cd26Alexander Larsson{ 16903781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_point != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN); 16913781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_point->mount_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN); 16923781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_point->device_path != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN); 16933781343738de4abddf56982325a77bd70a98cd26Alexander Larsson g_return_val_if_fail (mount_point->filesystem_type != NULL, G_UNIX_MOUNT_TYPE_UNKNOWN); 16943781343738de4abddf56982325a77bd70a98cd26Alexander Larsson 16953781343738de4abddf56982325a77bd70a98cd26Alexander Larsson return guess_mount_type (mount_point->mount_path, 16963781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_point->device_path, 16973781343738de4abddf56982325a77bd70a98cd26Alexander Larsson mount_point->filesystem_type); 16983781343738de4abddf56982325a77bd70a98cd26Alexander Larsson} 16997f3280230bc9448a5750fc17a6eabef691ba25f4Alexander Larsson 17003ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenstatic const char * 17013ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthentype_to_icon (GUnixMountType type, gboolean is_mount_point) 17023ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{ 17033ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen const char *icon_name; 17043ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 17053ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen switch (type) 17063ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen { 17073ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen case G_UNIX_MOUNT_TYPE_HD: 17083ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (is_mount_point) 17093ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "drive-removable-media"; 17103ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 17113ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "drive-harddisk"; 17123ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen break; 17133ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen case G_UNIX_MOUNT_TYPE_FLOPPY: 17143ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen case G_UNIX_MOUNT_TYPE_ZIP: 17153ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen case G_UNIX_MOUNT_TYPE_JAZ: 17163ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (is_mount_point) 17173ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "drive-removable-media"; 17183ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 17193ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "media-floppy"; 17203ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen break; 17213ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen case G_UNIX_MOUNT_TYPE_CDROM: 17223ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (is_mount_point) 17233ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "drive-optical"; 17243ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 17253ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "media-optical"; 17263ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen break; 17273ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen case G_UNIX_MOUNT_TYPE_NFS: 17283ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen /* TODO: Would like a better icon here... */ 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 case G_UNIX_MOUNT_TYPE_MEMSTICK: 17353ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (is_mount_point) 17363ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "drive-removable-media"; 17373ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 17383ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "media-flash"; 17393ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen break; 17403ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen case G_UNIX_MOUNT_TYPE_CAMERA: 17413ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (is_mount_point) 17423ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "drive-removable-media"; 17433ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 17443ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "camera-photo"; 17453ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen break; 17463ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen case G_UNIX_MOUNT_TYPE_IPOD: 17473ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (is_mount_point) 17483ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "drive-removable-media"; 17493ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 17503ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "multimedia-player"; 17513ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen break; 17523ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen case G_UNIX_MOUNT_TYPE_UNKNOWN: 17533ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen default: 17543ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (is_mount_point) 17553ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "drive-removable-media"; 17563ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 17573ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen icon_name = "drive-harddisk"; 17583ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen break; 17593ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 17603ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 17613ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen return icon_name; 17623ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen} 17633ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 17642e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen/** 17652e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * g_unix_mount_guess_name: 17662e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * @mount_entry: a #GUnixMountEntry 17672e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * 17682e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Guesses the name of a Unix mount. 17692e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * The result is a translated string. 17702e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * 17712e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Returns: A newly allocated string that must 17722e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * be freed with g_free() 17732e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen */ 17743ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenchar * 17753ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_guess_name (GUnixMountEntry *mount_entry) 17763ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{ 17773ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen char *name; 17783ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 17793ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (strcmp (mount_entry->mount_path, "/") == 0) 17803ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen name = g_strdup (_("Filesystem root")); 17813ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 17823ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen name = g_filename_display_basename (mount_entry->mount_path); 17833ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 17843ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen return name; 17853ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen} 17863ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 17872e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen/** 17882e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * g_unix_mount_guess_icon: 17892e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * @mount_entry: a #GUnixMountEntry 17902e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * 17912e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Guesses the icon of a Unix mount. 17922e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * 17932e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Returns: a #GIcon 17942e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen */ 17953ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid ZeuthenGIcon * 17963ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_guess_icon (GUnixMountEntry *mount_entry) 17973ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{ 179847b8809e176f4bc7f22768cb45fec47280c4242fAlexander Larsson return g_themed_icon_new_with_default_fallbacks (type_to_icon (g_unix_mount_guess_type (mount_entry), FALSE)); 17993ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen} 18003ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 18012e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen/** 18022e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * g_unix_mount_point_guess_name: 18032e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * @mount_point: a #GUnixMountPoint 18042e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * 18052e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Guesses the name of a Unix mount point. 18062e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * The result is a translated string. 18072e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * 18082e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Returns: A newly allocated string that must 18092e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * be freed with g_free() 18102e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen */ 18113ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenchar * 18123ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_point_guess_name (GUnixMountPoint *mount_point) 18133ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{ 18143ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen char *name; 18153ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 18163ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (strcmp (mount_point->mount_path, "/") == 0) 18173ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen name = g_strdup (_("Filesystem root")); 18183ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 18193ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen name = g_filename_display_basename (mount_point->mount_path); 18203ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 18213ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen return name; 18223ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen} 18233ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 18242e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen/** 18252e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * g_unix_mount_point_guess_icon: 18262e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * @mount_point: a #GUnixMountPoint 18272e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * 18282e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Guesses the icon of a Unix mount point. 18292e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * 18302e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen * Returns: a #GIcon 18312e3f48993ddf2a18eff36f3e4eae10da0207e510Matthias Clasen */ 18323ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid ZeuthenGIcon * 18333ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeutheng_unix_mount_point_guess_icon (GUnixMountPoint *mount_point) 18343ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{ 183547b8809e176f4bc7f22768cb45fec47280c4242fAlexander Larsson return g_themed_icon_new_with_default_fallbacks (type_to_icon (g_unix_mount_point_guess_type (mount_point), TRUE)); 18363ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen} 18373ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 1838c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen/** 1839c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * g_unix_mount_guess_can_eject: 1840c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * @mount_entry: a #GUnixMountEntry 1841c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * 1842c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * Guesses whether a Unix mount can be ejected. 1843c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * 1844c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * Returns: %TRUE if @mount_entry is deemed to be ejectable. 1845c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen */ 1846f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthengboolean 1847f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeutheng_unix_mount_guess_can_eject (GUnixMountEntry *mount_entry) 1848f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen{ 1849f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen GUnixMountType guessed_type; 1850f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen 1851f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen guessed_type = g_unix_mount_guess_type (mount_entry); 1852f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen if (guessed_type == G_UNIX_MOUNT_TYPE_IPOD || 1853f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen guessed_type == G_UNIX_MOUNT_TYPE_CDROM) 1854f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen return TRUE; 1855f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen 1856f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen return FALSE; 1857f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen} 1858f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen 1859c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen/** 1860896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson * g_unix_mount_guess_should_display: 1861896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson * @mount_entry: a #GUnixMountEntry 1862896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson * 1863896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson * Guesses whether a Unix mount should be displayed in the UI. 1864896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson * 1865896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson * Returns: %TRUE if @mount_entry is deemed to be displayable. 1866896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson */ 1867896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larssongboolean 1868896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larssong_unix_mount_guess_should_display (GUnixMountEntry *mount_entry) 1869896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson{ 18704a1cf45793e3e7ef5d94c10cd2331c6085423058Alexander Larsson const char *mount_path; 1871896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson 1872896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson /* Never display internal mountpoints */ 1873896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson if (g_unix_mount_is_system_internal (mount_entry)) 1874896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson return FALSE; 18754a1cf45793e3e7ef5d94c10cd2331c6085423058Alexander Larsson 18764a1cf45793e3e7ef5d94c10cd2331c6085423058Alexander Larsson /* Only display things in /media (which are generally user mountable) 18774a1cf45793e3e7ef5d94c10cd2331c6085423058Alexander Larsson and home dir (fuse stuff) */ 18784a1cf45793e3e7ef5d94c10cd2331c6085423058Alexander Larsson mount_path = mount_entry->mount_path; 18794a1cf45793e3e7ef5d94c10cd2331c6085423058Alexander Larsson if (mount_path != NULL) 18804a1cf45793e3e7ef5d94c10cd2331c6085423058Alexander Larsson { 188127dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen if (g_str_has_prefix (mount_path, "/media/")) { 188227dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen char *path; 188327dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen /* Avoid displaying mounts that are not accessible to the user. 188427dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen * 188527dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen * See http://bugzilla.gnome.org/show_bug.cgi?id=526320 for why we 188608b1ec389b00d8d60b22ad5b25256831f9fc295cMatthias Clasen * want to avoid g_access() for mount points which can potentially 188708b1ec389b00d8d60b22ad5b25256831f9fc295cMatthias Clasen * block or fail stat()'ing, such as network mounts. 188827dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen */ 188927dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen path = g_path_get_dirname (mount_path); 189027dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen if (g_str_has_prefix (path, "/media/")) 189127dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen { 189227dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen if (g_access (path, R_OK|X_OK) != 0) { 189327dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen g_free (path); 189427dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen return FALSE; 189527dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen } 189627dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen } 189727dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen g_free (path); 189808b1ec389b00d8d60b22ad5b25256831f9fc295cMatthias Clasen 189908b1ec389b00d8d60b22ad5b25256831f9fc295cMatthias Clasen if (mount_entry->device_path && mount_entry->device_path[0] == '/') 190008b1ec389b00d8d60b22ad5b25256831f9fc295cMatthias Clasen { 190108b1ec389b00d8d60b22ad5b25256831f9fc295cMatthias Clasen struct stat st; 190208b1ec389b00d8d60b22ad5b25256831f9fc295cMatthias Clasen if (g_stat (mount_entry->device_path, &st) == 0 && 190308b1ec389b00d8d60b22ad5b25256831f9fc295cMatthias Clasen S_ISBLK(st.st_mode) && 190408b1ec389b00d8d60b22ad5b25256831f9fc295cMatthias Clasen g_access (mount_path, R_OK|X_OK) != 0) 190508b1ec389b00d8d60b22ad5b25256831f9fc295cMatthias Clasen return FALSE; 190608b1ec389b00d8d60b22ad5b25256831f9fc295cMatthias Clasen } 19074a1cf45793e3e7ef5d94c10cd2331c6085423058Alexander Larsson return TRUE; 190827dba4c28b9276a4ce3c67e1777fa259931b1d82David Zeuthen } 19094a1cf45793e3e7ef5d94c10cd2331c6085423058Alexander Larsson 1910087bf32df3aff81a81a94153f09280706a7e732cSebastien Bacher if (g_str_has_prefix (mount_path, g_get_home_dir ()) && mount_path[strlen (g_get_home_dir())] == G_DIR_SEPARATOR) 19114a1cf45793e3e7ef5d94c10cd2331c6085423058Alexander Larsson return TRUE; 19124a1cf45793e3e7ef5d94c10cd2331c6085423058Alexander Larsson } 19134a1cf45793e3e7ef5d94c10cd2331c6085423058Alexander Larsson 1914896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson return FALSE; 1915896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson} 1916896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson 1917896ebed1a57623ec5e0b08ba2bec3e37c1c88d41Alexander Larsson/** 1918c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * g_unix_mount_point_guess_can_eject: 1919c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * @mount_point: a #GUnixMountPoint 1920c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * 1921c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * Guesses whether a Unix mount point can be ejected. 1922c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * 1923c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen * Returns: %TRUE if @mount_point is deemed to be ejectable. 1924c014e5f8deecbb85966d99fb3aa46d10c674c322Matthias Clasen */ 1925f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthengboolean 1926f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeutheng_unix_mount_point_guess_can_eject (GUnixMountPoint *mount_point) 1927f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen{ 1928f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen GUnixMountType guessed_type; 1929f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen 1930f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen guessed_type = g_unix_mount_point_guess_type (mount_point); 1931f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen if (guessed_type == G_UNIX_MOUNT_TYPE_IPOD || 1932f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen guessed_type == G_UNIX_MOUNT_TYPE_CDROM) 1933f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen return TRUE; 1934f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen 1935f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen return FALSE; 1936f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen} 1937f4add8f0faf4a8c2ca1cdb4f99f5f3d0d66aaff8David Zeuthen 19383ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 19393ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen/* borrowed from gtk/gtkfilesystemunix.c in GTK+ on 02/23/2006 */ 19403ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenstatic void 19413ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen_canonicalize_filename (gchar *filename) 19423ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{ 19433ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen gchar *p, *q; 19443ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen gboolean last_was_slash = FALSE; 19453ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 19463ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen p = filename; 19473ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen q = filename; 19483ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 19493ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen while (*p) 19503ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen { 19513ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (*p == G_DIR_SEPARATOR) 19523ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen { 19533ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (!last_was_slash) 19543ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen *q++ = G_DIR_SEPARATOR; 19553ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 19563ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen last_was_slash = TRUE; 19573ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 19583ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 19593ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen { 19603ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (last_was_slash && *p == '.') 19613ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen { 19623ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (*(p + 1) == G_DIR_SEPARATOR || 19633ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen *(p + 1) == '\0') 19643ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen { 19653ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (*(p + 1) == '\0') 19663ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen break; 19673ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 19683ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen p += 1; 19693ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 19703ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else if (*(p + 1) == '.' && 19713ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen (*(p + 2) == G_DIR_SEPARATOR || 19723ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen *(p + 2) == '\0')) 19733ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen { 19743ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (q > filename + 1) 19753ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen { 19763ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen q--; 19773ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen while (q > filename + 1 && 19783ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen *(q - 1) != G_DIR_SEPARATOR) 19793ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen q--; 19803ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 19813ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 19823ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (*(p + 2) == '\0') 19833ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen break; 19843ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 19853ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen p += 2; 19863ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 19873ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 19883ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen { 19893ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen *q++ = *p; 19903ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen last_was_slash = FALSE; 19913ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 19923ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 19933ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen else 19943ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen { 19953ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen *q++ = *p; 19963ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen last_was_slash = FALSE; 19973ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 19983ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 19993ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20003ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen p++; 20013ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 20023ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20033ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (q > filename + 1 && *(q - 1) == G_DIR_SEPARATOR) 20043ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen q--; 20053ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20063ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen *q = '\0'; 20073ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen} 20083ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20093ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenstatic char * 20103ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen_resolve_symlink (const char *file) 20113ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{ 20123ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen GError *error; 20133ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen char *dir; 20143ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen char *link; 20153ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen char *f; 20163ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen char *f1; 20173ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20183ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen f = g_strdup (file); 20193ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20203ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen while (g_file_test (f, G_FILE_TEST_IS_SYMLINK)) { 20213ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen link = g_file_read_link (f, &error); 20223ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (link == NULL) { 20233ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen g_error_free (error); 20243ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen g_free (f); 20253ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen f = NULL; 20263ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen goto out; 20273ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 20283ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20293ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen dir = g_path_get_dirname (f); 20303ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen f1 = g_strdup_printf ("%s/%s", dir, link); 20313ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen g_free (dir); 20323ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen g_free (link); 20333ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen g_free (f); 20343ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen f = f1; 20353ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 20363ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20373ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen out: 20383ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (f != NULL) 20393ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen _canonicalize_filename (f); 20403ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen return f; 20413ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen} 20423ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20436ad96b367793557d0a02c1bff75cc60befcd59a6Alexander Larsson#ifdef HAVE_MNTENT_H 20443ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthenstatic const char * 20453ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen_resolve_dev_root (void) 20463ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen{ 20473ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen static gboolean have_real_dev_root = FALSE; 20483ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen static char real_dev_root[256]; 20493ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen struct stat statbuf; 20503ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20513ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen /* see if it's cached already */ 20523ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (have_real_dev_root) 20533ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen goto found; 20543ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20553ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen /* otherwise we're going to find it right away.. */ 20563ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen have_real_dev_root = TRUE; 20573ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20583ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (stat ("/dev/root", &statbuf) == 0) { 20593ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (! S_ISLNK (statbuf.st_mode)) { 20603ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen dev_t root_dev = statbuf.st_dev; 20613ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen FILE *f; 20623ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen char buf[1024]; 20633ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20643ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen /* see if device with similar major:minor as /dev/root is mention 20653ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen * in /etc/mtab (it usually is) 20663ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen */ 20673ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen f = fopen ("/etc/mtab", "r"); 20683ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (f != NULL) { 20690766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen struct mntent *entp; 20700766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#ifdef HAVE_GETMNTENT_R 20713ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen struct mntent ent; 20720766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen while ((entp = getmntent_r (f, &ent, buf, sizeof (buf))) != NULL) { 20730766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#else 20740766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen G_LOCK (getmntent); 20750766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen while ((entp = getmntent (f)) != NULL) { 20760766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#endif 20770766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen if (stat (entp->mnt_fsname, &statbuf) == 0 && 20783ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen statbuf.st_dev == root_dev) { 20790766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen strncpy (real_dev_root, entp->mnt_fsname, sizeof (real_dev_root) - 1); 20803ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen real_dev_root[sizeof (real_dev_root) - 1] = '\0'; 20813ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen fclose (f); 20823ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen goto found; 20833ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 20843ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 20850766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen 20860766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen endmntent (f); 20870766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen 20880766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#ifndef HAVE_GETMNTENT_R 20890766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen G_UNLOCK (getmntent); 20900766a1ec399f2dcd707249ed45b13dfbd239f382Matthias Clasen#endif 20913ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 20923ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20933ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen /* no, that didn't work.. next we could scan /dev ... but I digress.. */ 20943ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 20953ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } else { 20963ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen char *resolved; 20973ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen resolved = _resolve_symlink ("/dev/root"); 20983ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen if (resolved != NULL) { 20993ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen strncpy (real_dev_root, resolved, sizeof (real_dev_root) - 1); 21003ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen real_dev_root[sizeof (real_dev_root) - 1] = '\0'; 21013ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen g_free (resolved); 21023ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen goto found; 21033ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 21043ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 21053ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen } 21063ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 21073ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen /* bah sucks.. */ 21083ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen strcpy (real_dev_root, "/dev/root"); 21093ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 21103ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen found: 21113ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen return real_dev_root; 21123ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen} 21136ad96b367793557d0a02c1bff75cc60befcd59a6Alexander Larsson#endif 21143ca9fd4dbb134088bf70f2f6584f14a559e6820aDavid Zeuthen 21157f3280230bc9448a5750fc17a6eabef691ba25f4Alexander Larsson#define __G_UNIX_MOUNTS_C__ 21167f3280230bc9448a5750fc17a6eabef691ba25f4Alexander Larsson#include "gioaliasdef.c" 2117