$NetBSD: patch-aa,v 1.4 2008/12/20 21:11:05 jmcneill Exp $

--- tools/hal-storage-mount.c.orig	2008-05-07 19:24:23.000000000 -0400
+++ tools/hal-storage-mount.c	2008-12-20 15:34:05.000000000 -0500
@@ -31,7 +31,7 @@
 #include <string.h>
 #include <glib.h>
 #include <glib/gstdio.h>
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__)
 #include <fstab.h>
 #include <sys/param.h>
 #include <sys/ucred.h>
@@ -41,6 +41,13 @@
 #elif sun
 #include <sys/mnttab.h>
 #include <sys/vfstab.h>
+#elif __NetBSD__
+#include <fstab.h>
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <unistd.h>
 #else
 #include <mntent.h>
 #endif
@@ -54,10 +61,14 @@
 
 #include "hal-storage-shared.h"
 
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__DragonFly__)
 #define MOUNT		"/sbin/mount"
 #define MOUNT_OPTIONS	"noexec,nosuid"
 #define MOUNT_TYPE_OPT	"-t"
+#elif __NetBSD__
+#define MOUNT		"/sbin/mount"
+#define MOUNT_OPTIONS	"noexec,nosuid,nodev"
+#define	MOUNT_TYPE_OPT	"-t"
 #elif sun
 #define MOUNT		"/sbin/mount"
 #define MOUNT_OPTIONS	"noexec,nosuid"
@@ -421,7 +432,7 @@ device_is_mounted (const char *device, c
 static const char *
 map_fstype (const char *fstype)
 {
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__DragonFly__)
 	if (! strcmp (fstype, "iso9660"))
 		return "cd9660";
 	else if (! strcmp (fstype, "ext2"))
@@ -430,6 +441,13 @@ map_fstype (const char *fstype)
 		return "ext2fs";
 	else if (! strcmp (fstype, "vfat"))
 		return "msdosfs";
+#elif __NetBSD__
+	if (! strcmp (fstype, "iso9660"))
+		return "cd9660";
+	else if (! strcmp (fstype, "ext2"))
+		return "ext2fs";
+	else if (! strcmp (fstype, "vfat"))
+		return "msdos";
 #elif sun
 	if (! strcmp (fstype, "iso9660"))
 		return "hsfs";
@@ -475,6 +493,11 @@ handle_mount (LibHalContext *hal_ctx, 
 	uid_t calling_uid;
 	gid_t calling_gid;
 #endif
+	gboolean have_rump = FALSE;
+#ifdef __NetBSD__
+	char *rump_cmd;
+	struct stat st;
+#endif
 	const char *label;
 	const char *uuid;
 
@@ -731,7 +754,6 @@ handle_mount (LibHalContext *hal_ctx, 
 	/* construct arguments to mount */
 	na = 0;
 	
-	args[na++] = MOUNT;
 	if (strlen (mount_fstype) > 0) {
 		mount_do_fstype = (char *) map_fstype (mount_fstype);
 	} else if (volume == NULL) {
@@ -742,8 +764,29 @@ handle_mount (LibHalContext *hal_ctx, 
 	} else {
 		mount_do_fstype = "auto";
 	}
-	args[na++] = MOUNT_TYPE_OPT;
-	args[na++] = mount_do_fstype;
+
+#ifdef __NetBSD__
+	rump_cmd = g_strdup_printf ("/usr/sbin/rump_%s", mount_do_fstype);
+	if (stat (rump_cmd, &st) == 0) {
+		int rump_fd = open ("/dev/puffs", O_RDONLY);
+		if (rump_fd >= 0) {
+			have_rump = TRUE;
+			close (rump_fd);
+		}
+	}
+
+	/* XXX rump_* option handling is different, disable for now */
+	have_rump = FALSE;
+
+	if (have_rump == TRUE)
+		args[na++] = rump_cmd;
+	else
+#endif
+	{
+		args[na++] = MOUNT;
+		args[na++] = MOUNT_TYPE_OPT;
+		args[na++] = mount_do_fstype;
+	}
 
 	args[na++] = "-o";
 #ifdef HAVE_UMOUNT_HAL
