add media type to hal

Robert Love rml at ximian.com
Fri Mar 26 00:19:47 EET 2004


On Wed, 2004-03-24 at 19:58, Robert Love wrote:

> Following patch adds a "storage.cdrom.media_type" string property to
> CD-ROM discs, which describes the type of disc media.  Credit for this
> idea goes to Bastien Nocera.

David,

Here is an updated patch, against today's CVS, with the following simple
changes:

	- s/iso9660/data/		(Christophe Fergeau and others) 
	- Mixed Mode is not CD Plus	(Bastien Nocera)

Danke.

	Robert Love


Thu Mar 25 2004  Robert Love  <rml at ximian.com>
	* hald/linux/linux_class_block.c: add support for "storage.cdrom.media_type"


 hald/linux/linux_class_block.c |   39 ++++++++++++++++++++++++++++++++++++---
 1 files changed, 36 insertions(+), 3 deletions(-)

diff -u -r1.26 linux_class_block.c
--- hald/linux/linux_class_block.c	3 Mar 2004 17:56:56 -0000	1.26
+++ hald/linux/linux_class_block.c	25 Mar 2004 00:44:09 -0000
@@ -1300,16 +1300,15 @@
 		/* got a disc in drive, */
 
 		/* disc in drive; check if the HAL device representing
-		 * the optical drive already got a child (it can have
+		 * the optical drive already has a child (it can have
 		 * only one child)
 		 */
 
-		close (fd);
-
 		child = ds_device_find_by_key_value_string ("info.parent",
 							    d->udi, TRUE);
 		if (child == NULL) {
 			char udi[256];
+			int type;
 
 			/* nope, add child */
 			HAL_INFO (("Adding volume for optical device %s",
@@ -1340,6 +1339,40 @@
 			ds_property_set_string (child, "info.udi", udi);
 			ds_device_set_udi (child, udi);
 
+			/* set disc media type as appropriate */
+			type = ioctl (fd, CDROM_DISC_STATUS, CDSL_CURRENT);
+			close(fd);
+			switch (type) {
+			case CDS_AUDIO:		/* audio CD */
+				ds_property_set_string (child,
+						"storage.cdrom.media_type",
+						"audio");
+				break;
+			case CDS_MIXED:		/* mixed mode CD */
+				ds_property_set_string (child,
+						"storage.cdrom.media_type",
+						"mixed");
+				break;
+			case CDS_DATA_1:	/* data CD */
+			case CDS_DATA_2:
+			case CDS_XA_2_1:
+			case CDS_XA_2_2:
+				ds_property_set_string (child,
+						"storage.cdrom.media_type",
+						"data");
+				break;
+			case CDS_NO_INFO:	/* blank or invalid CD */
+				ds_property_set_string (child,
+						"storage.cdrom.media_type",
+						"blank");
+				break;
+			default:		/* should never see this */
+				ds_property_set_string (child,
+						"storage.cdrom.media_type",
+						"unknown");
+				break;
+			}
+
 			/* add new device */
 			ds_gdl_add (child);
 






More information about the xdg mailing list