Skip to contentSkip to conversation

udev 0.2 release

ANNOUNCE Greg KH 4 participants 13 messages Jul 25, 2003 – Aug 13, 2003

lore
Share & tools
lore

Greg KH

author
#0 lore raw

Hi,

I've released the 0.2 version of udev into the wild, after surviving a live demo at the 2003 Ottawa Linux Symposium during a presentation. It can be found at:
kernel.org/pub/linux/utils/kernel/hotplug/udev-0.2.tar.gz

udev is a implementation of devfs in userspace using sysfs and /sbin/hotplug. It requires a 2.5/2.6 kernel to run properly. The major changes since the last release is that persistent device naming schemes are now implemented. Yeah, it's pretty rough, but it does prove that the concept is sane and will end up working well for users.

There's a BitKeeper tree of the latest stuff available at:
bk://kernel.bkbits.net/gregkh/udev/

I've also placed the slides from my OLS talk up at:

	http://www.kroah.com/linux/talks/ols_2003_udev_talk/

The paper which attempts to explain the background of udev, what it does, and where it is going is at:
http://archive.linuxsymposium.org/ols2003/Proceedings/All-Reprints/Reprint-Kroah-Hartman-OLS2003.pdf

Due to the rush of the development of udev in this past week (hacking at it during the conference in an attempt to have something to show) there are still a number of very rough corners present, a few known memory leaks, and at least one hard coded path to my home directory for a config file... Please feel free to take it for a spin to see how well things are progressing.

Patches are always welcome, and discussions of the implementation, and future directions that the project should entail are welcome for now on the linux-hotplug-devel mailing list (if it's over-run, a new list will be started up, but I don't think that's necessary for now.)

thanks,

greg k-h

-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#1 lore raw
Quoted 31 lines · Greg KH

Hi,

I've released the 0.2 version of udev into the wild, after surviving a live demo at the 2003 Ottawa Linux Symposium during a presentation. It can be found at:
kernel.org/pub/linux/utils/kernel/hotplug/udev-0.2.tar.gz

udev is a implementation of devfs in userspace using sysfs and /sbin/hotplug. It requires a 2.5/2.6 kernel to run properly. The major changes since the last release is that persistent device naming schemes are now implemented. Yeah, it's pretty rough, but it does prove that the concept is sane and will end up working well for users.

There's a BitKeeper tree of the latest stuff available at:
bk://kernel.bkbits.net/gregkh/udev/

I've also placed the slides from my OLS talk up at:

	http://www.kroah.com/linux/talks/ols_2003_udev_talk/

The paper which attempts to explain the background of udev, what it does, and where it is going is at:
http://archive.linuxsymposium.org/ols2003/Proceedings/All-Reprints/Reprint-Kroah-Hartman-OLS2003.pdf

Due to the rush of the development of udev in this past week (hacking at it during the conference in an attempt to have something to show) there are still a number of very rough corners present, a few known memory leaks, and at least one hard coded path to my home directory for a config file... Please feel free to take it for a spin to see how well things are progressing.

Quoted 8 lines

Patches are always welcome, and discussions of the implementation, and future directions that the project should entail are welcome for now on the linux-hotplug-devel mailing list (if it's over-run, a new list will be started up, but I don't think that's necessary for now.)

thanks,

greg k-h

This looks cool! I was so excited about devfs when it was written.
Since then I;ve felt a huge sense of disappointment as the implementation never quite became something cool as it could be.

Since this is mostly userspace it looks awesome. I have not looked at anything besides your slides yet. Will this affect existing apps? Does udev act as a /dev replacement, or will it actually need some app-level work?

thanks,
joshua

-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

author
#2 lore raw
In reply to Greg KH
Quoted 2 lines · Joshua Schmidlkofer

Since this is mostly userspace it looks awesome.

It is entirely userspace as we get the sysfs and /sbin/hotplug kernel support in 2.6 anyway.

Quoted 2 lines

I have not looked at
anything besides your slides yet. Will this affect existing apps?

In the default mode, no. We need to provide the default kernel naming scheme to comply with the Linux Standards Base and to prevent all older apps from breaking.

Quoted 2 lines

Does udev act as a /dev replacement, or will it actually need some app-level work?

Yes, it is a /dev replacement.
The only application work would be if a user starts to change their naming scheme (to always name a specific printer a specific name), as then the config file to point to a specific device would need to be changed. All applications should not have hard coded /dev entries, but I'm sure there are some out there that are for some reason...

thanks,

greg k-h

-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#3 lore raw
In reply to Greg KH

Simple patch for udev mknod.

Thanks
Guo Min
The content of this email message solely contains my own personal views, and not those of my employer.

-----------------------------------------------------------------------------------------------------------------

udev-add.c renamed from root/udev-0.2/udev-add.c +11 -20
@@ -81,35 +81,26 @@
  */
 static int create_node(char *name, char type, int major, int minor, int mode)
 {
-	char *argv[7];
-	char mode_string[100];
-	char type_string[3];
-	char major_string[20];
-	char minor_string[20];
 	char filename[255];
 	int retval = 0;
 
 	strncpy(filename, UDEV_ROOT, sizeof(filename));
 	strncat(filename, name, sizeof(filename));
+	if (type == 'b') {
+	       mode |= S_IFBLK;
+    	} else if ((type == 'c') || (type == 'u')){
+	        mode |= S_IFCHR;
+    	} else if ( type == 'p') {
+       		 mode |= S_IFIFO;
+    	} else {
+       		dbg("unknown node type %c\n", type);
+       		return -1;
+ 	}
 
-	snprintf(mode_string, sizeof(mode_string), "--mode=%#o", mode);
-	snprintf(type_string, sizeof(type_string), "%c", type);
-	snprintf(major_string, sizeof(major_string), "%d", major);
-	snprintf(minor_string, sizeof(minor_string), "%d", minor);
-	
-	argv[0] = MKNOD;
-	argv[1] = mode_string;
-	argv[2] = filename;
-	argv[3] = type_string;
-	argv[4] = major_string;
-	argv[5] = minor_string;
-	argv[6] = NULL;
-	dbg ("executing %s %s %s %s %s %s",
-		argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
 	switch (fork()) {
 		case 0:
 			/* we are the child, so lets run the program */
-			execv (MKNOD, argv);
+			mknod(filename,mode,makedev(major,minor));
 			exit(0);
 			break;
 		case (-1):
udev-add.c renamed from root/udev-0.2/udev-add.c +11 -20
@@ -81,35 +81,26 @@
  */
 static int create_node(char *name, char type, int major, int minor, int mode)
 {
-	char *argv[7];
-	char mode_string[100];
-	char type_string[3];
-	char major_string[20];
-	char minor_string[20];
 	char filename[255];
 	int retval = 0;
 
 	strncpy(filename, UDEV_ROOT, sizeof(filename));
 	strncat(filename, name, sizeof(filename));
+	if (type == 'b') {
+	       mode |= S_IFBLK;
+    	} else if ((type == 'c') || (type == 'u')){
+	        mode |= S_IFCHR;
+    	} else if ( type == 'p') {
+       		 mode |= S_IFIFO;
+    	} else {
+       		dbg("unknown node type %c\n", type);
+       		return -1;
+ 	}
 
-	snprintf(mode_string, sizeof(mode_string), "--mode=%#o", mode);
-	snprintf(type_string, sizeof(type_string), "%c", type);
-	snprintf(major_string, sizeof(major_string), "%d", major);
-	snprintf(minor_string, sizeof(minor_string), "%d", minor);
-	
-	argv[0] = MKNOD;
-	argv[1] = mode_string;
-	argv[2] = filename;
-	argv[3] = type_string;
-	argv[4] = major_string;
-	argv[5] = minor_string;
-	argv[6] = NULL;
-	dbg ("executing %s %s %s %s %s %s",
-		argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
 	switch (fork()) {
 		case 0:
 			/* we are the child, so lets run the program */
-			execv (MKNOD, argv);
+			mknod(filename,mode,makedev(major,minor));
 			exit(0);
 			break;
 		case (-1):
#4 lore raw
In reply to Greg KH

Simple patch for udev mknod.

Thanks
Guo Min
The content of this email message solely contains my own personal views, and not those of my employer.

-----------------------------------------------------------------------------------------------------------------

udev-add.c renamed from root/udev-0.2/udev-add.c +11 -20
@@ -81,35 +81,26 @@
  */
 static int create_node(char *name, char type, int major, int minor, int mode)
 {
-	char *argv[7];
-	char mode_string[100];
-	char type_string[3];
-	char major_string[20];
-	char minor_string[20];
 	char filename[255];
 	int retval = 0;
 
 	strncpy(filename, UDEV_ROOT, sizeof(filename));
 	strncat(filename, name, sizeof(filename));
+	if (type == 'b') {
+	       mode |= S_IFBLK;
+    	} else if ((type == 'c') || (type == 'u')){
+	        mode |= S_IFCHR;
+    	} else if ( type == 'p') {
+       		 mode |= S_IFIFO;
+    	} else {
+       		dbg("unknown node type %c\n", type);
+       		return -1;
+ 	}
 
-	snprintf(mode_string, sizeof(mode_string), "--mode=%#o", mode);
-	snprintf(type_string, sizeof(type_string), "%c", type);
-	snprintf(major_string, sizeof(major_string), "%d", major);
-	snprintf(minor_string, sizeof(minor_string), "%d", minor);
-	
-	argv[0] = MKNOD;
-	argv[1] = mode_string;
-	argv[2] = filename;
-	argv[3] = type_string;
-	argv[4] = major_string;
-	argv[5] = minor_string;
-	argv[6] = NULL;
-	dbg ("executing %s %s %s %s %s %s",
-		argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
 	switch (fork()) {
 		case 0:
 			/* we are the child, so lets run the program */
-			execv (MKNOD, argv);
+			mknod(filename,mode,makedev(major,minor));
 			exit(0);
 			break;
 		case (-1):
udev-add.c renamed from root/udev-0.2/udev-add.c +11 -20
@@ -81,35 +81,26 @@
  */
 static int create_node(char *name, char type, int major, int minor, int mode)
 {
-	char *argv[7];
-	char mode_string[100];
-	char type_string[3];
-	char major_string[20];
-	char minor_string[20];
 	char filename[255];
 	int retval = 0;
 
 	strncpy(filename, UDEV_ROOT, sizeof(filename));
 	strncat(filename, name, sizeof(filename));
+	if (type == 'b') {
+	       mode |= S_IFBLK;
+    	} else if ((type == 'c') || (type == 'u')){
+	        mode |= S_IFCHR;
+    	} else if ( type == 'p') {
+       		 mode |= S_IFIFO;
+    	} else {
+       		dbg("unknown node type %c\n", type);
+       		return -1;
+ 	}
 
-	snprintf(mode_string, sizeof(mode_string), "--mode=%#o", mode);
-	snprintf(type_string, sizeof(type_string), "%c", type);
-	snprintf(major_string, sizeof(major_string), "%d", major);
-	snprintf(minor_string, sizeof(minor_string), "%d", minor);
-	
-	argv[0] = MKNOD;
-	argv[1] = mode_string;
-	argv[2] = filename;
-	argv[3] = type_string;
-	argv[4] = major_string;
-	argv[5] = minor_string;
-	argv[6] = NULL;
-	dbg ("executing %s %s %s %s %s %s",
-		argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
 	switch (fork()) {
 		case 0:
 			/* we are the child, so lets run the program */
-			execv (MKNOD, argv);
+			mknod(filename,mode,makedev(major,minor));
 			exit(0);
 			break;
 		case (-1):
author
#5 lore raw
In reply to Greg KH
Quoted 1 line · Min

Simple patch for udev mknod.

Why still fork() for this? Can't we just call mknod() directly and then return?

thanks,

greg k-h

-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#6 lore raw
In reply to Greg KH

Thanks,the revised patch.
---------------------------------------------

udev/udev-add.c renamed from root/udev-0.2/udev-add.c +12 -33
@@ -81,45 +81,24 @@
  */
 static int create_node(char *name, char type, int major, int minor, int mode)
 {
-	char *argv[7];
-	char mode_string[100];
-	char type_string[3];
-	char major_string[20];
-	char minor_string[20];
 	char filename[255];
 	int retval = 0;
-
 	strncpy(filename, UDEV_ROOT, sizeof(filename));
 	strncat(filename, name, sizeof(filename));
+	if (type == 'b') {
+	       mode |= S_IFBLK;
+    	} else if ((type == 'c') || (type == 'u')){
+	        mode |= S_IFCHR;
+    	} else if ( type == 'p') {
+       		 mode |= S_IFIFO;
+    	} else {
+       		dbg("unknown node type %c\n", type);
+       		return -1;
+ 	}
 
-	snprintf(mode_string, sizeof(mode_string), "--mode=%#o", mode);
-	snprintf(type_string, sizeof(type_string), "%c", type);
-	snprintf(major_string, sizeof(major_string), "%d", major);
-	snprintf(minor_string, sizeof(minor_string), "%d", minor);
-	
-	argv[0] = MKNOD;
-	argv[1] = mode_string;
-	argv[2] = filename;
-	argv[3] = type_string;
-	argv[4] = major_string;
-	argv[5] = minor_string;
-	argv[6] = NULL;
-	dbg ("executing %s %s %s %s %s %s",
-		argv[0], argv[1], argv[2], argv[3], argv[4], argv[5]);
-	switch (fork()) {
-		case 0:
-			/* we are the child, so lets run the program */
-			execv (MKNOD, argv);
-			exit(0);
-			break;
-		case (-1):
-			dbg ("fork failed.");
-			retval = -EFAULT;
-			break;
-		default:
-			break;
-	}
+	retval = mknod(filename,mode,makedev(major,minor));
 	return retval;
+		
 }
 
 struct sysfs_class_device *get_class_dev(char *device_name)
udev/udev-add.c renamed from root/udev-0.2/udev-add.c +12 -33

57 lines not on this page · raw message

author
#7 lore raw
In reply to Greg KH
Quoted 1 line · Min

Thanks,the revised patch.

Thanks, I've applied this and cleaned it up a big (report the error to the debug log if there is one.)

greg k-h

-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#8 lore raw
In reply to Greg KH

Here are two function patch for libsys which metioned in TODO list, could you please take a look at it and see whether it can meet the TODO req.

Thanks
Guo Min
The content of this email message solely contains my own personal views, and not those of my employer.
-----------------------------------------------------------------------------------------------------------------------------------------

libsysfs.h renamed from udev/libsysfs/libsysfs.h +3 -0
diff -Nuar /udev/libsysfs/libsysfs.h libsysfs/libsysfs.h
@@ -124,6 +124,9 @@
 extern int sysfs_read_attribute(struct sysfs_attribute *sysattr);
 extern int sysfs_read_attribute_value(const char *attrpath, char *value, 
 								size_t vsize);
+extern int sysfs_write_attribute(struct sysfs_attribute *sysattr,char *value);
+extern int sysfs_write_attribute_value(const char *attrpath, char *value);
+
 extern char *sysfs_get_value_from_attributes(struct sysfs_attribute *attr, 
 							const char * name);
 extern void sysfs_close_directory(struct sysfs_directory *sysdir);
sysfs_dir.c renamed from udev/libsysfs/sysfs_dir.c +63 -0

75 lines not on this page · raw message

libsysfs.h renamed from udev/libsysfs/libsysfs.h +3 -0
diff -Nuar /udev/libsysfs/libsysfs.h libsysfs/libsysfs.h
@@ -124,6 +124,9 @@
 extern int sysfs_read_attribute(struct sysfs_attribute *sysattr);
 extern int sysfs_read_attribute_value(const char *attrpath, char *value, 
 								size_t vsize);
+extern int sysfs_write_attribute(struct sysfs_attribute *sysattr,char *value);
+extern int sysfs_write_attribute_value(const char *attrpath, char *value);
+
 extern char *sysfs_get_value_from_attributes(struct sysfs_attribute *attr, 
 							const char * name);
 extern void sysfs_close_directory(struct sysfs_directory *sysdir);
sysfs_dir.c renamed from udev/libsysfs/sysfs_dir.c +63 -0

75 lines not on this page · raw message

#9 lore raw
In reply to Greg KH

Hi Guo Min,

Thank you very much for the patch. It's a good start. Some ideas:

- sysfs_write_attribute needs to actually write the value out to the file/attribute. Use the path in sysfs_attribute.

- sysfs_write_attribute should probably only need the sysfs_attribute
*sysattr as an argument, the value being already assigned to the sysfs_attribute.

- sysfs_write_attribute_value could assign the value to the included sysfs_attribute and then call sysfs_write_attribute like you have it now.

- Please look at sysfs_read_attribute as a guide.

Thanks,

Dan

Quoted 101 lines

Subject: RE: [ANNOUNCE] udev 0.2 release
From: "Guo, Min" <[email protected]>
To: "Greg KH" <[email protected]>
Cc: <[email protected]>
Date: Tue, 5 Aug 2003 10:22:00 +0800

Here are two function patch for libsys which metioned in TODO list, could you please take a look at it and see whether it can meet the TODO req.

Thanks
Guo Min
The content of this email message solely contains my own personal views, and not those of my employer.
---------------------------------------------------------------------------
-------------------------------------------------------------- diff -Nuar /udev/libsysfs/libsysfs.h libsysfs/libsysfs.h

libsysfs.h renamed from udev/libsysfs/libsysfs.h +1 -0
@@ -124,6 +124,9 @@
 extern int sysfs_read_attribute(struct sysfs_attribute *sysattr);
 extern int sysfs_read_attribute_value(const char *attrpath, char *value,
 								size_t vsize);
+extern int sysfs_write_attribute(struct sysfs_attribute *sysattr,char
 *value); +extern int sysfs_write_attribute_value(const char *attrpath, char
 *value); +
 extern char *sysfs_get_value_from_attributes(struct sysfs_attribute *attr,
 							const char * name);
 extern void sysfs_close_directory(struct sysfs_directory *sysdir);

diff -Nuar /udev/libsysfs/sysfs_dir.c libsysfs/sysfs_dir.c

sysfs_dir.c renamed from udev/libsysfs/sysfs_dir.c +56 -0
@@ -78,6 +78,34 @@
 
 	return sysattr;
 }
+/**
+ * sysfs_write_attribute: write value to the attribute
+ * @sysattr: attribute to write
+ * returns 0 with success and -1 with error.
+ */
+int sysfs_write_attribute(struct sysfs_attribute *sysattr,char  *value)
+{
+	if (sysattr = NULL) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	if (!(sysattr->method & SYSFS_METHOD_STORE)) {
+		dprintf (stderr, "Store method not supported for attribute %s\n",
+			sysattr->path);
+		return -1;
+	}
+
+	if (!value)
+		sysattr->value=value;
+	else
+	{
+		dprintf (stderr, "The value is NULL\n");
+		return -1;
+	}
+	return 0;
+}
+
 
 /**
  * sysfs_read_attribute: reads value from attribute
@@ -134,6 +162,41 @@
 }
 
 /**
+ * sysfs_write_attribute_value: given path to attribute,
+ * value will be saved to the attribute.
+ * @attrpath: sysfs path to attribute
+ * @value: value to give to attribute
+ * returns 0 with success and -1 with error.
+ */
+int sysfs_write_attribute_value(const char *attrpath, char *value)
+{
+	struct sysfs_attribute *attr = NULL;
+
+	if (attrpath = NULL || value = NULL) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	attr = sysfs_open_attribute(attrpath);
+	if (attr = NULL) {
+		dprintf(stderr, "Invalid attribute path %s\n", attrpath);
+		errno = EINVAL;
+		return -1;
+	}
+
+	if((sysfs_write_attribute(attr,value)) != 0 ) {
+		dprintf(stderr, "Error write to attribute %s\n", attrpath);
+		sysfs_close_attribute(attr);
+		return -1;
+	}
+

sysfs_dir.c line 202

Quoted 10 lines
sysfs_dir.c renamed from udev/libsysfs/sysfs_dir.c +7 -0
+	sysfs_close_attribute(attr);
+
+	return 0;
+}
+
+
+/**
  * sysfs_read_attribute_value: given path to attribute, return its value.
  *	values can be up to a pagesize, if buffer is smaller the value will
  *	be truncated.

-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#10 lore raw
In reply to Greg KH

Thanks!The revised path!
----------------------------------------------------------------------------------------------------------

root/udev-0.2/libsysfs/libsysfs.h renamed from udev/libsysfs/libsysfs.h +3 -0
diff -Nuar /udev/libsysfs/libsysfs.h /root/udev-0.2/libsysfs/libsysfs.h
@@ -124,6 +124,9 @@
 extern int sysfs_read_attribute(struct sysfs_attribute *sysattr);
 extern int sysfs_read_attribute_value(const char *attrpath, char *value, 
 								size_t vsize);
+extern int sysfs_write_attribute(struct sysfs_attribute *sysattr);
+extern int sysfs_write_attribute_value(const char *attrpath, char *value);
+
 extern char *sysfs_get_value_from_attributes(struct sysfs_attribute *attr, 
 							const char * name);
 extern void sysfs_close_directory(struct sysfs_directory *sysdir);
root/udev-0.2/libsysfs/sysfs_dir.c renamed from udev/libsysfs/sysfs_dir.c +72 -0

84 lines not on this page · raw message

-----Original Message-----
From: Daniel Stekloff [mailto:[email protected]]
Sent: Tuesday, August 05, 2003 6:09 PM
To: Guo, Min
Cc: [email protected]; Greg KH
Subject: RE: [ANNOUNCE] udev 0.2 release

Hi Guo Min,

Thank you very much for the patch. It's a good start. Some ideas:

- sysfs_write_attribute needs to actually write the value out to the file/attribute. Use the path in sysfs_attribute.

- sysfs_write_attribute should probably only need the sysfs_attribute
*sysattr as an argument, the value being already assigned to the sysfs_attribute.

- sysfs_write_attribute_value could assign the value to the included sysfs_attribute and then call sysfs_write_attribute like you have it now.

- Please look at sysfs_read_attribute as a guide.

Thanks,

Dan

root/udev-0.2/libsysfs/libsysfs.h renamed from udev/libsysfs/libsysfs.h +3 -0
diff -Nuar /udev/libsysfs/libsysfs.h /root/udev-0.2/libsysfs/libsysfs.h
@@ -124,6 +124,9 @@
 extern int sysfs_read_attribute(struct sysfs_attribute *sysattr);
 extern int sysfs_read_attribute_value(const char *attrpath, char *value, 
 								size_t vsize);
+extern int sysfs_write_attribute(struct sysfs_attribute *sysattr);
+extern int sysfs_write_attribute_value(const char *attrpath, char *value);
+
 extern char *sysfs_get_value_from_attributes(struct sysfs_attribute *attr, 
 							const char * name);
 extern void sysfs_close_directory(struct sysfs_directory *sysdir);
root/udev-0.2/libsysfs/sysfs_dir.c renamed from udev/libsysfs/sysfs_dir.c +72 -0

84 lines not on this page · raw message

#11 lore raw
In reply to Greg KH

How to write value to sysfs? now sysfs is only readable.

Thanks
Guo Min
-----Original Message-----
From: Guo, Min
Sent: Tuesday, August 12, 2003 3:19 PM
To: 'Daniel Stekloff'
Cc: [email protected]; Greg KH
Subject: RE: [ANNOUNCE] udev 0.2 release

Thanks!The revised path!
----------------------------------------------------------------------------------------------------------

root/udev-0.2/libsysfs/libsysfs.h renamed from udev/libsysfs/libsysfs.h +3 -0
diff -Nuar /udev/libsysfs/libsysfs.h /root/udev-0.2/libsysfs/libsysfs.h
@@ -124,6 +124,9 @@
 extern int sysfs_read_attribute(struct sysfs_attribute *sysattr);
 extern int sysfs_read_attribute_value(const char *attrpath, char *value, 
 								size_t vsize);
+extern int sysfs_write_attribute(struct sysfs_attribute *sysattr);
+extern int sysfs_write_attribute_value(const char *attrpath, char *value);
+
 extern char *sysfs_get_value_from_attributes(struct sysfs_attribute *attr, 
 							const char * name);
 extern void sysfs_close_directory(struct sysfs_directory *sysdir);
root/udev-0.2/libsysfs/sysfs_dir.c renamed from udev/libsysfs/sysfs_dir.c +72 -0

84 lines not on this page · raw message

-----Original Message-----
From: Daniel Stekloff [mailto:[email protected]]
Sent: Tuesday, August 05, 2003 6:09 PM
To: Guo, Min
Cc: [email protected]; Greg KH
Subject: RE: [ANNOUNCE] udev 0.2 release

Hi Guo Min,

Thank you very much for the patch. It's a good start. Some ideas:

- sysfs_write_attribute needs to actually write the value out to the file/attribute. Use the path in sysfs_attribute.

- sysfs_write_attribute should probably only need the sysfs_attribute
*sysattr as an argument, the value being already assigned to the sysfs_attribute.

- sysfs_write_attribute_value could assign the value to the included sysfs_attribute and then call sysfs_write_attribute like you have it now.

- Please look at sysfs_read_attribute as a guide.

Thanks,

Dan

-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#12 lore raw
In reply to Greg KH

Thank you very much for the revised patch. We will put it into our tree.

As for writing values to sysfs, sysfs files or attributes are sometimes writeable. You can write to them as you write to any file. For instance, I could have a "debug" file for my usb device driver. The driver could export the callback through sysfs as a file. Reading from the file returns the current "debug" state of the driver. Writing to the file would change the debug level for the driver.

Is this what you were asking?

Thanks,

Dan

Quoted 148 lines · Min

How to write value to sysfs? now sysfs is only readable.

Thanks
Guo Min
-----Original Message-----
From: Guo, Min
Sent: Tuesday, August 12, 2003 3:19 PM
To: 'Daniel Stekloff'
Cc: [email protected]; Greg KH
Subject: RE: [ANNOUNCE] udev 0.2 release

Thanks!The revised path!
---------------------------------------------------------------------------
------------------------------- diff -Nuar /udev/libsysfs/libsysfs.h
/root/udev-0.2/libsysfs/libsysfs.h --- /udev/libsysfs/libsysfs.h 2003-07-19
03:06:48.000000000 +0800
+++ /root/udev-0.2/libsysfs/libsysfs.h 2003-08-12 16:05:36.483706096 +0800

(quoted diff) +3 -0
@@ -124,6 +124,9 @@
 extern int sysfs_read_attribute(struct sysfs_attribute *sysattr);
 extern int sysfs_read_attribute_value(const char *attrpath, char *value,
 								size_t vsize);
+extern int sysfs_write_attribute(struct sysfs_attribute *sysattr);
+extern int sysfs_write_attribute_value(const char *attrpath, char *value);
+
 extern char *sysfs_get_value_from_attributes(struct sysfs_attribute *attr,
 							const char * name);
 extern void sysfs_close_directory(struct sysfs_directory *sysdir);

diff -Nuar /udev/libsysfs/sysfs_dir.c /root/udev-0.2/libsysfs/sysfs_dir.c

root/udev-0.2/libsysfs/sysfs_dir.c renamed from udev/libsysfs/sysfs_dir.c +72 -1
@@ -78,6 +78,43 @@
 
 	return sysattr;
 }
+/**
+ * sysfs_write_attribute: write value to the attribute
+ * @sysattr: attribute to write
+ * returns 0 with success and -1 with error.
+ */
+int sysfs_write_attribute(struct sysfs_attribute *sysattr)
+{
+	int fd;
+	int length;
+
+	if (sysattr = NULL) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	if (!(sysattr->method & SYSFS_METHOD_STORE)) {
+		dprintf (stderr, "Store method not supported for attribute %s\n",
+			sysattr->path);
+		return -1;
+	}
+
+	if ((fd = open(sysattr->path, O_RDWR)) < 0) {
+		dprintf (stderr, "Error reading attribute %s\n", sysattr->path);
+		return -1;
+	}
+
+	length = write(fd,sysattr->value,sizeof(sysattr->value));
+	if (length < 0) {
+		dprintf (stderr, "Error write to the attribute %s\n",
+			sysattr->path);
+		close(fd);
+		return -1;
+	}
+	close(fd);
+	return 0;
+}
+
 
 /**
  * sysfs_read_attribute: reads value from attribute
@@ -134,6 +171,41 @@
 }
 
 /**
+ * sysfs_write_attribute_value: given path to attribute,
+ * value will be saved to the attribute.
+ * @attrpath: sysfs path to attribute
+ * @value: value to give to attribute
+ * returns 0 with success and -1 with error.
+ */
+int sysfs_write_attribute_value(const char *attrpath, char *value)
+{
+	struct sysfs_attribute *attr = NULL;
+
+	if (attrpath = NULL || value = NULL) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	attr = sysfs_open_attribute(attrpath);
+	if (attr = NULL) {
+		dprintf(stderr, "Invalid attribute path %s\n", attrpath);
+		errno = EINVAL;
+		return -1;
+	}
+	strncpy(attr->value,value,sizeof(value));
+	if((sysfs_write_attribute(attr) != 0 )){
+		dprintf(stderr, "Error write to attribute %s\n", attrpath);
+		sysfs_close_attribute(attr);
+		return -1;
+	}
+
+	sysfs_close_attribute(attr);
+
+	return 0;
+}
+
+
+/**
  * sysfs_read_attribute_value: given path to attribute, return its value.
  *	values can be up to a pagesize, if buffer is smaller the value will
  *	be truncated.
-----Original Message-----

From: Daniel Stekloff [mailto:[email protected]]
Sent: Tuesday, August 05, 2003 6:09 PM
To: Guo, Min
Cc: [email protected]; Greg KH
Subject: RE: [ANNOUNCE] udev 0.2 release

Hi Guo Min,

Thank you very much for the patch. It's a good start. Some ideas:

- sysfs_write_attribute needs to actually write the value out to the file/attribute. Use the path in sysfs_attribute.

- sysfs_write_attribute should probably only need the sysfs_attribute
*sysattr as an argument, the value being already assigned to the sysfs_attribute.

- sysfs_write_attribute_value could assign the value to the included sysfs_attribute and then call sysfs_write_attribute like you have it now.

- Please look at sysfs_read_attribute as a guide.

Thanks,

Dan

Quoted 9 lines

-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

-------------------------------------------------------
This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET.
http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel