add media type to hal
Robert Love
rml at ximian.com
Thu Mar 25 02:58:11 EET 2004
Hey, David.
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.
Aside from being genuinely useful information, I have a larger plan: I
want to get rid of Linux-specific code in g-v-m and have it rely on HAL
100% - that is the point of HAL, after all.
Currently, the valid values for "storage.cdrom.media_type" are "audio",
"iso9660", "mixed", "blank", and "unknown".
Patch is against today's CVS.
Robert Love
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 (CD Plus) */
+ 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",
+ "iso9660");
+ 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