hal: Branch 'master' - 2 commits

David Zeuthen david at kemper.freedesktop.org
Sat Aug 12 14:39:42 PDT 2006


 doc/spec/hal-spec-properties.xml    |    8 ++++++++
 hald/linux2/addons/addon-storage.c  |    3 ++-
 hald/linux2/blockdev.c              |    4 +++-
 hald/linux2/probing/probe-storage.c |   25 +++++++++++++++++++++----
 libhal-storage/libhal-storage.c     |    8 ++++++++
 libhal-storage/libhal-storage.h     |    1 +
 tools/lshal.c                       |    3 ++-
 7 files changed, 45 insertions(+), 7 deletions(-)

New commits:
diff-tree 0e7375f0196a55d095c8fb890bdd1b9f5e51bef0 (from 3d7863bdf1b9e34a6ea609ba54b40e9eb9a2b04a)
Author: David Zeuthen <davidz at redhat.com>
Date:   Sat Aug 12 17:39:23 2006 -0400

    fix up how we handle non-partitioned volumes
    
    We used to only creat a fakevolume if a mountable file system was
    detected. This is wrong as you can have LUKS, RAID or LVM on the main
    block device and we should detect this just like we do on
    partitions. This patch fixes that.
    
    Second, assume a piece of media is all zero'ed out. Then, on
    insertion, we don't find anything on the main block device and neither
    does the kernel so no child block devices are created. Hence, HAL
    won't spit out any event when such media is inserted. And that, so
    far, is correct as we don't detect any useful volumes. However, it
    would be useful in e.g. a disk utility program to know if media is
    actually available or not. This patch introduces a new property called
    storage.removable.media_available that is TRUE if, and only if, we have
    detected media on the storage device. Also expose this new property
    in libhal-storage.

diff --git a/doc/spec/hal-spec-properties.xml b/doc/spec/hal-spec-properties.xml
index c0791cd..89d3efd 100644
--- a/doc/spec/hal-spec-properties.xml
+++ b/doc/spec/hal-spec-properties.xml
@@ -2906,6 +2906,14 @@
             </row>
             <row>
               <entry>
+	        <literal>storage.removable.media_available</literal> (bool)
+              </entry>
+              <entry></entry>
+              <entry>Yes</entry>
+              <entry>true, if and only if, media have been detected in storage device</entry>
+            </row>
+            <row>
+              <entry>
 	        <literal>storage.size</literal> (uint64)
               </entry>
               <entry></entry>
diff --git a/hald/linux2/addons/addon-storage.c b/hald/linux2/addons/addon-storage.c
index 12aedb7..e725cba 100644
--- a/hald/linux2/addons/addon-storage.c
+++ b/hald/linux2/addons/addon-storage.c
@@ -432,6 +432,7 @@ main (int argc, char *argv[])
 				DBusError error;
 				
 				dbg ("Media removal detected on %s", device_file);
+				libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", FALSE, &error);
 				
 				/* attempt to unmount all childs */
 				unmount_childs (ctx, udi);
@@ -453,7 +454,7 @@ main (int argc, char *argv[])
 				DBusError error;
 
 				dbg ("Media insertion detected on %s", device_file);
-				/* our probe will trigger the appropriate hotplug events */
+				libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", TRUE, &error);				/* our probe will trigger the appropriate hotplug events */
 
 				/* could have a fs on the main block device; do a rescan to add it */
 				dbus_error_init (&error);
diff --git a/hald/linux2/blockdev.c b/hald/linux2/blockdev.c
index 1a74b0f..e9713aa 100644
--- a/hald/linux2/blockdev.c
+++ b/hald/linux2/blockdev.c
@@ -906,6 +906,7 @@ hotplug_event_begin_add_blockdev (const 
 		hal_device_property_set_string (d, "storage.drive_type", "floppy");
 		hal_device_property_set_string (d, "storage.physical_device", parent->udi);
 		hal_device_property_set_bool (d, "storage.removable", TRUE);
+		hal_device_property_set_bool (d, "storage.removable.media_available", FALSE);
 		hal_device_property_set_bool (d, "storage.hotpluggable", FALSE);
 		hal_device_property_set_bool (d, "storage.requires_eject", FALSE);
 		hal_device_property_set_uint64 (d, "storage.size", 0);
@@ -1048,6 +1049,7 @@ hotplug_event_begin_add_blockdev (const 
 			goto error;
 		}
 
+		hal_device_property_set_bool (d, "storage.removable.media_available", FALSE);
 		hal_device_property_set_bool (d, "storage.removable", is_removable);
 		/* set storage.size only if we have fixed media */
 		if (!is_removable) {
@@ -1432,7 +1434,7 @@ block_rescan_storage_done (HalDevice *d,
 	fakevolume = hal_device_store_match_key_value_string (hald_get_gdl (), "linux.sysfs_path", fake_sysfs_path);
 
 	if (return_code == 2) {
-		/* we've got a fs on the main block device - add fakevolume if we haven't got one already */
+		/* we've got something on the main block device - add fakevolume if we haven't got one already */
 		if (fakevolume == NULL) {
 			HAL_INFO (("Media insertion detected with file system on main block device; synthesizing hotplug add"));
 			generate_fakevolume_hotplug_event_add_for_storage_device (d);
diff --git a/hald/linux2/probing/probe-storage.c b/hald/linux2/probing/probe-storage.c
index e41ac5a..74f8bab 100644
--- a/hald/linux2/probing/probe-storage.c
+++ b/hald/linux2/probing/probe-storage.c
@@ -351,8 +351,12 @@ main (int argc, char *argv[])
 			break;
 		}
 
-		if (got_media)
+		if (got_media) {
 			ret = 2;
+			libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", TRUE, &error);
+		} else {
+			libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", FALSE, &error);
+		}
 
 		close (fd);
 	} else {
@@ -372,10 +376,15 @@ main (int argc, char *argv[])
 		fd = open (device_file, O_RDONLY);
 		if (fd < 0) {
 			dbg ("Cannot open %s: %s", device_file, strerror (errno));
+			/* no media */
+			libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", FALSE, &error);
 			goto out;
 		}
 		dbg ("Returned from open(2)");
 
+		/* if we get to here, we have media */
+		libhal_device_set_property_bool (ctx, udi, "storage.removable.media_available", TRUE, &error);
+
 		/* if the kernel has created partitions, we don't look for a filesystem */
 		main_device = strrchr (sysfs_path, '/');
 		if (main_device == NULL)
@@ -400,12 +409,20 @@ main (int argc, char *argv[])
 		/* probe for file system */
 		vid = volume_id_open_fd (fd);
 		if (vid != NULL) {
-			if (volume_id_probe_all (vid, 0, 0 /* size */) == 0) {
-				/* signal to hald that we've found a file system and a fakevolume
+			uint64_t size;
+
+			if (ioctl(vid->fd, BLKGETSIZE64, &size) != 0)
+				size = 0;
+
+			if (volume_id_probe_all (vid, 0, size) == 0) {
+				/* signal to hald that we've found something and a fakevolume
 				 * should be added - see hald/linux2/blockdev.c:add_blockdev_probing_helper_done()
 				 * and hald/linux2/blockdev.c:block_rescan_storage_done().
 				 */
-				if (vid->usage_id == VOLUME_ID_FILESYSTEM)
+				if (vid->usage_id == VOLUME_ID_FILESYSTEM ||
+				    vid->usage_id == VOLUME_ID_RAID ||
+				    vid->usage_id == VOLUME_ID_OTHER ||
+				    vid->usage_id == VOLUME_ID_CRYPTO)
 					ret = 2;
 			} else {
 				;
diff --git a/libhal-storage/libhal-storage.c b/libhal-storage/libhal-storage.c
index c572298..fb64c24 100644
--- a/libhal-storage/libhal-storage.c
+++ b/libhal-storage/libhal-storage.c
@@ -687,6 +687,7 @@ struct LibHalDrive_s {
 	char *model;              /* may be "", is never NULL */
 	dbus_bool_t is_hotpluggable;
 	dbus_bool_t is_removable;
+	dbus_bool_t is_media_detected;
 	dbus_bool_t requires_eject;
 
 	LibHalDriveType type;
@@ -933,6 +934,7 @@ libhal_drive_from_udi (LibHalContext *ha
 
 		LIBHAL_PROP_EXTRACT_BOOL   ("storage.hotpluggable",      drive->is_hotpluggable);
 		LIBHAL_PROP_EXTRACT_BOOL   ("storage.removable",         drive->is_removable);
+		LIBHAL_PROP_EXTRACT_BOOL   ("storage.removable.media_available", drive->is_media_detected);
 		LIBHAL_PROP_EXTRACT_BOOL   ("storage.requires_eject",    drive->requires_eject);
 
 		LIBHAL_PROP_EXTRACT_STRING ("storage.physical_device",   drive->physical_device);
@@ -1369,6 +1371,12 @@ libhal_drive_uses_removable_media (LibHa
 	return drive->is_removable;
 }
 
+dbus_bool_t
+libhal_drive_is_media_detected (LibHalDrive *drive)
+{
+	return drive->is_media_detected;
+}
+
 dbus_uint64_t
 libhal_drive_get_size (LibHalDrive *drive)
 {
diff --git a/libhal-storage/libhal-storage.h b/libhal-storage/libhal-storage.h
index 4228ff3..a7537a4 100644
--- a/libhal-storage/libhal-storage.h
+++ b/libhal-storage/libhal-storage.h
@@ -194,6 +194,7 @@ void                 libhal_drive_free  
 
 dbus_bool_t          libhal_drive_is_hotpluggable          (LibHalDrive      *drive);
 dbus_bool_t          libhal_drive_uses_removable_media     (LibHalDrive      *drive);
+dbus_bool_t          libhal_drive_is_media_detected        (LibHalDrive      *drive);
 dbus_uint64_t        libhal_drive_get_size                 (LibHalDrive      *drive);
 dbus_bool_t          libhal_drive_no_partitions_hint       (LibHalDrive      *drive);
 dbus_bool_t          libhal_drive_requires_eject           (LibHalDrive      *drive);
diff-tree 3d7863bdf1b9e34a6ea609ba54b40e9eb9a2b04a (from 7b1d143b988b378b3269b767259d387e64b14718)
Author: David Zeuthen <davidz at redhat.com>
Date:   Sat Aug 12 17:33:15 2006 -0400

    free dbus error freeing in lshal

diff --git a/tools/lshal.c b/tools/lshal.c
index 799e973..683f9b3 100644
--- a/tools/lshal.c
+++ b/tools/lshal.c
@@ -461,7 +461,8 @@ print_property (const char *udi, const c
 		break;
 	}
 
-	LIBHAL_FREE_DBUS_ERROR (&error);
+	if (dbus_error_is_set (&error))
+		LIBHAL_FREE_DBUS_ERROR (&error);
 }
 
 /** Invoked when a property of a device in the Global Device List is



More information about the hal-commit mailing list