r3103 - trunk/src/host/usbpath

werner at sita.openmoko.org werner at sita.openmoko.org
Sun Oct 7 14:57:07 CEST 2007


Author: werner
Date: 2007-10-07 14:56:57 +0200 (Sun, 07 Oct 2007)
New Revision: 3103

Modified:
   trunk/src/host/usbpath/README
   trunk/src/host/usbpath/devnum2path.c
   trunk/src/host/usbpath/path2devnum.c
   trunk/src/host/usbpath/usbpath.c
   trunk/src/host/usbpath/usbpath.h
Log:
Converted numbering scheme from bus+port+... with zero-based ports to
  bus-port. ... .port with one-based ports, as used by the kernel.



Modified: trunk/src/host/usbpath/README
===================================================================
--- trunk/src/host/usbpath/README	2007-10-07 11:44:44 UTC (rev 3102)
+++ trunk/src/host/usbpath/README	2007-10-07 12:56:57 UTC (rev 3103)
@@ -12,19 +12,19 @@
 The physical location of a USB device is represented by the following
 syntax:
 
-bus+port+...+port
+bus-port. ... .port
 
 where "bus" is again the number of the USB bus, and "port" is the number
-of the port on the respective next hub, counting from zero.
+of the port on the respective next hub, counting from one.
 
 
 usbport converts between the two representations.
 
 Example:
 usbport 1/19
-1+1+2
+1-1.2
 
-usbport 1+1+2
+usbport 1-1.2
 1/19
 
 

Modified: trunk/src/host/usbpath/devnum2path.c
===================================================================
--- trunk/src/host/usbpath/devnum2path.c	2007-10-07 11:44:44 UTC (rev 3102)
+++ trunk/src/host/usbpath/devnum2path.c	2007-10-07 12:56:57 UTC (rev 3103)
@@ -123,8 +123,8 @@
 	for (i = 0; i != n-1; i++) {
 		if (!path_size--)
 			return -1;
-		*path++ = '+';
-		res = add_int(&path, &path_size, ports[i]);
+		*path++ = i ? '.' : '-';
+		res = add_int(&path, &path_size, ports[i]+1);
 		if (res < 0)
 			return -1;
 		len += res+1;

Modified: trunk/src/host/usbpath/path2devnum.c
===================================================================
--- trunk/src/host/usbpath/path2devnum.c	2007-10-07 11:44:44 UTC (rev 3102)
+++ trunk/src/host/usbpath/path2devnum.c	2007-10-07 12:56:57 UTC (rev 3103)
@@ -116,7 +116,7 @@
 	if (!*path)
 		return -1;
 	for (p = path; *p; p++)
-		if (*p == '+')
+		if (*p == '-' || *p == '.')
 			nums++;
 	num = malloc(sizeof(int)*nums);
 	if (!num) {
@@ -126,10 +126,17 @@
 	while (1) {
 		char *end;
 
-		num[n++] = strtoul(path, &end, 10);
+		num[n] = strtoul(path, &end, 10);
+		if (!num[n]) {
+			free(num);
+			return -1;
+		}
+		if (n)
+			num[n]--;
+		n++;
 		if (!*end && n == nums)
 			break;
-		if (*end != '+') {
+		if (*end != (n == 1 ? '-' : '.')) {
 			free(num);
 			return -1;
 		}

Modified: trunk/src/host/usbpath/usbpath.c
===================================================================
--- trunk/src/host/usbpath/usbpath.c	2007-10-07 11:44:44 UTC (rev 3102)
+++ trunk/src/host/usbpath/usbpath.c	2007-10-07 12:56:57 UTC (rev 3103)
@@ -33,7 +33,7 @@
 
 static void usage(const char *name)
 {
-	fprintf(stderr, "usage: %s bus+port+...\n", name);
+	fprintf(stderr, "usage: %s bus-port. ... .port\n", name);
 	fprintf(stderr, "       %s bus/dev\n", name);
 	exit(1);
 }

Modified: trunk/src/host/usbpath/usbpath.h
===================================================================
--- trunk/src/host/usbpath/usbpath.h	2007-10-07 11:44:44 UTC (rev 3102)
+++ trunk/src/host/usbpath/usbpath.h	2007-10-07 12:56:57 UTC (rev 3103)
@@ -36,6 +36,8 @@
 /* path2devnum.c */
 
 /*
+ * Note that the port numbers in ports[] are 0-based.
+ *
  * Return codes:
  * 0  device not found
  * N  device number
@@ -45,6 +47,8 @@
     int num_ports);
 
 /*
+ * Note that the port numbers in the string are 1-based.
+ *
  * Return codes:
  * -1  invalid path specification
  * 0   device not found
@@ -57,16 +61,20 @@
 /* devnum2path.c */
 
 /*
+ * Note that the port numbers in ports[] are 0-based.
+ *
  * Return codes:
  * -1  buffer overflow
  * 0   device not found
- * N   N-1 ports placed into "ports"
+ * N   N-1 ports placed into "ports".
  */
 
 int usb_devnum2portlist(const struct usb_bus *bus, int devnum, int *ports,
     int num_ports);
 
 /*
+ * Note that the port numbers in the string are 1-based.
+ *
  * Return codes:
  * -1  buffer overflow
  * 0   device not found





More information about the commitlog mailing list