[PATCH] update pcmciautils to handle libsysfs2 API changes

Colin Watson cjwatson at ubuntu.com
Mon Dec 19 06:14:45 EST 2005


The new major version of libsysfs included some API cleanups, which
unfortunately killed some convenience functions that pccardctl was
using. Martin Pitt <martin.pitt at ubuntu.com> supplied this patch which
updates pccardctl to handle these API changes. I've checked, and
pccardctl still works with libsysfs 1.3.0 after applying this patch.

--- src/pccardctl.c	
+++ src/pccardctl.c	
@@ -94,26 +94,36 @@
 static char * pccardctl_get_string(unsigned long socket_no, const char *in_file)
 {
 	int ret, len;
-	char value[SYSFS_PATH_MAX];
 	char file[SYSFS_PATH_MAX];
+	struct sysfs_attribute *attr;
 	char *result;
 
 	snprintf(file, SYSFS_PATH_MAX, "/sys/bus/pcmcia/devices/%lu.0/%s",
 		 socket_no, in_file);
-	ret = sysfs_read_attribute_value(file, value, SYSFS_PATH_MAX);
-	if (ret)
+        attr = sysfs_open_attribute(file);
+	if (!attr)
 		return NULL;
-
-	len = strlen(value);
-	if (len < 2)
+	ret = sysfs_read_attribute(attr);
+	if (ret) {
+		sysfs_close_attribute(attr);
 		return NULL;
+	}
+
+	len = strlen(attr->value);
+	if (len < 2) {
+		sysfs_close_attribute(attr);
+		return NULL;
+	}
 
 	result = malloc(sizeof(char) * len);
-	if (!result)
+	if (!result) {
+		sysfs_close_attribute(attr);
 		return NULL;
-
-        strncpy(result, value, len);
+	}
+
+        strncpy(result, attr->value, len);
         result[len - 1] = '\0';
+	sysfs_close_attribute(attr);
 
 	return (result);
 }
@@ -121,14 +131,18 @@
 static int pccardctl_get_one(unsigned long socket_no, const char *in_file, unsigned int *result)
 {
 	int ret;
-	char value[SYSFS_PATH_MAX];
 	char file[SYSFS_PATH_MAX];
+	struct sysfs_attribute *attr;
 
 	snprintf(file, SYSFS_PATH_MAX, "/sys/bus/pcmcia/devices/%lu.0/%s",
 		 socket_no, in_file);
-	ret = sysfs_read_attribute_value(file, value, SYSFS_PATH_MAX);
+        attr = sysfs_open_attribute(file);
+	if (!attr)
+	    return -1;
+	ret = sysfs_read_attribute(attr);
 	if (!ret)
-		sscanf(value, "0x%X", result);
+		sscanf(attr->value, "0x%X", result);
+	sysfs_close_attribute(attr);
 
 	return (ret);
 }


Thanks,

-- 
Colin Watson                                       [cjwatson at ubuntu.com]



More information about the linux-pcmcia mailing list