Git Repositories

2006-09-08 Benedikt Meurer <benny@xfce.org>
authorBenedikt Meurer <benny@xfce.org>
Fri, 8 Sep 2006 19:54:59 +0000 (19:54 +0000)
committerBenedikt Meurer <benny@xfce.org>
Fri, 8 Sep 2006 19:54:59 +0000 (19:54 +0000)
* acinclude.m4, configure.in.in, thunar-vfs/thunar-vfs-volume-hal.c:
  Add support for FreeBSD to the HAL based volume manager.

(Old svn revision: 23108)

ChangeLog
acinclude.m4
configure.in.in
thunar-vfs/thunar-vfs-volume-hal.c

index 79b39f4..920cf57 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-09-08     Benedikt Meurer <benny@xfce.org>
+
+       * acinclude.m4, configure.in.in, thunar-vfs/thunar-vfs-volume-hal.c:
+         Add support for FreeBSD to the HAL based volume manager.
+
 2006-09-06     Benedikt Meurer <benny@xfce.org>
 
        * configure.in.in: Fix typo, -DNDEBUG instead of -NDEBUG.
index b14229c..1e036e1 100644 (file)
@@ -196,17 +196,25 @@ AC_HELP_STRING([--with-volume-manager=@<:@auto/freebsd/hal/none@:>@], [The volum
   elif test x"$with_volume_manager" = x"none"; then
     ac_bm_thunar_vfs_volume_impl=none
   else
-    dnl # Check target platform (auto-detection)
-    case "$target_os" in
-    freebsd*)
-      dnl # FreeBSD is fully supported
-      ac_bm_thunar_vfs_volume_impl=freebsd
-      ;;
-    *)
-      dnl # Otherwise, check if we have HAL
-      XDT_CHECK_PACKAGE([HAL], [hal-storage], [0.5.0], [ac_bm_thunar_vfs_volume_impl=hal], [ac_bm_thunar_vfs_volume_impl=none])
-      ;;
-    esac
+    dnl # Check if HAL is available
+    XDT_CHECK_PACKAGE([HAL], [hal-storage], [0.5.0],
+    [
+      dnl # HAL is available, use it
+      ac_bm_thunar_vfs_volume_impl=hal
+    ],
+    [
+      dnl # Check operating system type
+      case "$target_os" in
+      freebsd*)
+        dnl # FreeBSD is fully supported
+        ac_bm_thunar_vfs_volume_impl=freebsd
+        ;;
+      *)
+        dnl # Otherwise no volume support
+        ac_bm_thunar_vfs_volume_impl=none
+        ;;
+      esac
+    ])
   fi
 
   dnl # We need HAL >= 0.5.x and D-BUS >= 0.23 for the HAL volume manager
index a613748..3702535 100644 (file)
@@ -106,18 +106,18 @@ AC_CHECK_HEADERS([ctype.h dirent.h errno.h fcntl.h fnmatch.h fstab.h grp.h \
                   regex.h sched.h setjmp.h signal.h stdarg.h stdlib.h \
                   string.h sys/xattr.h sys/extattr.h sys/cdio.h sys/mman.h \
                   sys/mount.h sys/param.h sys/resource.h sys/stat.h \
-                  sys/statfs.h sys/statvfs.h sys/time.h sys/uio.h \
+                  sys/statfs.h sys/statvfs.h sys/time.h sys/ucred.h sys/uio.h \
                   sys/vfs.h sys/wait.h time.h wchar.h wctype.h])
 
 dnl ************************************
 dnl *** Check for standard functions ***
 dnl ************************************
 AC_FUNC_MMAP()
-AC_CHECK_FUNCS([attropen extattr_get_fd fgetxattr getdents lchmod localeconv \
-                localtime_r mbrtowc mkdtemp mkfifo posix_madvise pread \
-                pwrite readdir_r sched_yield setgroupent setpassent \
-                setpriority statfs statvfs statvfs1 strcoll strlcpy strptime \
-                symlink])
+AC_CHECK_FUNCS([attropen extattr_get_fd fgetxattr getdents getfsspec getfsstat \
+                lchmod localeconv localtime_r mbrtowc mkdtemp mkfifo \
+                posix_madvise pread pwrite readdir_r sched_yield setgroupent \
+                setpassent setpriority statfs statvfs statvfs1 strcoll strlcpy \
+                strptime symlink])
 
 dnl ******************************************
 dnl *** Linux/glibc specified work-arounds ***
index 0aaa14a..9f968c1 100644 (file)
 #include <config.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_ERRNO_H
 #include <errno.h>
 #endif
+#ifdef HAVE_FSTAB_H
+#include <fstab.h>
+#endif
 #ifdef HAVE_MNTENT_H
 #include <mntent.h>
 #endif
 
 
 
-static void                  thunar_vfs_volume_hal_class_init       (ThunarVfsVolumeHalClass *klass);
-static void                  thunar_vfs_volume_hal_finalize         (GObject                 *object);
-static ThunarVfsVolumeKind   thunar_vfs_volume_hal_get_kind         (ThunarVfsVolume         *volume);
-static const gchar          *thunar_vfs_volume_hal_get_name         (ThunarVfsVolume         *volume);
-static ThunarVfsVolumeStatus thunar_vfs_volume_hal_get_status       (ThunarVfsVolume         *volume);
-static ThunarVfsPath        *thunar_vfs_volume_hal_get_mount_point  (ThunarVfsVolume         *volume);
-static gboolean              thunar_vfs_volume_hal_eject            (ThunarVfsVolume         *volume,
-                                                                     GtkWidget               *window,
-                                                                     GError                 **error);
-static gboolean              thunar_vfs_volume_hal_mount            (ThunarVfsVolume         *volume,
-                                                                     GtkWidget               *window,
-                                                                     GError                 **error);
-static gboolean              thunar_vfs_volume_hal_unmount          (ThunarVfsVolume         *volume,
-                                                                     GtkWidget               *window,
-                                                                     GError                 **error);
-static ThunarVfsPath        *thunar_vfs_volume_hal_find_mount_point (ThunarVfsVolumeHal      *volume_hal,
-                                                                     const gchar             *file);
-static void                  thunar_vfs_volume_hal_update           (ThunarVfsVolumeHal      *volume_hal,
-                                                                     LibHalContext           *context,
-                                                                     LibHalVolume            *hv,
-                                                                     LibHalDrive             *hd);
+static void                  thunar_vfs_volume_hal_class_init               (ThunarVfsVolumeHalClass  *klass);
+static void                  thunar_vfs_volume_hal_finalize                 (GObject                  *object);
+static ThunarVfsVolumeKind   thunar_vfs_volume_hal_get_kind                 (ThunarVfsVolume          *volume);
+static const gchar          *thunar_vfs_volume_hal_get_name                 (ThunarVfsVolume          *volume);
+static ThunarVfsVolumeStatus thunar_vfs_volume_hal_get_status               (ThunarVfsVolume          *volume);
+static ThunarVfsPath        *thunar_vfs_volume_hal_get_mount_point          (ThunarVfsVolume          *volume);
+static gboolean              thunar_vfs_volume_hal_eject                    (ThunarVfsVolume          *volume,
+                                                                             GtkWidget                *window,
+                                                                             GError                  **error);
+static gboolean              thunar_vfs_volume_hal_mount                    (ThunarVfsVolume          *volume,
+                                                                             GtkWidget                *window,
+                                                                             GError                  **error);
+static gboolean              thunar_vfs_volume_hal_unmount                  (ThunarVfsVolume          *volume,
+                                                                             GtkWidget                *window,
+                                                                             GError                  **error);
+static ThunarVfsPath        *thunar_vfs_volume_hal_find_active_mount_point  (const ThunarVfsVolumeHal *volume_hal);
+static ThunarVfsPath        *thunar_vfs_volume_hal_find_fstab_mount_point   (const ThunarVfsVolumeHal *volume_hal);
+static void                  thunar_vfs_volume_hal_update                   (ThunarVfsVolumeHal       *volume_hal,
+                                                                             LibHalContext            *context,
+                                                                             LibHalVolume             *hv,
+                                                                             LibHalDrive              *hd);
 
 
 
@@ -204,7 +217,7 @@ thunar_vfs_volume_hal_eject (ThunarVfsVolume *volume,
   gchar              *quoted;
 
   /* check if the volume is currently mounted */
-  path = thunar_vfs_volume_hal_find_mount_point (volume_hal, "/proc/mounts");
+  path = thunar_vfs_volume_hal_find_active_mount_point (volume_hal);
   if (G_LIKELY (path != NULL))
     {
       /* try to unmount the volume first */
@@ -307,7 +320,7 @@ thunar_vfs_volume_hal_mount (ThunarVfsVolume *volume,
   if (G_LIKELY (result))
     {
       /* try to figure out where the device was mounted */
-      path = thunar_vfs_volume_hal_find_mount_point (volume_hal, "/proc/mounts");
+      path = thunar_vfs_volume_hal_find_active_mount_point (volume_hal);
       if (G_LIKELY (path != NULL))
         {
           /* we must have been mounted successfully */
@@ -395,15 +408,16 @@ thunar_vfs_volume_hal_unmount (ThunarVfsVolume *volume,
 
 
 static ThunarVfsPath*
-thunar_vfs_volume_hal_find_mount_point (ThunarVfsVolumeHal *volume_hal,
-                                        const gchar        *file)
+thunar_vfs_volume_hal_find_active_mount_point (const ThunarVfsVolumeHal *volume_hal)
 {
   ThunarVfsPath *mount_point = NULL;
+
+#if defined(HAVE_SETMNTENT) /* Linux */
   struct mntent *mntent;
   FILE          *fp;
 
-  /* try to open that file as mnt entry list */
-  fp = setmntent (file, "r");
+  /* try to open the /proc/mounts file */
+  fp = setmntent ("/proc/mounts", "r");
   if (G_LIKELY (fp != NULL))
     {
       /* process all mnt entries */
@@ -419,12 +433,98 @@ thunar_vfs_volume_hal_find_mount_point (ThunarVfsVolumeHal *volume_hal,
             {
               /* and there's our mount point */
               mount_point = thunar_vfs_path_new (mntent->mnt_dir, NULL);
+              break;
             }
         }
 
       /* close the file handle */
       endmntent (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; ++n)
+        {
+          /* check if this is the entry we are looking for */
+          if (exo_str_is_equal (mntbuf[n].f_mntfromname, volume_hal->device_file))
+            {
+              /* and there's our mount point */
+              mount_point = thunar_vfs_path_new (mntbuf[n].f_mntonname, NULL);
+              break;
+            }
+        }
+
+      /* release the buffer */
+      g_free (mntbuf);
+    }
+#else
+#error "Add support for your operating system here."
+#endif
+
+  return mount_point;
+}
+
+
+
+static ThunarVfsPath*
+thunar_vfs_volume_hal_find_fstab_mount_point (const ThunarVfsVolumeHal *volume_hal)
+{
+  ThunarVfsPath *mount_point = NULL;
+
+#if defined(HAVE_SETMNTENT) /* Linux */
+  struct mntent *mntent;
+  FILE          *fp;
+
+  /* try to open the /etc/fstab file */
+  fp = setmntent ("/proc/fstab", "r");
+  if (G_LIKELY (fp != NULL))
+    {
+      /* process all mnt entries */
+      while (mount_point == NULL)
+        {
+          /* read the next entry */
+          mntent = getmntent (fp);
+          if (mntent == NULL)
+            break;
+
+          /* check if this is the entry we are looking for */
+          if (exo_str_is_equal (mntent->mnt_fsname, volume_hal->device_file))
+            {
+              /* and there's our mount point */
+              mount_point = thunar_vfs_path_new (mntent->mnt_dir, NULL);
+              break;
+            }
+        }
+
+      /* close the file handle */
+      endmntent (fp);
+    }
+#elif defined(HAVE_GETFSSPEC) /* FreeBSD */
+  struct fstab *fs;
+
+  /* check if we have an fstab entry for the device file */
+  fs = getfsspec (volume_hal->device_file);
+  if (G_LIKELY (fs != NULL))
+    {
+      /* and there's out mount point */
+      mount_point = thunar_vfs_path_new (fs->fs_file, NULL);
+    }
+#else
+#error "Add support for your operating system here."
+#endif
 
   return mount_point;
 }
@@ -568,8 +668,8 @@ thunar_vfs_volume_hal_update (ThunarVfsVolumeHal *volume_hal,
     }
   else
     {
-      /* we don't trust HAL, so let's see what /proc/mounts says about the volume */
-      volume_hal->mount_point = thunar_vfs_volume_hal_find_mount_point (volume_hal, "/proc/mounts");
+      /* we don't trust HAL, so let's see what the kernel says about the volume */
+      volume_hal->mount_point = thunar_vfs_volume_hal_find_active_mount_point (volume_hal);
 
       /* we must have been mounted successfully if we have a mount point */
       if (G_LIKELY (volume_hal->mount_point != NULL))
@@ -589,7 +689,7 @@ thunar_vfs_volume_hal_update (ThunarVfsVolumeHal *volume_hal,
         }
 
       /* lets see, maybe /etc/fstab knows where to mount */
-      volume_hal->mount_point = thunar_vfs_volume_hal_find_mount_point (volume_hal, "/etc/fstab");
+      volume_hal->mount_point = thunar_vfs_volume_hal_find_fstab_mount_point (volume_hal);
 
       /* if we still don't have a mount point, ask HAL */
       if (G_UNLIKELY (volume_hal->mount_point == NULL))