hal/hald/linux2/probing linux_dvd_rw_utils.c, 1.3, 1.4 linux_dvd_rw_utils.h, 1.1, 1.2 probe-storage.c, 1.17, 1.18

Danny Kukawka dkukawka at freedesktop.org
Mon Jan 16 04:22:18 PST 2006


Update of /cvs/hal/hal/hald/linux2/probing
In directory gabe:/tmp/cvs-serv19118/hald/linux2/probing

Modified Files:
	linux_dvd_rw_utils.c linux_dvd_rw_utils.h probe-storage.c 
Log Message:
2006-01-16  Danny Kukawka  <danny.kukawka at web.de>

        * doc/spec/hal-spec.xml.in: added storage.cdrom.write_speeds to spec

        * hald/linux2/probing/probe-storage.c,
        hald/linux2/probing/linux_dvd_rw_utils.h,
        hald/linux2/probing/linux_dvd_rw_utils.c: (int_compare),
        (get_write_speeds), (get_read_write_speed): added slightly adopted patch
        from Ryan Lortie <desrt at desrt.ca> (changed from comma-separated string
        to strlist) to add list of write speeds supported by a CD/DVD Burner.



Index: linux_dvd_rw_utils.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/probing/linux_dvd_rw_utils.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- linux_dvd_rw_utils.c	27 Sep 2005 09:42:13 -0000	1.3
+++ linux_dvd_rw_utils.c	16 Jan 2006 12:22:16 -0000	1.4
@@ -325,8 +325,97 @@
 	return page2A;
 }
 
+static int
+int_compare (const void *a, const void *b)
+{
+	/* descending order */
+	return *((int *) b) - *((int *) a);
+}
+
+/* gets the list of supported write speeds.  in the event
+ * that anything goes wrong, returns NULL.
+ */
+static char *
+get_write_speeds (const unsigned char *p, int length, int max_speed)
+{
+	char *result, *str;
+	int nr_records;
+	int *tmpspeeds;
+	int i, j;
+
+	result = NULL;
+
+	/* paranoia */
+	if (length < 32)
+		return NULL;
+
+	nr_records = p[30] << 8 | p[31];
+
+	/* paranoia */
+	if (length < 32 + 4 * nr_records)
+		return NULL;
+
+	tmpspeeds = malloc (nr_records * sizeof (int));
+
+	for (i = 0; i < nr_records; i++)
+	{
+		tmpspeeds[i] = p[4*i + 34] << 8 | p[4*i + 35];
+
+		/* i'm not sure how likely this is to show up, but it's
+		 * definitely wrong.  if we see it, abort.
+		 */
+		if (tmpspeeds[i] == 0)
+			goto free_tmpspeeds;
+	}
+
+	/* sort */
+	qsort (tmpspeeds, nr_records, sizeof (int), int_compare);
+
+	/* uniq */
+	for (i = j = 0; i < nr_records; i++)
+	{
+		tmpspeeds[j] = tmpspeeds[i];
+
+		/* make sure we don't look past the end of the array */
+		if (i >= (nr_records - 1) || tmpspeeds[i+1] != tmpspeeds[i])
+			j++;
+	}
+
+	/* j is now the number of unique entries in the array */
+	if (j == 0)
+		/* no entries?  this isn't right. */
+		goto free_tmpspeeds;
+
+	/* sanity check: the first item in the descending order
+	 * list ought to be the highest speed as detected through
+	 * other means
+	 */
+	if (tmpspeeds[0] != max_speed)
+		/* sanity check failed. */
+		goto free_tmpspeeds;
+
+	/* our values are 16-bit.  8 bytes per value
+	 * is more than enough including space for
+	 * ',' and '\0'.  we know j is not zero.
+	 */
+	result = str = malloc (8 * j);
+
+	for (i = 0; i < j; i++)
+	{
+		if (i > 0)
+			*(str++) = ',';
+
+		str += sprintf (str, "%d", tmpspeeds[i]);
+	}
+
+free_tmpspeeds:
+	free (tmpspeeds);
+
+	return result;
+}
+
 int
-get_read_write_speed (int fd, int *read_speed, int *write_speed)
+get_read_write_speed (int fd, int *read_speed, int *write_speed, char **write_speeds)
 {
 	unsigned char *page2A;
 	int len, hlen;
@@ -334,6 +423,7 @@
 
 	*read_speed = 0;
 	*write_speed = 0;
+	*write_speeds = NULL;
 
 	page2A = pull_page2a_from_fd (fd);
 	if (page2A == NULL) {
@@ -364,6 +454,8 @@
 	else
 	    *read_speed = 0;
 
+	*write_speeds = get_write_speeds (p, len, *write_speed);
+
 	free (page2A);
 
 	return 0;

Index: linux_dvd_rw_utils.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/probing/linux_dvd_rw_utils.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- linux_dvd_rw_utils.h	10 Feb 2005 17:03:57 -0000	1.1
+++ linux_dvd_rw_utils.h	16 Jan 2006 12:22:16 -0000	1.2
@@ -10,7 +10,7 @@
 #define LINUX_DVD_RW_UTILS_H
 
 int get_dvd_r_rw_profile (int fd);
-int get_read_write_speed (int fd, int *read_speed, int *write_speed);
+int get_read_write_speed (int fd, int *read_speed, int *write_speed, char **write_speeds);
 int get_disc_type (int fd);
 int disc_is_appendable (int fd);
 int disc_is_rewritable (int fd);

Index: probe-storage.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/probing/probe-storage.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- probe-storage.c	10 Nov 2005 19:28:34 -0000	1.17
+++ probe-storage.c	16 Jan 2006 12:22:16 -0000	1.18
@@ -4,6 +4,7 @@
  * probe-storage.c : Probe storage devices
  *
  * Copyright (C) 2004 David Zeuthen, <david at fubar.dk>
+ * Copyright (C) 2005 Danny Kukawka, <danny.kukawka at web.de>
  *
  * Licensed under the Academic Free License version 2.1
  *
@@ -237,6 +238,7 @@
 		if (strcmp (drive_type, "cdrom") == 0) {
 			int capabilities;
 			int read_speed, write_speed;
+			char *write_speeds;
 			
 			dbg ("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file);
 			fd = open (device_file, O_RDONLY | O_NONBLOCK);
@@ -315,10 +317,21 @@
 				libhal_device_set_property_bool (ctx, udi, "storage.cdrom.support_media_changed", FALSE, &error);
 			}
 			
-			if (get_read_write_speed(fd, &read_speed, &write_speed) >= 0) {
+			if (get_read_write_speed(fd, &read_speed, &write_speed, &write_speeds) >= 0) {
 				libhal_device_set_property_int (ctx, udi, "storage.cdrom.read_speed", read_speed, &error);
-				if (write_speed > 0)
+				if (write_speed > 0) {
 					libhal_device_set_property_int (ctx, udi, "storage.cdrom.write_speed", write_speed, &error);
+					if (write_speeds != NULL)
+					{
+						char *wspeed;
+						wspeed = strtok (write_speeds, ",");
+						while (wspeed != NULL) {
+							libhal_device_property_strlist_append (ctx, udi, "storage.cdrom.write_speeds", wspeed, &error);
+							wspeed = strtok (NULL, ",");
+						}
+						free (write_speeds);
+					}
+				}	
 				else
 					libhal_device_set_property_int (ctx, udi, "storage.cdrom.write_speed", 0, &error);
 			}




More information about the hal-commit mailing list