Author: benny
Date: 2007-01-10 21:28:37 +0000 (Wed, 10 Jan 2007)
New Revision: 24347

Added:
   libexo/trunk/docs/reference/tmpl/exo-mount-point.sgml
   libexo/trunk/exo/exo-mount-point.c
   libexo/trunk/exo/exo-mount-point.h
   libexo/trunk/tests/test-exo-mount-point.c
Modified:
   libexo/trunk/ChangeLog
   libexo/trunk/docs/reference/exo-docs.sgml
   libexo/trunk/docs/reference/exo-sections.txt
   libexo/trunk/docs/reference/exo.types
   libexo/trunk/exo-mount/exo-mount-fstab.c
   libexo/trunk/exo-mount/exo-mount-utils.c
   libexo/trunk/exo-mount/exo-mount-utils.h
   libexo/trunk/exo-mount/main.c
   libexo/trunk/exo/Makefile.am
   libexo/trunk/exo/exo-md5.c
   libexo/trunk/exo/exo.h
   libexo/trunk/exo/exo.symbols
   libexo/trunk/po/ChangeLog
   libexo/trunk/po/POTFILES.in
   libexo/trunk/tests/
   libexo/trunk/tests/Makefile.am
Log:
2007-01-10      Benedikt Meurer <[EMAIL PROTECTED]>

        * exo/exo-md5.c(exo_md5_digest_dup): Fix invalid usage of g_memdup().
        * exo/exo-mount-point.{c,h}, exo/Makefile.am, exo/exo.symbols,
          exo/exo.h: Import new module ExoMountPoint, which handles the
          retrieval of active or configured mount points. This was merged
          here to avoid duplicating the code in several other applications.
          For example, Thunar, exo-mount and thunar-volman included similar
          code somehow. The code itself is highly platform-depend and so its
          easier to manage it in a central place.
        * docs/reference/: Update reference manual.
        * exo-mount/: Use the functions from the ExoMountPoint module.
        * tests/: Add a test case for the ExoMountPoint module.
        * po/POTFILES.in: Add new files here.




Modified: libexo/trunk/ChangeLog
===================================================================
--- libexo/trunk/ChangeLog      2007-01-10 20:50:18 UTC (rev 24346)
+++ libexo/trunk/ChangeLog      2007-01-10 21:28:37 UTC (rev 24347)
@@ -1,3 +1,18 @@
+2007-01-10     Benedikt Meurer <[EMAIL PROTECTED]>
+
+       * exo/exo-md5.c(exo_md5_digest_dup): Fix invalid usage of g_memdup().
+       * exo/exo-mount-point.{c,h}, exo/Makefile.am, exo/exo.symbols,
+         exo/exo.h: Import new module ExoMountPoint, which handles the
+         retrieval of active or configured mount points. This was merged
+         here to avoid duplicating the code in several other applications.
+         For example, Thunar, exo-mount and thunar-volman included similar
+         code somehow. The code itself is highly platform-depend and so its
+         easier to manage it in a central place.
+       * docs/reference/: Update reference manual.
+       * exo-mount/: Use the functions from the ExoMountPoint module.
+       * tests/: Add a test case for the ExoMountPoint module.
+       * po/POTFILES.in: Add new files here.
+
 2007-01-09     Benedikt Meurer <[EMAIL PROTECTED]>
 
        * exo-hal/exo-hal.{c,h}: Add utility function exo_hal_udi_validate()

Modified: libexo/trunk/docs/reference/exo-docs.sgml
===================================================================
--- libexo/trunk/docs/reference/exo-docs.sgml   2007-01-10 20:50:18 UTC (rev 
24346)
+++ libexo/trunk/docs/reference/exo-docs.sgml   2007-01-10 21:28:37 UTC (rev 
24347)
@@ -20,6 +20,7 @@
 <!ENTITY exo-binding SYSTEM "xml/exo-binding.xml">
 <!ENTITY exo-execute SYSTEM "xml/exo-execute.xml">
 <!ENTITY exo-md5 SYSTEM "xml/exo-md5.xml">
+<!ENTITY exo-mount-point SYSTEM "xml/exo-mount-point.xml">
 <!ENTITY exo-string SYSTEM "xml/exo-string.xml">
 <!ENTITY exo-url SYSTEM "xml/exo-url.xml">
 <!ENTITY exo-utils SYSTEM "xml/exo-utils.xml">
@@ -273,6 +274,7 @@
     &exo-binding;
     &exo-execute;
     &exo-md5;
+    &exo-mount-point;
     &exo-string;
     &exo-url;
     &exo-utils;

Modified: libexo/trunk/docs/reference/exo-sections.txt
===================================================================
--- libexo/trunk/docs/reference/exo-sections.txt        2007-01-10 20:50:18 UTC 
(rev 24346)
+++ libexo/trunk/docs/reference/exo-sections.txt        2007-01-10 21:28:37 UTC 
(rev 24347)
@@ -424,6 +424,19 @@
 </SECTION>
 
 <SECTION>
+<FILE>exo-mount-point</FILE>
+<TITLE>Mount Points</TITLE>
+ExoMountPointFlags
+ExoMountPoint
+exo_mount_point_dup
+exo_mount_point_free
+ExoMountPointMatchMask
+exo_mount_point_list_matched
+exo_mount_point_list_active
+exo_mount_point_list_configured
+</SECTION>
+
+<SECTION>
 <FILE>exo-string</FILE>
 <TITLE>String Utility Functions</TITLE>
 exo_str_elide_underscores

Modified: libexo/trunk/docs/reference/exo.types
===================================================================
--- libexo/trunk/docs/reference/exo.types       2007-01-10 20:50:18 UTC (rev 
24346)
+++ libexo/trunk/docs/reference/exo.types       2007-01-10 21:28:37 UTC (rev 
24347)
@@ -16,5 +16,6 @@
 
 exo_xsession_client_get_type
 exo_md5_digest_get_type
+exo_mount_point_get_type
 
 exo_ellipsized_label_get_type

Added: libexo/trunk/docs/reference/tmpl/exo-mount-point.sgml
===================================================================
--- libexo/trunk/docs/reference/tmpl/exo-mount-point.sgml                       
        (rev 0)
+++ libexo/trunk/docs/reference/tmpl/exo-mount-point.sgml       2007-01-10 
21:28:37 UTC (rev 24347)
@@ -0,0 +1,100 @@
+<!-- ##### SECTION Title ##### -->
+Mount Points
+
+<!-- ##### SECTION Short_Description ##### -->
+Functions to query active and configured mount points
+
+<!-- ##### SECTION Long_Description ##### -->
+<para>
+  This module provides functions to query active and configured mount points 
from
+  the system. This is commonly required in file and volume management, and 
hence
+  it was added to the library. For example, <command>exo-mount</command>,
+  <command>Thunar</command> and <command>thunar-volman</command> make use of 
this.
+</para>
+
+<!-- ##### SECTION See_Also ##### -->
+<para>
+
+</para>
+
+<!-- ##### SECTION Stability_Level ##### -->
+
+
+<!-- ##### ENUM ExoMountPointFlags ##### -->
+<para>
+
+</para>
+
[EMAIL PROTECTED]: 
+
+<!-- ##### STRUCT ExoMountPoint ##### -->
+<para>
+  Structure to represent a mount point, which can be either an
+  active mount point, queried from the kernel's internal mount
+  table, or a configured mount point queried from the file
+  system table (usually <filename>/etc/fstab</filename> or
+  <filename>/etc/vfstab</filename>).
+</para>
+
[EMAIL PROTECTED]: see #ExoMountPointFlags.
[EMAIL PROTECTED]: the device file path.
[EMAIL PROTECTED]: the folder where the device is mounted (or may be mounted).
[EMAIL PROTECTED]: the type of the file system used for the device.
+
+<!-- ##### FUNCTION exo_mount_point_dup ##### -->
+<para>
+
+</para>
+
[EMAIL PROTECTED]: 
[EMAIL PROTECTED]: 
+
+
+<!-- ##### FUNCTION exo_mount_point_free ##### -->
+<para>
+
+</para>
+
[EMAIL PROTECTED]: 
+
+
+<!-- ##### ENUM ExoMountPointMatchMask ##### -->
+<para>
+
+</para>
+
[EMAIL PROTECTED]: 
[EMAIL PROTECTED]: 
[EMAIL PROTECTED]: 
[EMAIL PROTECTED]: 
[EMAIL PROTECTED]: 
+
+<!-- ##### FUNCTION exo_mount_point_list_matched ##### -->
+<para>
+
+</para>
+
[EMAIL PROTECTED]: 
[EMAIL PROTECTED]: 
[EMAIL PROTECTED]: 
[EMAIL PROTECTED]: 
[EMAIL PROTECTED]: 
[EMAIL PROTECTED]: 
+
+
+<!-- ##### MACRO exo_mount_point_list_active ##### -->
+<para>
+
+</para>
+
[EMAIL PROTECTED]: 
+
+
+<!-- ##### MACRO exo_mount_point_list_configured ##### -->
+<para>
+
+</para>
+
[EMAIL PROTECTED]: 
+
+


Property changes on: libexo/trunk/docs/reference/tmpl/exo-mount-point.sgml
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Rev

Modified: libexo/trunk/exo/Makefile.am
===================================================================
--- libexo/trunk/exo/Makefile.am        2007-01-10 20:50:18 UTC (rev 24346)
+++ libexo/trunk/exo/Makefile.am        2007-01-10 21:28:37 UTC (rev 24347)
@@ -25,6 +25,7 @@
        exo-icon-chooser-dialog.h                                       \
        exo-icon-view.h                                                 \
        exo-md5.h                                                       \
+       exo-mount-point.h                                               \
        exo-pango-extensions.h                                          \
        exo-string.h                                                    \
        exo-toolbars-editor-dialog.h                                    \
@@ -74,6 +75,7 @@
        exo-icon-chooser-model.h                                        \
        exo-icon-view.c                                                 \
        exo-md5.c                                                       \
+       exo-mount-point.c                                               \
        exo-pango-extensions.c                                          \
        exo-private.c                                                   \
        exo-private.h                                                   \

Modified: libexo/trunk/exo/exo-md5.c
===================================================================
--- libexo/trunk/exo/exo-md5.c  2007-01-10 20:50:18 UTC (rev 24346)
+++ libexo/trunk/exo/exo-md5.c  2007-01-10 21:28:37 UTC (rev 24347)
@@ -1,6 +1,6 @@
 /* $Id$ */
 /*-
- * Copyright (c) 2004-2006 os-cillation e.K.
+ * Copyright (c) 2004-2007 os-cillation e.K.
  * Copyright (c) 2004      James M. Cape <[EMAIL PROTECTED]>
  *
  * Written by Benedikt Meurer <[EMAIL PROTECTED]>.
@@ -447,9 +447,20 @@
 ExoMd5Digest*
 exo_md5_digest_dup (const ExoMd5Digest *digest)
 {
-  g_return_val_if_fail (digest != NULL, NULL);
+  ExoMd5Digest *duplicate;
 
-  return g_memdup (digest, sizeof (*digest));
+  if (G_LIKELY (digest != NULL))
+    {
+      /* take a copy of the digest */
+      duplicate = _exo_slice_new (ExoMd5Digest);
+      memcpy (duplicate, digest, sizeof (*digest));
+      return duplicate;
+    }
+  else
+    {
+      /* duplicating NULL yields NULL */
+      return NULL;
+    }
 }
 
 

Added: libexo/trunk/exo/exo-mount-point.c
===================================================================
--- libexo/trunk/exo/exo-mount-point.c                          (rev 0)
+++ libexo/trunk/exo/exo-mount-point.c  2007-01-10 21:28:37 UTC (rev 24347)
@@ -0,0 +1,551 @@
+/* $Id$ */
+/*-
+ * Copyright (c) 2005-2007 Benedikt Meurer <[EMAIL PROTECTED]>.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+#ifdef HAVE_SYS_UCRED_H
+#include <sys/ucred.h>
+#endif
+#ifdef HAVE_SYS_MOUNT_H
+#include <sys/mount.h>
+#endif
+#ifdef HAVE_SYS_MNTTAB_H
+#include <sys/mnttab.h>
+#endif
+
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#ifdef HAVE_FSTAB_H
+#include <fstab.h>
+#endif
+#ifdef HAVE_MEMORY_H
+#include <memory.h>
+#endif
+#ifdef HAVE_MNTENT_H
+#include <mntent.h>
+#endif
+#ifdef HAVE_PATHS_H
+#include <paths.h>
+#endif
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+#include <exo/exo-mount-point.h>
+#include <exo/exo-private.h>
+#include <exo/exo-string.h>
+#include <exo/exo-alias.h>
+
+
+
+/* define _PATH_FSTAB if undefined */
+#ifndef _PATH_FSTAB
+#ifdef sun
+#define _PATH_FSTAB "/etc/vfstab"
+#else
+#define _PATH_FSTAB "/etc/fstab"
+#endif
+#endif
+
+
+
+static inline void    exo_mount_point_add_if_matches        
(ExoMountPointMatchMask mask,
+                                                             const gchar       
    *mask_device,
+                                                             const gchar       
    *mask_folder,
+                                                             const gchar       
    *mask_fstype,
+                                                             const gchar       
    *real_device,
+                                                             const gchar       
    *real_folder,
+                                                             const gchar       
    *real_fstype,
+                                                             gboolean          
     real_read_only,
+                                                             GSList            
   **mount_points);
+static inline GSList *exo_mount_point_list_match_active     
(ExoMountPointMatchMask mask,
+                                                             const gchar       
    *device,
+                                                             const gchar       
    *folder,
+                                                             const gchar       
    *fstype,
+                                                             GError            
   **error) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+static inline GSList *exo_mount_point_list_match_configured 
(ExoMountPointMatchMask mask,
+                                                             const gchar       
    *device,
+                                                             const gchar       
    *folder,
+                                                             const gchar       
    *fstype,
+                                                             GError            
   **error) G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+
+
+
+/* locking required, because most of the routines used aren't thread-safe */
+G_LOCK_DEFINE_STATIC (exo_mount_point_list_matched);
+
+
+
+static inline void
+exo_mount_point_add_if_matches (ExoMountPointMatchMask mask,
+                                const gchar           *mask_device,
+                                const gchar           *mask_folder,
+                                const gchar           *mask_fstype,
+                                const gchar           *real_device,
+                                const gchar           *real_folder,
+                                const gchar           *real_fstype,
+                                gboolean               real_read_only,
+                                GSList               **mount_points)
+{
+  ExoMountPoint *mount_point;
+  struct stat    statb1;
+  struct stat    statb2;
+
+  /* check if device should be matched */
+  if ((mask & EXO_MOUNT_POINT_MATCH_DEVICE) != 0)
+    {
+      /* check if both specify an absolute path */
+      if (*mask_device == '/' && *real_device == '/')
+        {
+          /* check if both refer to the same device, which means both must be
+           * a character device or a block device and the rdev's must match.
+           */
+          if (stat (mask_device, &statb1) < 0 || stat (real_device, &statb2) < 
0)
+            {
+              /* comapre by path/name instead */
+              goto match_device_by_path;
+            }
+          else if (((!S_ISBLK (statb1.st_mode) || !S_ISBLK (statb2.st_mode))
+                 && (!S_ISCHR (statb1.st_mode) || !S_ISCHR (statb1.st_mode)))
+              || (statb1.st_rdev != statb2.st_rdev))
+            {
+              /* different devices */
+              return;
+            }
+        }
+      else
+        {
+match_device_by_path:
+          /* compare by their paths/names instead */
+          if (strcmp (mask_device, real_device) != 0)
+            return;
+        }
+    }
+
+  /* check if folder should be matched */
+  if ((mask & EXO_MOUNT_POINT_MATCH_FOLDER) != 0)
+    {
+      /* just compare the folders by their paths */
+      if (strcmp (mask_folder, real_folder) != 0)
+        return;
+    }
+
+  /* check if fstype should be matched */
+  if ((mask & EXO_MOUNT_POINT_MATCH_FSTYPE) != 0)
+    {
+      /* just compare the file system types by their names */
+      if (strcmp (mask_fstype, real_fstype) != 0)
+        return;
+    }
+
+  /* allocate an ExoMountPoint, we matched */
+  mount_point = _exo_slice_new (ExoMountPoint);
+  mount_point->flags = real_read_only ? EXO_MOUNT_POINT_READ_ONLY : 0;
+  mount_point->device = g_strdup (real_device);
+  mount_point->folder = g_strdup (real_folder);
+  mount_point->fstype = g_strdup (real_fstype);
+
+  /* and add the mount point to the list */
+  *mount_points = g_slist_prepend (*mount_points, mount_point);
+}
+
+
+
+static inline GSList*
+exo_mount_point_list_match_active (ExoMountPointMatchMask mask,
+                                   const gchar           *device,
+                                   const gchar           *folder,
+                                   const gchar           *fstype,
+                                   GError               **error)
+{
+  GSList *mount_points = NULL;
+
+#if defined(HAVE_SETMNTENT) /* Linux */
+  struct mntent *mntent;
+  FILE          *fp;
+
+  /* try to open the /proc/mounts file */
+  fp = setmntent ("/proc/mounts", "r");
+  if (G_UNLIKELY (fp == NULL))
+    {
+      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
+                   _("Failed to open file \"%s\": %s"), "/proc/mounts",
+                   g_strerror (errno));
+      return NULL;
+    }
+
+  /* match all included entries */
+  for (;;)
+    {
+      /* grab the next entry */
+      mntent = getmntent (fp);
+      if (mntent == NULL)
+        break;
+
+      /* check if we have a match here */
+      exo_mount_point_add_if_matches (mask, device, folder, fstype, 
mntent->mnt_fsname, mntent->mnt_dir,
+                                      mntent->mnt_type, (hasmntopt (mntent, 
"ro") != NULL), &mount_points);
+    }
+
+  /* close the file handle */
+  endmntent (fp);
+#elif defined(HAVE_GETMNTENT)
+  struct mnttab mntent;
+  FILE         *fp;
+
+  /* try to open the /etc/mnttab file */
+  fp = setmntent ("/etc/mnttab", "r");
+  if (G_UNLIKELY (fp == NULL))
+    {
+      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
+                   _("Failed to open file \"%s\": %s"), "/etc/mnttab",
+                   g_strerror (errno));
+      return NULL;
+    }
+
+  /* match all included entries */
+  for (;;)
+    {
+      /* grab the next entry */
+      if (getmntent (fp, &mntent) != 0)
+        break;
+
+      /* check if we have a match here */
+      exo_mount_point_add_if_matches (mask, device, folder, fstype, 
mntent.mnt_special, mntent.mnt_mountp,
+                                      mntent.mnt_fstype, (hasmntopt (&mntent, 
"ro") != NULL), &mount_points);
+    }
+
+  /* close the file handle */
+  fclose (fp);
+#elif defined(HAVE_GETFSSTAT) /* BSD */
+  struct statfs *mntbuf = NULL;
+  glong          bufsize = 0;
+  gint           mntsize;
+  gint           n;
+
+  /* determine the number of active mount points */
+  mntsize = getfsstat (NULL, 0, MNT_NOWAIT);
+  if (G_LIKELY (mntsize > 0))
+    {
+      /* allocate a new buffer */
+      bufsize = (mntsize + 4) * sizeof (*mntbuf);
+      mntbuf = (struct statfs *) malloc (bufsize);
+
+      /* determine the mount point for the device file */
+      mntsize = getfsstat (mntbuf, bufsize, MNT_NOWAIT);
+      for (n = 0; n < mntsize; ++n)
+        {
+          /* check if we have a match here */
+          exo_mount_point_add_if_matches (mask, device, folder, fstype, 
mntbuf[n].f_mntfromname, mntbuf[n].f_mntonname,
+                                          mntbuf[n].f_fstypename, 
((mntbuf[n].f_flags & MNT_RDONLY) != 0), &mount_points);
+        }
+
+      /* release the buffer */
+      free (mntbuf);
+    }
+#else
+#error "Add support for your operating system here."
+#endif
+
+  /* return the collected mount points */
+  return mount_points;
+}
+
+
+
+static inline GSList*
+exo_mount_point_list_match_configured (ExoMountPointMatchMask mask,
+                                       const gchar           *device,
+                                       const gchar           *folder,
+                                       const gchar           *fstype,
+                                       GError               **error)
+{
+  GSList *mount_points = NULL;
+
+#if defined(HAVE_SETMNTENT) /* Linux */
+  struct mntent *mntent;
+  FILE          *fp;
+
+  /* try to open the fstab file */
+  fp = setmntent (_PATH_FSTAB, "r");
+  if (G_UNLIKELY (fp == NULL))
+    goto err;
+
+  /* match all included entries */
+  for (;;)
+    {
+      /* grab the next entry */
+      mntent = getmntent ();
+      if (mntent == NULL)
+        break;
+
+      /* skip swap entries */
+      if (strcmp (mntent->mnt_type, "swap") == 0)
+        continue;
+
+      /* check if we have a match here */
+      exo_mount_point_add_if_matches (mask, device, folder, fstype, 
mntent->mnt_fsname, mntent->mnt_dir,
+                                      mntent->mnt_type, (hasmntopt (mntent, 
"ro") != NULL), &mount_points);
+    }
+
+  /* close the file handle */
+  endmntent (fp);
+#elif defined(HAVE_GETMNTENT) /* Solaris */
+  struct mnttab mntent;
+  FILE         *fp;
+
+  /* try to open the fstab file */
+  fp = fopen (_PATH_FSTAB, "r");
+  if (G_UNLIKELY (fp == NULL))
+    goto err;
+
+  /* match all included entries */
+  for (;;)
+    {
+      /* grab the next entry */
+      if (getmntent (fp, &mntent) != 0)
+        break;
+
+      /* skip swap entries */
+      if (strcmp (mntent.mnt_fstype, "swap") == 0)
+        continue;
+
+      /* check if we have a match here */
+      exo_mount_point_add_if_matches (mask, device, folder, fstype, 
mntent.mnt_special, mntent.mnt_mountp,
+                                      mntent.mnt_fstype, (hasmntopt (&mntent, 
"ro") != NULL), &mount_points);
+    }
+
+  /* close the file handle */
+  fclose (fp);
+#elif defined(HAVE_SETFSENT) /* BSD */
+  struct fstab *fs;
+
+  /* try to open the fstab file */
+  if (setfsent () == 0)
+    goto err;
+
+  /* match all included entries */
+  for (;;)
+    {
+      /* grab the next entry */
+      fs = getfsent ();
+      if (fs == NULL)
+        break;
+
+      /* skip special entries */
+      if (strcmp (fs->fs_type, FSTAB_SW) == 0
+#ifdef FSTAB_DP
+          || strcmp (fs->fs_type, FSTAB_DP) == 0
+#endif
+          || strcmp (fs->fs_type, FSTAB_XX) == 0)
+        continue;
+
+      /* check if we have a match here */
+      exo_mount_point_add_if_matches (mask, device, folder, fstype, 
fs->fs_spec, fs->fs_file, fs->fs_vfstype,
+                                      (strcmp (fs->fs_type, FSTAB_RO) == 0), 
&mount_points);
+    }
+
+  /* close the file handle */
+  endfsent ();
+#else
+#error "Add support for your operating system here."
+#endif
+
+  /* return the collected mount points */
+  return mount_points;
+
+err:
+  g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
+               _("Failed to open file \"%s\": %s"), _PATH_FSTAB,
+               g_strerror (errno));
+  return NULL;
+}
+
+
+
+GType
+exo_mount_point_get_type (void)
+{
+  static GType type = G_TYPE_INVALID;
+
+  if (G_UNLIKELY (type == G_TYPE_INVALID))
+    {
+      type = g_boxed_type_register_static (I_("ExoMountPoint"),
+                                           (GBoxedCopyFunc) 
exo_mount_point_dup,
+                                           (GBoxedFreeFunc) 
exo_mount_point_free);
+    }
+
+  return type;
+}
+
+
+
+/**
+ * exo_mount_point_dup:
+ * @mount_point : an #ExoMountPoint.
+ *
+ * Duplicates the specified @mount_point and returns
+ * the duplicate. If @mount_point is %NULL, this simply
+ * returns %NULL.
+ *
+ * The caller is responsible to free the returned mount
+ * point using exo_mount_point_free() when no longer
+ * needed.
+ *
+ * Return value: a copy of the specified @mount_point.
+ *
+ * Since: 0.3.1.13
+ **/
+ExoMountPoint*
+exo_mount_point_dup (const ExoMountPoint *mount_point)
+{
+  ExoMountPoint *duplicate;
+
+  if (G_LIKELY (mount_point != NULL))
+    {
+      duplicate = _exo_slice_new (ExoMountPoint);
+      duplicate->flags = mount_point->flags;
+      duplicate->device = g_strdup (mount_point->device);
+      duplicate->folder = g_strdup (mount_point->folder);
+      duplicate->fstype = g_strdup (mount_point->fstype);
+      return duplicate;
+    }
+  else
+    {
+      /* duplicating NULL yields NULL */
+      return NULL;
+    }
+}
+
+
+
+/**
+ * exo_mount_point_free:
+ * @mount_point : an #ExoMountPoint.
+ *
+ * Frees the resources allocated to the specified @mount_point.
+ * If @mount_point is %NULL, this function does nothing.
+ *
+ * Since: 0.3.1.13
+ **/
+void
+exo_mount_point_free (ExoMountPoint *mount_point)
+{
+  if (G_LIKELY (mount_point != NULL))
+    {
+      g_free (mount_point->device);
+      g_free (mount_point->folder);
+      g_free (mount_point->fstype);
+      _exo_slice_free (ExoMountPoint, mount_point);
+    }
+}
+
+
+
+/**
+ * exo_mount_point_list_matched:
+ * @mask   : the mask of flags that have to match for a mount point to be 
returned.
+ * @device : the device file to match if %EXO_MOUNT_POINT_MATCH_DEVICE is 
specified.
+ * @folder : the folder to match if %EXO_MOUNT_POINT_MATCH_FOLDER is specified.
+ * @fstype : the file system type to match if %EXO_MOUNT_POINT_MATCH_FSTYPE is 
specified.
+ * @error  : return location for errors or %NULL.
+ *
+ * Lists mount points matching the given @mask and optionally the parameters 
@device,
+ * @folder and @fstype. If an error occurrs and @error is non-%NULL, the 
@error will
+ * be set to point to a #GError describing the problem, and %NULL will be 
returned.
+ * Note, however, that %NULL may also be returned if no mount points match.
+ *
+ * If @mask includes %EXO_MOUNT_POINT_MATCH_ACTIVE, the currently active mount 
points will
+ * be matched, that is, the currently mounted file systems, queried from the 
kernel. Otherwise
+ * if %EXO_MOUNT_POINT_MATCH_CONFIGURED is specified, the configured mount 
points from the
+ * file system table (usually <filename>/etc/fstab</filename> or 
<filename>/etc/vfstab</filename>)
+ * will be matched.
+ *
+ * The caller is responsible to free the returned list using
+ * <informalexample><programlisting>
+ * g_slist_foreach (list, (GFunc) exo_mount_point_free, NULL);
+ * g_slist_free (list);
+ * </programlisting></informalexample>
+ * when no longer needed.
+ *
+ * Return value: the list of matching #ExoMountPoint<!---->s.
+ *
+ * Since: 0.3.1.13
+ **/
+GSList*
+exo_mount_point_list_matched (ExoMountPointMatchMask mask,
+                              const gchar           *device,
+                              const gchar           *folder,
+                              const gchar           *fstype,
+                              GError               **error)
+{
+  GSList *mount_points;
+
+  g_return_val_if_fail ((mask & EXO_MOUNT_POINT_MATCH_DEVICE) == 0 || device 
!= NULL, NULL);
+  g_return_val_if_fail ((mask & EXO_MOUNT_POINT_MATCH_FOLDER) == 0 || folder 
!= NULL, NULL);
+  g_return_val_if_fail ((mask & EXO_MOUNT_POINT_MATCH_FSTYPE) == 0 || fstype 
!= NULL, NULL);
+  g_return_val_if_fail (error == NULL || *error == NULL, NULL);
+
+#if defined(HAVE_GETFSSTAT) && !defined(HAVE_GETMNTENT) && 
!defined(HAVE_SETMNTENT) 
+  /* getfsstat(2) is really thread-safe, so we can skip locking there */
+  if ((mask & EXO_MOUNT_POINT_MATCH_CONFIGURED) == 
EXO_MOUNT_POINT_MATCH_CONFIGURED)
+#endif
+    {
+      /* acquire the mount point listing lock */
+      G_LOCK (exo_mount_point_list_matched);
+    }
+
+  /* list the requested mount points */
+  mount_points = ((mask & EXO_MOUNT_POINT_MATCH_CONFIGURED) == 0)
+               ? exo_mount_point_list_match_active (mask, device, folder, 
fstype, error)
+               : exo_mount_point_list_match_configured (mask, device, folder, 
fstype, error);
+
+#if defined(HAVE_GETFSSTAT) && !defined(HAVE_GETMNTENT) && 
!defined(HAVE_SETMNTENT) 
+  /* getfsstat(2) is really thread-safe, so we can skip locking there */
+  if ((mask & EXO_MOUNT_POINT_MATCH_CONFIGURED) == 
EXO_MOUNT_POINT_MATCH_CONFIGURED)
+#endif
+    {
+      /* release the mount point listing lock */
+      G_UNLOCK (exo_mount_point_list_matched);
+    }
+
+  return mount_points;
+}
+
+
+
+#define __EXO_MOUNT_POINT_C__
+#include <exo/exo-aliasdef.c>


Property changes on: libexo/trunk/exo/exo-mount-point.c
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Rev

Added: libexo/trunk/exo/exo-mount-point.h
===================================================================
--- libexo/trunk/exo/exo-mount-point.h                          (rev 0)
+++ libexo/trunk/exo/exo-mount-point.h  2007-01-10 21:28:37 UTC (rev 24347)
@@ -0,0 +1,133 @@
+/* $Id$ */
+/*-
+ * Copyright (c) 2005-2007 Benedikt Meurer <[EMAIL PROTECTED]>.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#if !defined (EXO_INSIDE_EXO_H) && !defined (EXO_COMPILATION)
+#error "Only <exo/exo.h> can be included directly, this file may disappear or 
change contents."
+#endif
+
+#ifndef __EXO_MOUNT_POINT_H__
+#define __EXO_MOUNT_POINT_H__
+
+#include <exo/exo-config.h>
+
+G_BEGIN_DECLS;
+
+/**
+ * ExoMountPointFlags:
+ * @EXO_MOUNT_POINT_READ_ONLY : read only mount point.
+ *
+ * Identifies options of #ExoMountPoint<!---->s.
+ *
+ * Since: 0.3.1.13
+ **/
+typedef enum /*< flags >*/
+{
+  EXO_MOUNT_POINT_READ_ONLY = (1L << 0),
+} ExoMountPointFlags;
+
+#define EXO_TYPE_MOUNT_POINT (exo_mount_point_get_type ())
+
+typedef struct _ExoMountPoint ExoMountPoint;
+struct _ExoMountPoint
+{
+  ExoMountPointFlags flags;
+  gchar             *device;
+  gchar             *folder;
+  gchar             *fstype;
+};
+
+/**
+ * ExoMountPointMatchMask:
+ * @EXO_MOUNT_POINT_MATCH_ACTIVE     : see exo_mount_point_list_active().
+ * @EXO_MOUNT_POINT_MATCH_CONFIGURED : see exo_mount_point_list_configured().
+ * @EXO_MOUNT_POINT_MATCH_DEVICE     : match by device file.
+ * @EXO_MOUNT_POINT_MATCH_FOLDER     : match by mount point folder.
+ * @EXO_MOUNT_POINT_MATCH_FSTYPE     : match by file system type.
+ *
+ * Flags for exo_mount_point_list_matched(), that control which mount points
+ * will be returned. The fewer match options are specified, the more mount
+ * points will usually match (surprising, eh?).
+ *
+ * Since: 0.3.1.13
+ **/
+typedef enum /*< skip >*/
+{
+  EXO_MOUNT_POINT_MATCH_ACTIVE      = (0L << 0),
+  EXO_MOUNT_POINT_MATCH_CONFIGURED  = (1L << 0),
+  EXO_MOUNT_POINT_MATCH_DEVICE      = (1L << 1),
+  EXO_MOUNT_POINT_MATCH_FOLDER      = (1L << 2),
+  EXO_MOUNT_POINT_MATCH_FSTYPE      = (1L << 3),
+} ExoMountPointMatchMask;
+
+GType          exo_mount_point_get_type     (void) G_GNUC_CONST;
+
+ExoMountPoint *exo_mount_point_dup          (const ExoMountPoint *mount_point) 
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+void           exo_mount_point_free         (ExoMountPoint       *mount_point);
+
+GSList        *exo_mount_point_list_matched (ExoMountPointMatchMask mask,
+                                             const gchar           *device,
+                                             const gchar           *folder,
+                                             const gchar           *fstype,
+                                             GError               **error) 
G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT;
+
+/**
+ * exo_mount_point_list_active:
+ * @error : return location for errors or %NULL.
+ *
+ * Convenience wrapper for exo_mount_point_list_matched(), that returns the
+ * currently active mount points, or %NULL in case of an error.
+ *
+ * The caller is responsible to free the returned list using
+ * <informalexample><programlisting>
+ * g_slist_foreach (list, (GFunc) exo_mount_point_free, NULL);
+ * g_slist_free (list);
+ * </programlisting></informalexample>
+ * when no longer needed.
+ *
+ * Return value: the list of currently active mount points.
+ *
+ * Since: 0.3.1.13
+ **/
+#define exo_mount_point_list_active(error) (exo_mount_point_list_matched 
(EXO_MOUNT_POINT_MATCH_ACTIVE, NULL, NULL, NULL, (error)))
+
+/**
+ * exo_mount_point_list_configured:
+ * @error : return location for errors or %NULL.
+ *
+ * Convenience wrapper for exo_mount_point_list_matched(), that returns the
+ * configured mount points, i.e. the entries from the file system table (which
+ * is usually specified in <filename>/etc/fstab</filename>).
+ *
+ * The caller is responsible to free the returned list using
+ * <informalexample><programlisting>
+ * g_slist_foreach (list, (GFunc) exo_mount_point_free, NULL);
+ * g_slist_free (list);
+ * </programlisting></informalexample>
+ * when no longer needed.
+ *
+ * Return value: the list of configured mount points.
+ *
+ * Since: 0.3.1.13
+ **/
+#define exo_mount_point_list_configured(error) (exo_mount_point_list_matched 
(EXO_MOUNT_POINT_MATCH_CONFIGURED, NULL, NULL, NULL, (error)))
+
+G_END_DECLS;
+
+#endif /* !__EXO_MOUNT_POINT_H__ */


Property changes on: libexo/trunk/exo/exo-mount-point.h
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Rev

Modified: libexo/trunk/exo/exo.h
===================================================================
--- libexo/trunk/exo/exo.h      2007-01-10 20:50:18 UTC (rev 24346)
+++ libexo/trunk/exo/exo.h      2007-01-10 21:28:37 UTC (rev 24347)
@@ -1,6 +1,6 @@
 /* $Id$ */
 /*-
- * Copyright (c) 2004-2006 os-cillation e.K.
+ * Copyright (c) 2004-2007 os-cillation e.K.
  *
  * Written by Benedikt Meurer <[EMAIL PROTECTED]>.
  *
@@ -53,6 +53,7 @@
 #include <exo/exo-icon-chooser-dialog.h>
 #include <exo/exo-icon-view.h>
 #include <exo/exo-md5.h>
+#include <exo/exo-mount-point.h>
 #include <exo/exo-pango-extensions.h>
 #include <exo/exo-string.h>
 #include <exo/exo-toolbars-editor.h>

Modified: libexo/trunk/exo/exo.symbols
===================================================================
--- libexo/trunk/exo/exo.symbols        2007-01-10 20:50:18 UTC (rev 24346)
+++ libexo/trunk/exo/exo.symbols        2007-01-10 21:28:37 UTC (rev 24347)
@@ -1,6 +1,6 @@
 /* $Id$ */
 /*-
- * Copyright (c) 2005-2006 Benedikt Meurer <[EMAIL PROTECTED]>.
+ * Copyright (c) 2005-2007 Benedikt Meurer <[EMAIL PROTECTED]>.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -89,8 +89,9 @@
 #if IN_HEADER(__EXO_ENUM_TYPES_H__)
 #if IN_SOURCE(__EXO_ENUM_TYPES_C__)
 exo_icon_view_drop_position_get_type G_GNUC_CONST
-exo_toolbars_model_flags_get_type G_GNUC_CONST
 exo_icon_view_layout_mode_get_type G_GNUC_CONST
+exo_mount_point_flags_get_type G_GNUC_CONST
+exo_toolbars_model_flags_get_type G_GNUC_CONST
 #endif
 #endif
 
@@ -155,18 +156,6 @@
 #endif
 #endif
 
-/* ExoIconChooserButton methods */
-#if IN_HEADER(__EXO_ICON_CHOOSER_BUTTON_H__)
-#if IN_SOURCE(__EXO_ICON_CHOOSER_BUTTON_C__)
-exo_icon_chooser_button_get_type G_GNUC_CONST
-exo_icon_chooser_button_new G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT
-exo_icon_chooser_button_get_icon G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT
-exo_icon_chooser_button_set_icon
-exo_icon_chooser_button_get_title
-exo_icon_chooser_button_set_title
-#endif
-#endif
-
 /* ExoIconChooserDialog methods */
 #if IN_HEADER(__EXO_ICON_CHOOSER_DIALOG_H__)
 #if IN_SOURCE(__EXO_ICON_CHOOSER_DIALOG_C__)
@@ -265,6 +254,16 @@
 #endif
 #endif
 
+/* exo-mount-point functions */
+#if IN_HEADER(__EXO_MOUNT_POINT_H__)
+#if IN_SOURCE(__EXO_MOUNT_POINT_C__)
+exo_mount_point_get_type G_GNUC_CONST
+exo_mount_point_dup G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT
+exo_mount_point_free
+exo_mount_point_list_matched G_GNUC_MALLOC G_GNUC_WARN_UNUSED_RESULT
+#endif
+#endif
+
 /* exo-utils functions */
 #if IN_HEADER(__EXO_UTILS_H__)
 #if IN_SOURCE(__EXO_UTILS_C__)

Modified: libexo/trunk/exo-mount/exo-mount-fstab.c
===================================================================
--- libexo/trunk/exo-mount/exo-mount-fstab.c    2007-01-10 20:50:18 UTC (rev 
24346)
+++ libexo/trunk/exo-mount/exo-mount-fstab.c    2007-01-10 21:28:37 UTC (rev 
24347)
@@ -21,26 +21,12 @@
 #include <config.h>
 #endif
 
-#ifdef HAVE_SYS_MNTTAB_H
-#include <sys/mnttab.h>
-#endif
-
-#ifdef HAVE_ERRNO_H
-#include <errno.h>
-#endif
-#ifdef HAVE_FSTAB_H
-#include <fstab.h>
-#endif
 #ifdef HAVE_MEMORY_H
 #include <memory.h>
 #endif
-#ifdef HAVE_MNTENT_H
-#include <mntent.h>
-#endif
 #ifdef HAVE_PATHS_H
 #include <paths.h>
 #endif
-#include <stdio.h>
 #ifdef HAVE_STRING_H
 #include <string.h>
 #endif
@@ -50,15 +36,6 @@
 
 
 
-/* define _PATH_FSTAB if undefined */
-#ifndef _PATH_FSTAB
-#ifdef sun
-#define _PATH_FSTAB "/etc/vfstab"
-#else
-#define _PATH_FSTAB "/etc/fstab"
-#endif
-#endif
-
 /* define _PATH_MOUNT if undefined */
 #ifndef _PATH_MOUNT
 #define _PATH_MOUNT "/bin/mount"
@@ -134,114 +111,35 @@
 exo_mount_fstab_lookup (const gchar *device_file,
                         GError     **error)
 {
-  gchar *path = NULL;
+  GError *err = NULL;
+  GSList *mount_points;
+  gchar  *path = NULL;
 
-#if defined(HAVE_SETMNTENT) /* Linux */
-  struct mntent *mntent;
-  FILE          *fp;
-
-  /* try to open the fstab file */
-  fp = setmntent (_PATH_FSTAB, "r");
-  if (G_UNLIKELY (fp == NULL))
+  /* lookup the configured device in the file system table using the 
ExoMountPoint module */
+  mount_points = exo_mount_point_list_matched 
(EXO_MOUNT_POINT_MATCH_CONFIGURED | EXO_MOUNT_POINT_MATCH_DEVICE, device_file, 
NULL, NULL, &err);
+  if (G_LIKELY (mount_points != NULL))
     {
-      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
-                   _("Failed to open file \"%s\": %s"), _PATH_FSTAB,
-                   g_strerror (errno));
-      return NULL;
-    }
+      /* take a copy of the folder path of the first matching mount point */
+      path = g_strdup (((const ExoMountPoint *) mount_points->data)->folder);
 
-  /* look up an entry for our device file */
-  while (path == NULL)
-    {
-      /* grab the next entry */
-      mntent = getmntent (fp);
-      if (mntent == NULL)
-        break;
-
-      /* check if this entry matches */
-      if (exo_mount_utils_is_same_device (device_file, mntent->mnt_fsname))
-        path = g_strdup (mntent->mnt_dir);
+      /* cleanup the mount points */
+      g_slist_foreach (mount_points, (GFunc) exo_mount_point_free, NULL);
+      g_slist_free (mount_points);
     }
-
-  /* close the file handle */
-  endmntent (fp);
-#elif defined(HAVE_GETMNTENT) /* Solaris */
-  struct mnttab mntent;
-  FILE         *fp;
-
-  /* try to open the fstab file */
-  fp = fopen (_PATH_FSTAB, "r");
-  if (G_UNLIKELY (fp == NULL))
+  else if (err == NULL)
     {
-      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
-                   _("Failed to open file \"%s\": %s"), _PATH_FSTAB,
-                   g_strerror (errno));
-      return NULL;
+      /* TRANSLATORS: a device is missing from the file system table (usually 
/etc/fstab) */
+      g_set_error (&err, G_FILE_ERROR, G_FILE_ERROR_INVAL, _("Device \"%s\" 
not found in file system device table"), device_file);
     }
 
-  /* look up an entry for our device file */
-  while (path == NULL)
+  /* check if we failed */
+  if (G_UNLIKELY (err != NULL))
     {
-      /* grab the next entry */
-      if (getmntent (fp, &mntent) != 0)
-        break;
-
-      /* check if this entry matches */
-      if (exo_mount_utils_is_same_device (device_file, mntent.mnt_special))
-        path = g_strdup (mntent.mnt_mountp);
-    }
-
-  /* close the file handle */
-  fclose (fp);
-#elif defined(HAVE_SETFSENT) /* FreeBSD */
-  struct fstab *fs;
-
-  /* open the fstab file */
-  if (setfsent () == 0)
-    {
-      g_set_error (error, G_FILE_ERROR, g_file_error_from_errno (errno),
-                   _("Failed to open file \"%s\": %s"), _PATH_FSTAB,
-                   g_strerror (errno));
+      /* propagate the error */
+      g_propagate_error (error, err);
       return NULL;
     }
 
-  /* look up an entry for our device file */
-  while (path == NULL)
-    {
-      /* grab the next entry */
-      fs = getfsent ();
-      if (fs == NULL)
-        break;
-
-      /* check if this is a usable file system */
-      if (strcmp (fs->fs_type, FSTAB_SW) == 0
-#ifdef FSTAB_DP
-          || strcmp (fs->fs_type, FSTAB_DP) == 0
-#endif
-          || strcmp (fs->fs_type, FSTAB_XX) == 0)
-        {
-          /* skip this one then */
-          continue;
-        }
-
-      /* check if this entry matches */
-      if (exo_mount_utils_is_same_device (device_file, fs->fs_spec))
-        path = g_strdup (fs->fs_file);
-    }
-
-  /* close the file handle */
-  endfsent ();
-#else
-#error "Add support for your operating system here."
-#endif
-
-  /* check if we failed to find the entry */
-  if (G_UNLIKELY (path == NULL))
-    {
-      /* generate an appropriate error message */
-      g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, _("Device \"%s\" 
not found in file system device table"), device_file);
-    }
-
   return path;
 }
 

Modified: libexo/trunk/exo-mount/exo-mount-utils.c
===================================================================
--- libexo/trunk/exo-mount/exo-mount-utils.c    2007-01-10 20:50:18 UTC (rev 
24346)
+++ libexo/trunk/exo-mount/exo-mount-utils.c    2007-01-10 21:28:37 UTC (rev 
24347)
@@ -21,111 +21,11 @@
 #include <config.h>
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-#include <sys/types.h>
-#endif
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
-#endif
-#ifdef HAVE_SYS_UCRED_H
-#include <sys/ucred.h>
-#endif
-#ifdef HAVE_SYS_MNTTAB_H
-#include <sys/mnttab.h>
-#endif
-#ifdef HAVE_SYS_MOUNT_H
-#include <sys/mount.h>
-#endif
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
-#ifdef HAVE_MEMORY_H
-#include <memory.h>
-#endif
-#ifdef HAVE_MNTENT_H
-#include <mntent.h>
-#endif
-#include <stdio.h>
-#ifdef HAVE_STRING_H
-#include <string.h>
-#endif
-
 #include <exo-mount/exo-mount-utils.h>
 
 
 
 /**
- * exo_mount_utils_canonicalize_filename:
- * @filename : an absolute local path.
- *
- * Translates the @filename to a canonicalized form.
- **/
-void
-exo_mount_utils_canonicalize_filename (gchar *filename)
-{
-  gboolean last_was_slash = FALSE;
-  gchar   *p;
-  gchar   *q;
-
-  for (p = q = filename; *p != '\0'; )
-    {
-      if (*p == G_DIR_SEPARATOR)
-        {
-          if (!last_was_slash)
-            *q++ = G_DIR_SEPARATOR;
-          last_was_slash = TRUE;
-        }
-      else
-        {
-          if (last_was_slash && *p == '.')
-            {
-              if (*(p + 1) == G_DIR_SEPARATOR || *(p + 1) == '\0')
-              {
-                if (*(p + 1) == '\0')
-                  break;
-                
-                p += 1;
-              }
-              else if (*(p + 1) == '.' && (*(p + 2) == G_DIR_SEPARATOR || *(p 
+ 2) == '\0'))
-                {
-                  if (q > filename + 1)
-                    {
-                      q--;
-                      while (q > filename + 1 && *(q - 1) != G_DIR_SEPARATOR)
-                        q--;
-                    }
-                  
-                  if (*(p + 2) == '\0')
-                    break;
-                  
-                  p += 2;
-                }
-              else
-                {
-                  *q++ = *p;
-                  last_was_slash = FALSE;
-                }
-            }
-          else
-            {
-              *q++ = *p;
-              last_was_slash = FALSE;
-            }
-        }
-      
-      p++;
-    }
-  
-  if (q > filename + 1 && *(q - 1) == G_DIR_SEPARATOR)
-    q--;
-  
-  *q = '\0';
-}
-
-
-
-/**
  * exo_mount_utils_is_mounted:
  * @device_file     : an absolute path to a device file.
  * @readonly_return : if non-%NULL and the device is mounted, this
@@ -140,133 +40,20 @@
 exo_mount_utils_is_mounted (const gchar *device_file,
                             gboolean    *readonly_return)
 {
-  gboolean result = FALSE;
+  GSList *mount_points;
 
-#if defined(HAVE_SETMNTENT) /* Linux */
-  struct mntent *mntent;
-  FILE          *fp;
-
-  /* try to open the /proc/mounts file */
-  fp = setmntent ("/proc/mounts", "r");
-  if (G_LIKELY (fp != NULL))
+  /* check if we have an active mount point for the device file */
+  mount_points = exo_mount_point_list_matched (EXO_MOUNT_POINT_MATCH_ACTIVE | 
EXO_MOUNT_POINT_MATCH_DEVICE, device_file, NULL, NULL, NULL);
+  if (G_LIKELY (mount_points != NULL))
     {
-      /* process all mnt entries */
-      while (!result)
-        {
-          /* read the next entry */
-          mntent = getmntent (fp);
-          if (mntent == NULL)
-            break;
-
-          /* check if this is the entry we are looking for */
-          result = exo_mount_utils_is_same_device (mntent->mnt_fsname, 
device_file);
-
-          /* check if the device was mounted read-only */
-          if (readonly_return != NULL && result)
-            *readonly_return = (hasmntopt (mntent, "ro") != NULL);
-        }
-
-      /* close the file handle */
-      endmntent (fp);
+      /* check if the first matching device is mounted read-only */
+      if (G_LIKELY (readonly_return != NULL))
+        *readonly_return = ((((const ExoMountPoint *) 
mount_points->data)->flags & EXO_MOUNT_POINT_READ_ONLY) != 0);
+      g_slist_foreach (mount_points, (GFunc) exo_mount_point_free, NULL);
+      g_slist_free (mount_points);
+      return TRUE;
     }
-#elif defined(HAVE_GETMNTENT) /* Solaris */
-  struct mnttab mntent;
-  FILE         *fp;
 
-  /* try to open the /proc/mountfs file */
-  fp = fopen ("/proc/mounts", "r");
-  if (G_LIKELY (fp != NULL))
-    {
-      /* process all mnt entries */
-      while (!result)
-        {
-          /* grab the next entry */
-          if (getmntent (fp, &mntent) != 0)
-            break;
-
-          /* check if this is the entry we are looking for */
-          result = exo_mount_utils_is_same_device (mntent.mnt_special, 
device_file);
-
-          /* check if the device was mounted read-only */
-          if (readonly_return != NULL && result)
-            *readonly_return = (hasmntopt (&mntent, "ro") != NULL);
-        }
-
-      /* close the file handle */
-      fclose (fp);
-    }
-#elif defined(HAVE_GETFSSTAT) /* FreeBSD */
-  struct statfs *mntbuf = NULL;
-  glong          bufsize = 0;
-  gint           mntsize;
-  gint           n;
-
-  /* determine the number of active mount points */
-  mntsize = getfsstat (NULL, 0, MNT_NOWAIT);
-  if (G_LIKELY (mntsize > 0))
-    {
-      /* allocate a new buffer */
-      bufsize = (mntsize + 4) * sizeof (*mntbuf);
-      mntbuf = (struct statfs *) g_malloc (bufsize);
-
-      /* determine the mount point for the device file */
-      mntsize = getfsstat (mntbuf, bufsize, MNT_NOWAIT);
-      for (n = 0; n < mntsize && !result; ++n)
-        {
-          /* check if this is the entry we are looking for */
-          result = exo_mount_utils_is_same_device (mntbuf[n].f_mntfromname, 
device_file);
-
-          /* check if the device was mounted read-only */
-          if (readonly_return != NULL && result)
-            *readonly_return = ((mntbuf[n].f_flags & MNT_RDONLY) != 0);
-        }
-
-      /* release the buffer */
-      g_free (mntbuf);
-    }
-#else
-#error "Add support for your operating system here."
-#endif
-
-  return result;
+  return FALSE;
 }
 
-
-
-/**
- * exo_mount_utils_is_same_device:
- * @device_file1 : absolute path to the first device file.
- * @device_file2 : absolute path to the second device file.
- *
- * Returns %TRUE if @device_file1 and @device_file2 refer to
- * the same device (comparing their device major and minor
- * numbers).
- *
- * Return value: %TRUE if @device_file1 and @device_file2
- *               refer to the same device, %FALSE otherwise.
- **/
-gboolean
-exo_mount_utils_is_same_device (const gchar *device_file1,
-                                const gchar *device_file2)
-{
-  struct stat statb1;
-  struct stat statb2;
-
-  g_return_val_if_fail (device_file1 != NULL, FALSE);
-  g_return_val_if_fail (device_file2 != NULL, FALSE);
-
-  /* both device file names must be absolute paths */
-  if (!g_path_is_absolute (device_file1) || !g_path_is_absolute (device_file2))
-    return FALSE;
-
-  /* try to stat both device files */
-  if (stat (device_file1, &statb1) < 0 || stat (device_file2, &statb2) < 0)
-    return FALSE;
-
-  /* must be both a character or a block device whose rdev matches */
-  return ((S_ISBLK (statb1.st_mode) && S_ISBLK (statb2.st_mode))
-       || (S_ISCHR (statb1.st_mode) && S_ISCHR (statb1.st_mode)))
-      && (statb1.st_rdev == statb2.st_rdev);
-}
-
-

Modified: libexo/trunk/exo-mount/exo-mount-utils.h
===================================================================
--- libexo/trunk/exo-mount/exo-mount-utils.h    2007-01-10 20:50:18 UTC (rev 
24346)
+++ libexo/trunk/exo-mount/exo-mount-utils.h    2007-01-10 21:28:37 UTC (rev 
24347)
@@ -24,14 +24,9 @@
 
 G_BEGIN_DECLS;
 
-void     exo_mount_utils_canonicalize_filename  (gchar       *filename) 
G_GNUC_INTERNAL;
+gboolean exo_mount_utils_is_mounted (const gchar *device_file,
+                                     gboolean    *readonly_return) 
G_GNUC_INTERNAL;
 
-gboolean exo_mount_utils_is_mounted             (const gchar *device_file,
-                                                 gboolean    *readonly_return) 
G_GNUC_INTERNAL;
-
-gboolean exo_mount_utils_is_same_device         (const gchar *device_file1,
-                                                 const gchar *device_file2) 
G_GNUC_INTERNAL;
-
 G_END_DECLS;
 
 #endif /* !__EXO_MOUNT_UTILS_H__ */

Modified: libexo/trunk/exo-mount/main.c
===================================================================
--- libexo/trunk/exo-mount/main.c       2007-01-10 20:50:18 UTC (rev 24346)
+++ libexo/trunk/exo-mount/main.c       2007-01-10 21:28:37 UTC (rev 24347)
@@ -205,9 +205,6 @@
   mounted_readonly = exo_mount_hal_device_is_readonly (device);
 #endif
 
-  /* canonicalize the device file path */
-  exo_mount_utils_canonicalize_filename (opt_device);
-
   /* check if the device is currently mounted */
   mounted = exo_mount_utils_is_mounted (opt_device, &mounted_readonly);
   if ((!opt_eject && !opt_unmount && mounted)

Modified: libexo/trunk/po/ChangeLog
===================================================================
--- libexo/trunk/po/ChangeLog   2007-01-10 20:50:18 UTC (rev 24346)
+++ libexo/trunk/po/ChangeLog   2007-01-10 21:28:37 UTC (rev 24347)
@@ -1,6 +1,10 @@
+2007-01-10  Benedikt Meurer <[EMAIL PROTECTED]>
+
+       * POTFILES.in: Add new files here.
+
 2007-01-10  Piarres Beobide <[EMAIL PROTECTED]>
 
-        * eu.po: Updated Basque translation.
+       * eu.po: Updated Basque translation.
 
 2007-01-10  Maximilian Schleiss <[EMAIL PROTECTED]>
 

Modified: libexo/trunk/po/POTFILES.in
===================================================================
--- libexo/trunk/po/POTFILES.in 2007-01-10 20:50:18 UTC (rev 24346)
+++ libexo/trunk/po/POTFILES.in 2007-01-10 21:28:37 UTC (rev 24347)
@@ -12,6 +12,7 @@
 exo/exo-icon-chooser-model.c
 exo/exo-icon-view.c
 exo/exo-md5.c
+exo/exo-mount-point.c
 exo/exo-pango-extensions.c
 exo/exo-private.c
 exo/exo-string.c


Property changes on: libexo/trunk/tests
___________________________________________________________________
Name: svn:ignore
   - .deps
.libs
Makefile
Makefile.in
test-exo-csource-data.c
*.core
core
core.*
.*.swp
test-exo-csource
test-exo-icon-chooser-dialog
test-exo-noop
test-exo-string
test-exo-wrap-table

   + .deps
.libs
Makefile
Makefile.in
test-exo-csource-data.c
*.core
core
core.*
.*.swp
test-exo-csource
test-exo-icon-chooser-dialog
test-exo-mount-point
test-exo-noop
test-exo-string
test-exo-wrap-table


Modified: libexo/trunk/tests/Makefile.am
===================================================================
--- libexo/trunk/tests/Makefile.am      2007-01-10 20:50:18 UTC (rev 24346)
+++ libexo/trunk/tests/Makefile.am      2007-01-10 21:28:37 UTC (rev 24347)
@@ -10,11 +10,13 @@
 
 TESTS =                                                                        
\
        test-exo-csource                                                \
+       test-exo-mount-point                                            \
        test-exo-noop                                                   \
        test-exo-string
 
 check_PROGRAMS =                                                       \
        test-exo-csource                                                \
+       test-exo-mount-point                                            \
        test-exo-noop                                                   \
        test-exo-string
 
@@ -28,6 +30,19 @@
 test_exo_csource_LDADD =                                               \
        $(GLIB_LIBS)
 
+test_exo_mount_point_SOURCES =                                         \
+       test-exo-mount-point.c
+
+test_exo_mount_point_CFLAGS =                                          \
+       $(GTK_CFLAGS)                                                   \
+       $(LIBXFCE4UTIL_CFLAGS)
+
+test_exo_mount_point_DEPENDENCIES =                                    \
+       
$(top_builddir)/exo/libexo-$(LIBEXO_VERSION_MAJOR).$(LIBEXO_VERSION_MINOR).la
+
+test_exo_mount_point_LDADD =                                           \
+       
$(top_builddir)/exo/libexo-$(LIBEXO_VERSION_MAJOR).$(LIBEXO_VERSION_MINOR).la
+
 test_exo_noop_SOURCES =                                                        
\
        test-exo-noop.c
 

Added: libexo/trunk/tests/test-exo-mount-point.c
===================================================================
--- libexo/trunk/tests/test-exo-mount-point.c                           (rev 0)
+++ libexo/trunk/tests/test-exo-mount-point.c   2007-01-10 21:28:37 UTC (rev 
24347)
@@ -0,0 +1,86 @@
+/* $Id$ */
+/*-
+ * Copyright (c) 2007 Benedikt Meurer <[EMAIL PROTECTED]>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+
+#include <exo/exo.h>
+
+
+
+static void
+print_mount_point (const ExoMountPoint *mount_point)
+{
+  g_print (" - %s\t%s\t%s", mount_point->device, mount_point->folder, 
mount_point->fstype);
+  if ((mount_point->flags & EXO_MOUNT_POINT_READ_ONLY) != 0)
+    g_print (" (ro)");
+  g_print ("\n");
+}
+
+
+
+int
+main (int argc, char **argv)
+{
+  GError *err = NULL;
+  GSList *mount_points;
+  GSList *lp;
+
+  mount_points = exo_mount_point_list_active (&err);
+  if (G_UNLIKELY (err != NULL))
+    {
+      g_printerr ("Failed to query active mount points: %s\n", err->message);
+      g_error_free (err);
+      return EXIT_FAILURE;
+    }
+  g_print ("Active mount points:\n--------------------\n");
+  for (lp = mount_points; lp != NULL; lp = lp->next)
+    {
+      print_mount_point (lp->data);
+      exo_mount_point_free (lp->data);
+    }
+  g_slist_free (mount_points);
+  g_print ("\n");
+
+  mount_points = exo_mount_point_list_configured (&err);
+  if (G_UNLIKELY (err != NULL))
+    {
+      g_printerr ("Failed to query configured mount points: %s\n", 
err->message);
+      g_error_free (err);
+      return EXIT_FAILURE;
+    }
+  g_print ("Configured mount points:\n------------------------\n");
+  for (lp = mount_points; lp != NULL; lp = lp->next)
+    {
+      print_mount_point (lp->data);
+      exo_mount_point_free (lp->data);
+    }
+  g_slist_free (mount_points);
+  g_print ("\n");
+
+  return EXIT_SUCCESS;
+}
+
+


Property changes on: libexo/trunk/tests/test-exo-mount-point.c
___________________________________________________________________
Name: svn:keywords
   + Author Date Id Rev

_______________________________________________
Xfce4-commits mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/xfce4-commits

Reply via email to