summaryrefslogtreecommitdiff
path: root/sysutils/hal/files
diff options
context:
space:
mode:
authorjmcneill <jmcneill>2008-12-01 02:02:33 +0000
committerjmcneill <jmcneill>2008-12-01 02:02:33 +0000
commit9839b60a5a38bd9cf8d60ef1b853a0805791a204 (patch)
tree702709299e5329bb8a024772bc5810f79bd40cba /sysutils/hal/files
parent2087c1dc118f65fa2c918059c65fc11a5c887195 (diff)
downloadpkgsrc-9839b60a5a38bd9cf8d60ef1b853a0805791a204.tar.gz
hald-netbsd: add basic support for automounting non-optical media. Still
some bugs to work out, but it's a start. Bump PKGREVISION.
Diffstat (limited to 'sysutils/hal/files')
-rw-r--r--sysutils/hal/files/hald-netbsd/Makefile.am7
-rw-r--r--sysutils/hal/files/hald-netbsd/devinfo.c2
-rw-r--r--sysutils/hal/files/hald-netbsd/devinfo_mass.c341
-rw-r--r--sysutils/hal/files/hald-netbsd/devinfo_mass.h37
-rw-r--r--sysutils/hal/files/hald-netbsd/osspec.c20
-rw-r--r--sysutils/hal/files/hald-netbsd/vfsstat.c157
-rw-r--r--sysutils/hal/files/hald-netbsd/vfsstat.h36
7 files changed, 581 insertions, 19 deletions
diff --git a/sysutils/hal/files/hald-netbsd/Makefile.am b/sysutils/hal/files/hald-netbsd/Makefile.am
index 95adf63394b..6f278ee4e8c 100644
--- a/sysutils/hal/files/hald-netbsd/Makefile.am
+++ b/sysutils/hal/files/hald-netbsd/Makefile.am
@@ -8,16 +8,17 @@ AM_CPPFLAGS = \
-DPACKAGE_LOCALE_DIR=\""$(localedir)"\" \
-DPACKAGE_LOCALSTATEDIR=\""$(localstatedir)"\" \
-I$(top_srcdir) -I.. \
- @GLIB_CFLAGS@ @DBUS_CFLAGS@ @POLKIT_CFLAGS@
+ @GLIB_CFLAGS@ @DBUS_CFLAGS@ @POLKIT_CFLAGS@ @VOLUME_ID_CFLAGS@
if HALD_COMPILE_NETBSD
noinst_LTLIBRARIES = libhald_netbsd.la
endif
libhald_netbsd_la_SOURCES = \
- osspec.c drvctl.c envsys.c \
+ osspec.c drvctl.c envsys.c vfsstat.c \
devinfo.c devinfo_misc.c devinfo_audio.c devinfo_video.c \
+ devinfo_mass.c \
hotplug.c hal-file-monitor.c
# devinfo_pci.c devinfo_storage.c devinfo_usb.c
-libhald_netbsd_la_LDFLAGS = -lprop
+libhald_netbsd_la_LDFLAGS = -lprop @VOLUME_ID_LIBS@
diff --git a/sysutils/hal/files/hald-netbsd/devinfo.c b/sysutils/hal/files/hald-netbsd/devinfo.c
index 9e894b80571..a92f4929fa2 100644
--- a/sysutils/hal/files/hald-netbsd/devinfo.c
+++ b/sysutils/hal/files/hald-netbsd/devinfo.c
@@ -32,6 +32,7 @@
#include "devinfo_video.h"
#include "devinfo_pci.h"
#include "devinfo_storage.h"
+#include "devinfo_mass.h"
#include "devinfo_usb.h"
#include "devinfo_misc.h"
#include "devinfo_cpu.h"
@@ -153,6 +154,7 @@ static DevinfoDevHandler *devinfo_handlers[] = {
&devinfo_audio_mixer_handler,
&devinfo_audio_dsp_handler,
&devinfo_video_handler,
+ &devinfo_mass_handler,
&devinfo_default_handler,
NULL
};
diff --git a/sysutils/hal/files/hald-netbsd/devinfo_mass.c b/sysutils/hal/files/hald-netbsd/devinfo_mass.c
new file mode 100644
index 00000000000..ee355b6c9a9
--- /dev/null
+++ b/sysutils/hal/files/hald-netbsd/devinfo_mass.c
@@ -0,0 +1,341 @@
+/* $NetBSD: devinfo_mass.c,v 1.1 2008/12/01 02:02:33 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2008 Jared D. McNeill <jmcneill@invisible.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/disklabel.h>
+#include <sys/bootblock.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <paths.h>
+#include <unistd.h>
+
+#include "../osspec.h"
+#include "../logger.h"
+#include "../hald.h"
+#include "../hald_dbus.h"
+#include "../device_info.h"
+#include "../util.h"
+#include "../ids.h"
+#include "hotplug.h"
+#include "devinfo.h"
+#include "devinfo_mass.h"
+#include "drvctl.h"
+
+#include <libvolume_id.h>
+
+HalDevice *devinfo_mass_add(HalDevice *parent, const char *devnode, char *devfs_path, char *device_type);
+HalDevice *devinfo_mass_disklabel_add(HalDevice *parent, const char *devnode, char *devfs_path, char *device_type);
+
+DevinfoDevHandler devinfo_mass_handler = {
+ devinfo_mass_add,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+DevinfoDevHandler devinfo_mass_disklabel_handler = {
+ devinfo_mass_disklabel_add,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
+static const char *
+devinfo_mass_get_fstype(uint8_t fstype)
+{
+ switch (fstype) {
+ case FS_BSDFFS:
+ return "ffs";
+ case FS_MSDOS:
+ return "vfat";
+ case FS_EX2FS:
+ return "ext2";
+ case FS_NTFS:
+ return "ntfs";
+ default:
+ return NULL;
+ }
+}
+
+static uint8_t
+devinfo_mass_get_mbrtype(uint8_t fstype)
+{
+ switch (fstype) {
+ case FS_BSDFFS:
+ return MBR_PTYPE_NETBSD;
+ case FS_MSDOS:
+ return MBR_PTYPE_FAT32; /* XXX */
+ case FS_EX2FS:
+ return MBR_PTYPE_LNXEXT2;
+ case FS_NTFS:
+ return MBR_PTYPE_NTFS;
+ default:
+ return MBR_PTYPE_UNUSED;
+ }
+}
+
+HalDevice *
+devinfo_mass_add(HalDevice *parent, const char *devnode, char *devfs_path, char *device_type)
+{
+ HalDevice *d = NULL;
+ prop_dictionary_t dict;
+ struct disklabel label;
+ struct stat st;
+ const char *driver;
+ char *rdevpath, *devpath;
+ char *childnode;
+ char *parent_devnode;
+ int16_t unit;
+ int i, fd;
+
+ if (drvctl_find_device (devnode, &dict) == FALSE || dict == NULL)
+ return NULL;
+
+ if (prop_dictionary_get_int16 (dict, "device-unit", &unit) == false ||
+ prop_dictionary_get_cstring_nocopy (dict, "device-driver", &driver) == false) {
+ prop_object_release (dict);
+ return NULL;
+ }
+
+ if (strcmp (driver, "wd") != 0 && strcmp (driver, "sd") != 0) {
+ prop_object_release (dict);
+ return NULL;
+ }
+
+ sleep (1);
+
+ devpath = g_strdup_printf ("/dev/%s%c", devnode, RAW_PART + 'a');
+ rdevpath = g_strdup_printf ("/dev/r%s%c", devnode, RAW_PART + 'a');
+ HAL_INFO ((" going to open %s", rdevpath));
+ fd = open (rdevpath, O_RDONLY);
+ if (fd < 0) {
+ HAL_WARNING (("couldn't open %s: %s", rdevpath, strerror (errno)));
+ g_free (rdevpath);
+ g_free (devpath);
+ return NULL;
+ }
+
+ HAL_INFO ((" going to DIOCGDINFO %s", rdevpath));
+ if (ioctl (fd, DIOCGDINFO, &label) == -1) {
+ HAL_WARNING (("DIOCGDINFO failed on %s: %s", rdevpath, strerror (errno)));
+ g_free (rdevpath);
+ g_free (devpath);
+ close (fd);
+ return NULL;
+ }
+
+ close (fd);
+
+ d = hal_device_new ();
+
+ devinfo_set_default_properties (d, parent, devnode, devfs_path);
+
+ hal_device_add_capability (d, "block");
+ hal_device_property_set_string (d, "info.subsystem", "block");
+ hal_device_property_set_string (d, "block.device", devpath);
+ if (stat (devpath, &st) == 0) {
+ hal_device_property_set_int (d, "block.major", major (st.st_rdev));
+ hal_device_property_set_int (d, "block.minor", minor (st.st_rdev));
+ }
+ hal_device_property_set_bool (d, "block.is_volume", FALSE);
+ hal_device_property_set_bool (d, "block.no_partitions", FALSE);
+ hal_device_property_set_bool (d, "block.have_scanned", TRUE);
+
+ hal_device_add_capability (d, "storage");
+ hal_device_property_set_string (d, "info.category", "storage");
+ parent_devnode = hal_device_property_get_string (parent, "netbsd.device");
+ if (strstr (parent_devnode, "umass") == parent_devnode)
+ hal_device_property_set_string (d, "storage.bus", "usb");
+ else if (strstr (parent_devnode, "atabus") == parent_devnode)
+ hal_device_property_set_string (d, "storage.bus", "ide");
+ else
+ hal_device_property_set_string (d, "storage.bus", "scsi");
+ hal_device_property_set_string (d, "storage.device_type", "disk");
+ hal_device_property_set_bool (d, "storage.removable", label.d_flags & D_REMOVABLE ? TRUE : FALSE);
+ if (label.d_flags & D_REMOVABLE) {
+ hal_device_property_set_bool (d, "storage.removable.media_available", TRUE);
+ hal_device_property_set_uint64 (d, "storage.removable.media_size",
+ (uint64_t)label.d_secsize * (uint64_t)label.d_secperunit);
+ hal_device_property_set_uint64 (d, "storage.size", 0);
+ hal_device_property_set_bool (d, "storage.hotpluggable", TRUE);
+ hal_device_property_set_bool (d, "storage.automount_enabled_hint", TRUE);
+ } else {
+ hal_device_property_set_bool (d, "storage.removable.media_available", FALSE);
+ hal_device_property_set_uint64 (d, "storage.removable.media_size", 0);
+ hal_device_property_set_uint64 (d, "storage.size",
+ (uint64_t)label.d_secsize * (uint64_t)label.d_secperunit);
+ hal_device_property_set_bool (d, "storage.hotpluggable", FALSE);
+ hal_device_property_set_bool (d, "storage.automount_enabled_hint", FALSE);
+ }
+ hal_device_property_set_bool (d, "storage.no_partitions_hint", FALSE);
+ hal_device_property_set_bool (d, "storage.requires_eject", FALSE);
+ hal_device_property_set_bool (d, "storage.removable.support_async_notification", FALSE);
+ hal_device_property_set_string (d, "storage.partitioning_scheme", "mbr");
+ hal_device_property_set_string (d, "storage.originating_device",
+ hal_device_property_get_string (d, "info.udi"));
+ hal_device_property_set_string (d, "storage.model", label.d_packname);
+ hal_device_property_set_string (d, "storage.vendor", label.d_typename);
+
+ devinfo_add_enqueue (d, devfs_path, &devinfo_mass_handler);
+
+ for (i = 0; i < MAXPARTITIONS; i++) {
+ const char *fstype;
+
+ fstype = devinfo_mass_get_fstype(label.d_partitions[i].p_fstype);
+ if (fstype == NULL)
+ continue;
+
+ childnode = g_strdup_printf ("%s%c", devnode, 'a' + i);
+ HAL_INFO ((" adding %s on %s", childnode, rdevpath));
+ devinfo_mass_disklabel_add (d, childnode, childnode, childnode);
+ g_free (childnode);
+ }
+
+ HAL_INFO ((" returning"));
+ g_free (rdevpath);
+ g_free (devpath);
+
+done:
+ prop_object_release (dict);
+
+ return d;
+}
+
+HalDevice *
+devinfo_mass_disklabel_add(HalDevice *parent, const char *devnode, char *devfs_path, char *device_type)
+{
+ HalDevice *d = NULL;
+ struct disklabel label;
+ struct partition *part;
+ struct stat st;
+ const char *driver;
+ char *devpath, *rdevpath, *partname;
+ char *childnode;
+ char unit;
+ struct volume_id *vid;
+ uint64_t psize, msize;
+ int i, fd;
+
+ partname = devnode;
+ unit = partname[strlen (partname) - 1] - 'a';
+
+ if (unit >= MAXPARTITIONS)
+ return NULL;
+
+ devpath = g_strdup_printf ("/dev/%s", partname);
+ rdevpath = g_strdup_printf ("/dev/r%s", partname);
+ fd = open (rdevpath, O_RDONLY);
+ if (fd < 0) {
+ HAL_WARNING (("couldn't open %s: %s", rdevpath, strerror (errno)));
+ g_free (rdevpath);
+ return NULL;
+ }
+
+ if (ioctl (fd, DIOCGDINFO, &label) == -1) {
+ HAL_WARNING (("DIOCGDINFO failed on %s: %s", rdevpath, strerror (errno)));
+ g_free (rdevpath);
+ close (fd);
+ return NULL;
+ }
+ part = &label.d_partitions[unit];
+
+ d = hal_device_new ();
+
+ devinfo_set_default_properties (d, parent, devnode, devfs_path);
+
+ hal_device_add_capability (d, "block");
+ hal_device_property_set_string (d, "info.subsystem", "block");
+ hal_device_property_set_string (d, "info.category", "volume");
+ hal_device_property_set_string (d, "block.device", devpath);
+ hal_device_property_set_string (d, "block.storage_device",
+ hal_device_property_get_string (parent, "info.udi"));
+
+ if (stat (devpath, &st) == 0) {
+ hal_device_property_set_int (d, "block.major", major (st.st_rdev));
+ hal_device_property_set_int (d, "block.minor", minor (st.st_rdev));
+ }
+
+ hal_device_property_set_bool (d, "block.is_volume", TRUE);
+ hal_device_property_set_bool (d, "block.no_partitions", FALSE);
+ hal_device_property_set_bool (d, "block.have_scanned", TRUE);
+
+ hal_device_add_capability (d, "volume");
+ hal_device_property_set_bool (d, "volume.ignore", FALSE);
+ hal_device_property_set_bool (d, "volume.is_mounted", FALSE);
+ hal_device_property_set_bool (d, "volume.is_mounted_read_only", FALSE);
+ hal_device_property_set_string (d, "volume.mount_point", "");
+ hal_device_property_set_string (d, "volume.fsusage", "filesystem");
+ hal_device_property_set_string (d, "volume.fstype", devinfo_mass_get_fstype (part->p_fstype));
+ hal_device_property_set_bool (d, "volume.is_disc", FALSE);
+
+ hal_device_property_set_string (d, "volume.label", "");
+ hal_device_property_set_string (d, "volume.partition.label", "");
+ hal_device_property_set_string (d, "volume.uuid", "");
+ hal_device_property_set_string (d, "volume.partition.uuid", "");
+
+ psize = (uint64_t)part->p_size * (uint64_t)label.d_secsize;
+ msize = (uint64_t)label.d_secsize * (uint64_t)label.d_secperunit;
+
+ hal_device_property_set_uint64 (d, "volume.size", psize);
+ hal_device_property_set_int (d, "volume.block_size", label.d_secsize);
+ hal_device_property_set_uint64 (d, "volume.num_blocks", part->p_size);
+ hal_device_property_set_uint64 (d, "volume.partition.media_size", msize);
+
+ hal_device_property_set_bool (d, "volume.is_partition", TRUE);
+ hal_device_property_set_int (d, "volume.partition.number", unit);
+ hal_device_property_set_string (d, "volume.partition.scheme", "mbr");
+
+ vid = volume_id_open_fd (fd);
+ if (vid) {
+ if (volume_id_probe_all (vid, 0, psize) == 0) {
+ hal_device_property_set_string (d, "volume.label", vid->label);
+ hal_device_property_set_string (d, "volume.partition.label", vid->label);
+ hal_device_property_set_string (d, "volume.uuid", vid->uuid);
+ hal_device_property_set_string (d, "volume.partition.uuid", vid->uuid);
+ }
+ volume_id_close (vid);
+ }
+
+ devinfo_add_enqueue (d, devfs_path, &devinfo_mass_disklabel_handler);
+
+ close (fd);
+
+ g_free (rdevpath);
+ g_free (devpath);
+
+ return d;
+}
diff --git a/sysutils/hal/files/hald-netbsd/devinfo_mass.h b/sysutils/hal/files/hald-netbsd/devinfo_mass.h
new file mode 100644
index 00000000000..1b7bdc91f48
--- /dev/null
+++ b/sysutils/hal/files/hald-netbsd/devinfo_mass.h
@@ -0,0 +1,37 @@
+/* $NetBSD: devinfo_mass.h,v 1.1 2008/12/01 02:02:33 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2008 Jared D. McNeill <jmcneill@invisible.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef DEVINFO_MASS_H
+#define DEVINFO_MASS_H
+
+#include "devinfo.h"
+
+extern DevinfoDevHandler devinfo_mass_handler;
+extern DevinfoDevHandler devinfo_mass_disklabel_handler;
+
+#endif /* DEVINFO_MASS_H */
diff --git a/sysutils/hal/files/hald-netbsd/osspec.c b/sysutils/hal/files/hald-netbsd/osspec.c
index da891e96f72..44a035dd81a 100644
--- a/sysutils/hal/files/hald-netbsd/osspec.c
+++ b/sysutils/hal/files/hald-netbsd/osspec.c
@@ -164,23 +164,14 @@ dsk_to_rdsk(char *dsk)
static void
mntinfo_event_init ()
{
-#if notyet
- g_timeout_add(1000, mntinfo_timeout, NULL);
-#endif
+ g_timeout_add (1000, mntinfo_timeout, NULL);
}
static gboolean
mntinfo_timeout (gpointer user_data)
{
-#if notyet
- struct statvfs *statvfs;
-
- HAL_INFO (("mntinfo timeout"));
-
- if (!hald_is_initialising) {
- devinfo_storage_mnttab_event (NULL);
- }
-#endif
+ if (!hald_is_initialising)
+ vfsstat_event (NULL);
return TRUE;
}
@@ -188,8 +179,5 @@ mntinfo_timeout (gpointer user_data)
void
osspec_refresh_mount_state_for_block_device (HalDevice *d)
{
-#warning osspec_refresh_mount_state_for_block_device TODO
-#if notyet
- devinfo_storage_mnttab_event (d);
-#endif
+ vfsstat_event (d);
}
diff --git a/sysutils/hal/files/hald-netbsd/vfsstat.c b/sysutils/hal/files/hald-netbsd/vfsstat.c
new file mode 100644
index 00000000000..9a09c0ef531
--- /dev/null
+++ b/sysutils/hal/files/hald-netbsd/vfsstat.c
@@ -0,0 +1,157 @@
+/* $NetBSD: vfsstat.c,v 1.1 2008/12/01 02:02:33 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2008 Jared D. McNeill <jmcneill@invisible.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/statvfs.h>
+#include <sys/ioctl.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <paths.h>
+#include <unistd.h>
+
+#include "../osspec.h"
+#include "../logger.h"
+#include "../hald.h"
+#include "../hald_dbus.h"
+#include "../hald_runner.h"
+#include "../device_info.h"
+#include "../util.h"
+#include "../ids.h"
+#include "hotplug.h"
+#include "devinfo.h"
+#include "vfsstat.h"
+#include "drvctl.h"
+
+static void
+vfsstat_cleanup_mountpoint_cb(HalDevice *d, guint32 exit_type,
+ gint return_code, gchar **error, gpointer data1, gpointer data2)
+{
+ char *mount_point = data1;
+
+ HAL_INFO (("cleaned up mount point %s", mount_point));
+
+ g_free (mount_point);
+}
+
+void
+vfsstat_event(HalDevice *volume)
+{
+ GSList *volumes, *v;
+ HalDevice *d;
+ struct statvfs *statvfs;
+ int nmounts, i;
+
+ if (volume == NULL)
+ volumes = hal_device_store_match_multiple_key_value_string (hald_get_gdl (), "info.category", "volume");
+ else
+ volumes = g_slist_append (NULL, volume);
+
+ if (volumes == NULL)
+ return;
+
+ nmounts = getvfsstat (NULL, 0, ST_WAIT);
+ if (nmounts <= 0)
+ return;
+ statvfs = calloc (nmounts, sizeof (*statvfs));
+ if (statvfs == NULL)
+ return;
+ nmounts = getvfsstat (statvfs, nmounts * sizeof (*statvfs), ST_WAIT);
+ if (nmounts <= 0)
+ goto done;
+
+ for (i = 0; i < nmounts; i++)
+ for (v = volumes; v; v = g_slist_next (v)) {
+ const char *devpath;
+
+ d = HAL_DEVICE (v->data);
+ devpath = hal_device_property_get_string (d, "block.device");
+ if (devpath == NULL || strlen (devpath) == 0)
+ continue;
+ if (strcmp (devpath, statvfs[i].f_mntfromname) != 0)
+ continue;
+
+ device_property_atomic_update_begin ();
+ hal_device_property_set_bool (d, "volume.is_mounted", TRUE);
+ hal_device_property_set_bool (d, "volume.is_mounted_read_only",
+ statvfs[i].f_flag & ST_RDONLY ? TRUE : FALSE);
+ hal_device_property_set_string (d, "volume.mount_point", statvfs[i].f_mntonname);
+ device_property_atomic_update_end ();
+
+ volumes = g_slist_delete_link (volumes, v);
+ }
+
+ for (v = volumes; v; v = g_slist_next (v)) {
+ const char *mount_path;
+
+ d = HAL_DEVICE (v->data);
+ mount_path = g_strdup (hal_device_property_get_string (d, "volume.mount_point"));
+ if (mount_path == NULL || strlen (mount_path) == 0) {
+ if (mount_path)
+ g_free (mount_path);
+ continue;
+ }
+
+ device_property_atomic_update_begin ();
+ hal_device_property_set_bool (d, "volume.is_mounted", FALSE);
+ hal_device_property_set_bool (d, "volume.is_mounted_read_only", FALSE);
+ hal_device_property_set_string (d, "volume.mount_point", "");
+ device_property_atomic_update_end ();
+
+ if (hal_util_is_mounted_by_hald (mount_path)) {
+ char *cleanup_stdin;
+ char *extra_env[2];
+
+ extra_env[0] = g_strdup_printf ("HALD_CLEANUP=%s", mount_path);
+ extra_env[1] = NULL;
+ cleanup_stdin = "\n";
+
+ hald_runner_run_method (d,
+ "hal-storage-cleanup-mountpoint",
+ extra_env,
+ cleanup_stdin, TRUE,
+ 0,
+ vfsstat_cleanup_mountpoint_cb,
+ g_strdup (mount_path), NULL);
+
+ g_free (extra_env[0]);
+ }
+
+ g_free (mount_path);
+ }
+
+ g_slist_free (volumes);
+
+done:
+ free (statvfs);
+}
diff --git a/sysutils/hal/files/hald-netbsd/vfsstat.h b/sysutils/hal/files/hald-netbsd/vfsstat.h
new file mode 100644
index 00000000000..a78bc7aa527
--- /dev/null
+++ b/sysutils/hal/files/hald-netbsd/vfsstat.h
@@ -0,0 +1,36 @@
+/* $NetBSD: vfsstat.h,v 1.1 2008/12/01 02:02:33 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2008 Jared D. McNeill <jmcneill@invisible.ca>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef VFSSTAT_H
+#define VFSSTAT_H
+
+#include "devinfo.h"
+
+void vfsstat_event(HalDevice *volume);
+
+#endif /* VFSSTAT_H */