Skip to contentSkip to conversation

udevinfo patch

PATCH Applied Daniel Stekloff 5 participants 13 messages Mar 23, 2004 – Mar 31, 2004

lore
Share & tools
lore
#0 lore raw

Hi Greg,

I think this is what you want for udevinfo. Patched against the latest BK tree. I tested it and it seemed to work.

One other question, shouldn't udevinfo.c:print_all_attributes() check to make sure attr->method is SYSFS_METHOD_SHOW along with checking to see if attr->value != NULL or doesn't that matter?

Here's the libsysfs fix for print_device_chain():

PATCH FOLLOWS:
-------------

udevinfo.c +6 -9
@@ -158,7 +158,6 @@
 	       "to match the device for which the node will be created.\n"
 	       "\n");
 	printf("device '%s' has major:minor %s", class_dev->path, attr->value);
-	sysfs_close_attribute(attr);
 
 	/* open sysfs class device directory and print all attributes */
 	printf("  looking at class device '%s':\n", class_dev->path);
@@ -170,11 +169,11 @@
 
 	/* get the device link (if parent exists look here) */
 	class_dev_parent = sysfs_get_classdev_parent(class_dev);
-	if (class_dev_parent != NULL) {
-		//sysfs_close_class_device(class_dev);
-		class_dev = class_dev_parent;
-	}
-	sysfs_dev = sysfs_get_classdev_device(class_dev);
+	if (class_dev_parent != NULL) 
+		sysfs_dev = sysfs_get_classdev_device(class_dev_parent);
+	else 
+		sysfs_dev = sysfs_get_classdev_device(class_dev);
+	
 	if (sysfs_dev != NULL)
 		printf("follow the class device's \"device\"\n");
 
@@ -191,13 +190,11 @@
 		if (sysfs_dev_parent = NULL)
 			break;
 
-		//sysfs_close_device(sysfs_dev);
 		sysfs_dev = sysfs_dev_parent;
 	}
-	sysfs_close_device(sysfs_dev);
 
 exit:
-	//sysfs_close_class_device(class_dev);
+	sysfs_close_class_device(class_dev);
 	return retval;
 }
 

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
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 6 lines · Daniel Stekloff

Hi Greg,

I think this is what you want for udevinfo. Patched against the latest BK tree. I tested it and it seemed to work.

Hey, thanks for fixing this. I always wanted to ask why I needed to comment out the close() calls.
Beeing lazy sometimes seems to work well :)

Quoted 3 lines

One other question, shouldn't udevinfo.c:print_all_attributes() check to make sure attr->method is SYSFS_METHOD_SHOW along with checking to see if attr->value != NULL or doesn't that matter?

Seems that the value is always NULL, if the file does not have read permissions. The sysfs_read_attribute() which sets the value is not called if SYSFS_METHOD_SHOW is not valid.

thanks again,
Kay

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#2 lore raw
In reply to Daniel Stekloff
Quoted 6 lines · Daniel Stekloff

Hi Greg,

I think this is what you want for udevinfo. Patched against the latest BK tree. I tested it and it seemed to work.

Thanks, I've applied this.

greg k-h

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
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 Daniel Stekloff
Quoted 7 lines · Greg KH
Quoted 5 lines · Daniel Stekloff

Hi Greg,

I think this is what you want for udevinfo. Patched against the latest BK tree. I tested it and it seemed to work.

It seems to have a bug:

carldani@4100xcdt:~/work/udev-023-orig> ./udevinfo -a -p /sys/block

udevinfo starts with the device the node belongs to and then walks up the [...]
to match the device for which the node will be created.

looking at class device '/sys/block':
couldn't open class device directory

carldani@4100xcdt:~/work/udev-023-orig> ./udevinfo -a -p /sys/block/

udevinfo starts with the device the node belongs to and then walks up the [...]
to match the device for which the node will be created.

device '/sys/block' has major:minor 1:9
looking at class device '/sys/block':
couldn't open class device directory

How can /sys/block have a major/minor number which changes everytime I recompile udevinfo?

Quoted 1 line

Thanks, I've applied this.

Could you also apply the attached patch to clean up a bit?

Thanks,
Carl-Daniel

udevinfo.c +10 -7
diff -urN udev-023-orig/udevinfo.c udev-023/udevinfo.c
@@ -133,7 +133,7 @@
 static int print_device_chain(const char *path)
 {
 	struct sysfs_class_device *class_dev;
-	struct sysfs_class_device *class_dev_parent;
+	struct sysfs_class_device *class_dev_basedev;
 	struct sysfs_attribute *attr;
 	struct sysfs_device *sysfs_dev;
 	struct sysfs_device *sysfs_dev_parent;
@@ -166,6 +166,10 @@
 			goto exit;
 		}
 		printf("device '%s' has major:minor %s", class_dev->path, attr->value);
+	} else {
+		printf("this is not a block or char device\n");
+		retval =-1;
+		goto exit;
 	}
 
 	/* open sysfs class device directory and print all attributes */
@@ -176,12 +180,11 @@
 		goto exit;
 	}
 
-	/* get the device link (if parent exists look here) */
-	class_dev_parent = sysfs_get_classdev_parent(class_dev);
-	if (class_dev_parent != NULL) 
-		sysfs_dev = sysfs_get_classdev_device(class_dev_parent);
-	else 
-		sysfs_dev = sysfs_get_classdev_device(class_dev);
+	/* if parent exists, use that instead */
+	class_dev_basedev = sysfs_get_classdev_parent(class_dev) ? : class_dev;
+
+	/* get the device link */
+	sysfs_dev = sysfs_get_classdev_device(class_dev_basedev);
 	
 	if (sysfs_dev != NULL)
 		printf("follow the class device's \"device\"\n");
#4 lore raw
In reply to Daniel Stekloff
Quoted 17 lines · Carl-Daniel Hailfinger
Quoted 7 lines · Greg KH
Quoted 5 lines · Daniel Stekloff

Hi Greg,

I think this is what you want for udevinfo. Patched against the latest BK tree. I tested it and it seemed to work.

It seems to have a bug:

carldani@4100xcdt:~/work/udev-023-orig> ./udevinfo -a -p /sys/block/

udevinfo starts with the device the node belongs to and then walks up the [...]
to match the device for which the node will be created.

Quoted 7 lines

device '/sys/block' has major:minor 1:9
looking at class device '/sys/block':
couldn't open class device directory

How can /sys/block have a major/minor number which changes everytime I recompile udevinfo?

It's the attribute value read from the last sysfs device.

Quoted 3 lines
Quoted 1 line

Thanks, I've applied this.

Could you also apply the attached patch to clean up a bit?

No, it breaks the net device handling. I think we should change libsysfs instead, not to return a class device for '/block', if we want to fix it.

Quoted 13 lines

diff -urN udev-023-orig/udevinfo.c udev-023/udevinfo.c

udevinfo.c +1 -1
@@ -133,7 +133,7 @@
 static int print_device_chain(const char *path)
 {
 	struct sysfs_class_device *class_dev;
-	struct sysfs_class_device *class_dev_parent;
+	struct sysfs_class_device *class_dev_basedev;
 	struct sysfs_attribute *attr;
 	struct sysfs_device *sysfs_dev;
 	struct sysfs_device *sysfs_dev_parent;

udevinfo.c line 172

Quoted 7 lines
udevinfo.c +4 -0
@@ -166,6 +166,10 @@
 			goto exit;
 		}
 		printf("device '%s' has major:minor %s", class_dev->path, attr->value);
+	} else {
+		printf("this is not a block or char device\n");
+		retval =-1;
+		goto exit;

What's this?
It doesn't fix your "bug", '/block' is still a block device and prints the garbage.

Quoted 5 lines
udevinfo.c +0 -0
 	}
 
 	/* open sysfs class device directory and print all attributes */
@@ -176,12 +180,11 @@
 		goto exit;

udevinfo.c line 184

Quoted 10 lines
udevinfo.c +2 -6
 	}
 
-	/* get the device link (if parent exists look here) */
-	class_dev_parent = sysfs_get_classdev_parent(class_dev);
-	if (class_dev_parent != NULL) 
-		sysfs_dev = sysfs_get_classdev_device(class_dev_parent);
-	else 
-		sysfs_dev = sysfs_get_classdev_device(class_dev);
+	/* if parent exists, use that instead */
+	class_dev_basedev = sysfs_get_classdev_parent(class_dev) ? : class_dev;

I don't see the reason to change this? What's the problem here?

udevinfo.c line 178

Quoted 6 lines
udevinfo.c +3 -0
+
+	/* get the device link */
+	sysfs_dev = sysfs_get_classdev_device(class_dev_basedev);
 
 	if (sysfs_dev != NULL)
 		printf("follow the class device's \"device\"\n");

thanks,
Kay

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#5 lore raw
In reply to Daniel Stekloff
Quoted 25 lines · Kay Sievers
Quoted 23 lines · Carl-Daniel Hailfinger
Quoted 7 lines · Greg KH
Quoted 4 lines · Daniel Stekloff

Hi Greg,

I think this is what you want for udevinfo. Patched against the latest BK tree. I tested it and it seemed to work.

It seems to have a bug:

carldani@4100xcdt:~/work/udev-023-orig> ./udevinfo -a -p /sys/block/

udevinfo starts with the device the node belongs to and then walks up the [...]
to match the device for which the node will be created.

device '/sys/block' has major:minor 1:9
looking at class device '/sys/block':
couldn't open class device directory

Quoted 5 lines
Quoted 2 lines

How can /sys/block have a major/minor number which changes everytime I recompile udevinfo?

It's the attribute value read from the last sysfs device.

And why does it only happen with /sys/block/ and not with /sys/block (Note the bug depends on the trailing slash).

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Thanks, I've applied this.

Could you also apply the attached patch to clean up a bit?

No, it breaks the net device handling. I think we should change

Sorry for that. My patch should not have changed change the behaviour of udevinfo at all (except one warning). Feel free to delete the offending hunk.

Quoted 2 lines

libsysfs instead, not to return a class device for '/block', if we want to fix it.

I agree. Daniel, can this be fixed in libsysfs?

Quoted 14 lines
Quoted 12 lines

diff -urN udev-023-orig/udevinfo.c udev-023/udevinfo.c

udevinfo.c +1 -1
@@ -133,7 +133,7 @@
 static int print_device_chain(const char *path)
 {
 	struct sysfs_class_device *class_dev;
-	struct sysfs_class_device *class_dev_parent;
+	struct sysfs_class_device *class_dev_basedev;
 	struct sysfs_attribute *attr;
 	struct sysfs_device *sysfs_dev;
 	struct sysfs_device *sysfs_dev_parent;
Quoted 13 lines

udevinfo.c line 172

Quoted 8 lines
udevinfo.c +4 -0
@@ -166,6 +166,10 @@
 			goto exit;
 		}
 		printf("device '%s' has major:minor %s", class_dev->path, attr->value);
+	} else {
+		printf("this is not a block or char device\n");
+		retval =-1;
+		goto exit;

What's this?
It doesn't fix your "bug", '/block' is still a block device and prints the garbage.

Sorry, the above hunk is bogus. I was working with udev-022 and udev-023 at the same time and got confused.

Quoted 8 lines
Quoted 8 lines
udevinfo.c +0 -0
 	}
 
 	/* open sysfs class device directory and print all attributes */
@@ -176,12 +180,11 @@
 		goto exit;
 	}
 
Quoted 11 lines

udevinfo.c line 184

Quoted 8 lines
udevinfo.c +2 -6
-	/* get the device link (if parent exists look here) */
-	class_dev_parent = sysfs_get_classdev_parent(class_dev);
-	if (class_dev_parent != NULL) 
-		sysfs_dev = sysfs_get_classdev_device(class_dev_parent);
-	else 
-		sysfs_dev = sysfs_get_classdev_device(class_dev);
+	/* if parent exists, use that instead */
+	class_dev_basedev = sysfs_get_classdev_parent(class_dev) ? : class_dev;

I don't see the reason to change this? What's the problem here?

As I said, this is a cleanup patch. It makes the code more readable (at least for me).

Quoted 6 lines

udevinfo.c line 178

Quoted 6 lines
udevinfo.c +3 -0
+
+	/* get the device link */
+	sysfs_dev = sysfs_get_classdev_device(class_dev_basedev);
 
 	if (sysfs_dev != NULL)
 		printf("follow the class device's \"device\"\n");

Regards,
Carl-Daniel

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
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 Daniel Stekloff
Quoted 28 lines · Kay Sievers
Quoted 17 lines · Carl-Daniel Hailfinger
Quoted 7 lines · Greg KH
Quoted 5 lines · Daniel Stekloff

Hi Greg,

I think this is what you want for udevinfo. Patched against the latest BK tree. I tested it and it seemed to work.

It seems to have a bug:

carldani@4100xcdt:~/work/udev-023-orig> ./udevinfo -a -p /sys/block/

udevinfo starts with the device the node belongs to and then walks up the [...]
to match the device for which the node will be created.

Quoted 7 lines

device '/sys/block' has major:minor 1:9
looking at class device '/sys/block':
couldn't open class device directory

How can /sys/block have a major/minor number which changes everytime I recompile udevinfo?

It's the attribute value read from the last sysfs device.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Thanks, I've applied this.

Could you also apply the attached patch to clean up a bit?

No, it breaks the net device handling. I think we should change libsysfs instead, not to return a class device for '/block', if we want to fix it.

/sys/block is considered a sysfs "class" and not a class_device. So, going by udevinfo's help, -p expects path to a class_device and _not_ a class itself and hence option /sys/block with -p is not a valid query.

Kay?

Thanks,
Ananth

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#7 lore raw
In reply to Daniel Stekloff
Quoted 26 lines · Carl-Daniel Hailfinger
Quoted 25 lines · Kay Sievers
Quoted 23 lines · Carl-Daniel Hailfinger
Quoted 7 lines · Greg KH
Quoted 4 lines · Daniel Stekloff

Hi Greg,

I think this is what you want for udevinfo. Patched against the latest BK tree. I tested it and it seemed to work.

It seems to have a bug:

carldani@4100xcdt:~/work/udev-023-orig> ./udevinfo -a -p /sys/block/

udevinfo starts with the device the node belongs to and then walks up the [...]
to match the device for which the node will be created.

device '/sys/block' has major:minor 1:9
looking at class device '/sys/block':
couldn't open class device directory

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

How can /sys/block have a major/minor number which changes everytime I recompile udevinfo?

It's the attribute value read from the last sysfs device.

And why does it only happen with /sys/block/ and not with /sys/block (Note the bug depends on the trailing slash).

Cause '/block' isn't recognized as a block device.

strstr(path, "/block/") != NULL)

Kay

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
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 Daniel Stekloff
Quoted 37 lines · Ananth N Mavinakayanahalli
Quoted 28 lines · Kay Sievers
Quoted 17 lines · Carl-Daniel Hailfinger
Quoted 7 lines · Greg KH
Quoted 5 lines · Daniel Stekloff

Hi Greg,

I think this is what you want for udevinfo. Patched against the latest BK tree. I tested it and it seemed to work.

It seems to have a bug:

carldani@4100xcdt:~/work/udev-023-orig> ./udevinfo -a -p /sys/block/

udevinfo starts with the device the node belongs to and then walks up the [...]
to match the device for which the node will be created.

Quoted 7 lines

device '/sys/block' has major:minor 1:9
looking at class device '/sys/block':
couldn't open class device directory

How can /sys/block have a major/minor number which changes everytime I recompile udevinfo?

It's the attribute value read from the last sysfs device.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Thanks, I've applied this.

Could you also apply the attached patch to clean up a bit?

No, it breaks the net device handling. I think we should change libsysfs instead, not to return a class device for '/block', if we want to fix it.

Quoted 5 lines

/sys/block is considered a sysfs "class" and not a class_device. So, going by udevinfo's help, -p expects path to a class_device and _not_ a class itself and hence option /sys/block with -p is not a valid query.

Kay?

Yes, it's invalid, but we shouldn't print major minor for a invalid path. sysfs_open_class_device_path("/block") returns a device. If this is the right behavior for libsysfs, I will change the get_device_type("/block") not to return a 'b'-type.

thanks,
Kay

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#9 lore raw
In reply to Daniel Stekloff
Quoted 14 lines · Kay Sievers
Quoted 13 lines · Ananth N Mavinakayanahalli
Quoted 7 lines · Kay Sievers
Quoted 2 lines · Carl-Daniel Hailfinger
Quoted 1 line · Greg KH

On Tue, Mar 23, 2004 at 01:51:01PM -0800, Daniel Stekloff wrote:

No, it breaks the net device handling. I think we should change libsysfs instead, not to return a class device for '/block', if we want to fix it.

/sys/block is considered a sysfs "class" and not a class_device. So, going by udevinfo's help, -p expects path to a class_device and _not_ a class itself and hence option /sys/block with -p is not a valid query.

Quoted 6 lines
Quoted 1 line

Kay?

Yes, it's invalid, but we shouldn't print major minor for a invalid path. sysfs_open_class_device_path("/block") returns a device. If this is the right behavior for libsysfs, I will change the get_device_type("/block") not to return a 'b'-type.

Libsysfs validates the path given to it for opening a class_device to be a valid directory; it does not however validate if the path is a valid class_device path. So, in the case of udevinfo, a 'b' type should not be returned if the path is just /sys/block or /sys/block/

Thanks,
Ananth

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
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 Daniel Stekloff
Quoted 28 lines · Ananth N Mavinakayanahalli
Quoted 18 lines · Kay Sievers
Quoted 16 lines · Ananth N Mavinakayanahalli
Quoted 9 lines · Kay Sievers
Quoted 3 lines · Carl-Daniel Hailfinger
Quoted 1 line · Greg KH

On Tue, Mar 23, 2004 at 01:51:01PM -0800, Daniel Stekloff wrote:

No, it breaks the net device handling. I think we should change libsysfs instead, not to return a class device for '/block', if we want to fix it.

/sys/block is considered a sysfs "class" and not a class_device. So, going by udevinfo's help, -p expects path to a class_device and _not_ a class itself and hence option /sys/block with -p is not a valid query.

Quoted 6 lines
Quoted 1 line

Kay?

Yes, it's invalid, but we shouldn't print major minor for a invalid path. sysfs_open_class_device_path("/block") returns a device. If this is the right behavior for libsysfs, I will change the get_device_type("/block") not to return a 'b'-type.

Quoted 4 lines

Libsysfs validates the path given to it for opening a class_device to be a valid directory; it does not however validate if the path is a valid class_device path. So, in the case of udevinfo, a 'b' type should not be returned if the path is just /sys/block or /sys/block/

Regardless of that, libsysfs should not claim something has a major/minor if it has not.

Regards,
Carl-Daniel

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

#11 lore raw
In reply to Daniel Stekloff
Quoted 22 lines · Ananth N Mavinakayanahalli
Quoted 14 lines · Kay Sievers
Quoted 13 lines · Ananth N Mavinakayanahalli
Quoted 7 lines · Kay Sievers
Quoted 2 lines · Carl-Daniel Hailfinger
Quoted 1 line · Greg KH

On Tue, Mar 23, 2004 at 01:51:01PM -0800, Daniel Stekloff wrote:

No, it breaks the net device handling. I think we should change libsysfs instead, not to return a class device for '/block', if we want to fix it.

/sys/block is considered a sysfs "class" and not a class_device. So, going by udevinfo's help, -p expects path to a class_device and _not_ a class itself and hence option /sys/block with -p is not a valid query.

Quoted 6 lines
Quoted 1 line

Kay?

Yes, it's invalid, but we shouldn't print major minor for a invalid path. sysfs_open_class_device_path("/block") returns a device. If this is the right behavior for libsysfs, I will change the get_device_type("/block") not to return a 'b'-type.

Quoted 4 lines

Libsysfs validates the path given to it for opening a class_device to be a valid directory; it does not however validate if the path is a valid class_device path. So, in the case of udevinfo, a 'b' type should not be returned if the path is just /sys/block or /sys/block/

This may prevent it.

thanks,
Kay

===== udev_lib.c 1.3 vs edited =====

udev_lib.c +16 -5
@@ -81,17 +81,28 @@
 	return subsystem;
 }
 
+#define BLOCK_PATH		"/block/"
+#define CLASS_PATH		"/class/"
+#define NET_PATH		"/class/net/"
+
 char get_device_type(const char *path, const char *subsystem)
 {
-	if (strcmp(subsystem, "block") == 0 ||
-	    strstr(path, "/block/") != NULL)
+	if (strcmp(subsystem, "block") == 0)
+		return 'b';
+
+	if (strcmp(subsystem, "net") == 0)
+		return 'n';
+
+	if (strncmp(path, BLOCK_PATH, strlen(BLOCK_PATH)) == 0 &&
+	    strlen(path) > strlen(BLOCK_PATH))
 		return 'b';
 
-	if (strcmp(subsystem, "net") == 0 ||
-	    strstr(path, "/class/net/") != NULL)
+	if (strncmp(path, NET_PATH, strlen(NET_PATH)) == 0 &&
+	    strlen(path) > strlen(NET_PATH))
 		return 'n';
 
-	if (strstr(path, "/class/") != NULL)
+	if (strncmp(path, CLASS_PATH, strlen(CLASS_PATH)) == 0 &&
+	    strlen(path) > strlen(CLASS_PATH))
 		return 'c';
 
 	return '\0';
Applied
#12 lore raw
In reply to Daniel Stekloff
Quoted 23 lines · Kay Sievers
Quoted 22 lines · Ananth N Mavinakayanahalli
Quoted 20 lines · Kay Sievers
Quoted 9 lines · Ananth N Mavinakayanahalli
Quoted 7 lines · Kay Sievers
Quoted 2 lines · Carl-Daniel Hailfinger
Quoted 1 line · Greg KH

On Tue, Mar 23, 2004 at 01:51:01PM -0800, Daniel Stekloff wrote:

No, it breaks the net device handling. I think we should change libsysfs instead, not to return a class device for '/block', if we want to fix it.

Quoted 5 lines

/sys/block is considered a sysfs "class" and not a class_device. So, going by udevinfo's help, -p expects path to a class_device and _not_ a class itself and hence option /sys/block with -p is not a valid query.

Kay?

Yes, it's invalid, but we shouldn't print major minor for a invalid path. sysfs_open_class_device_path("/block") returns a device. If this is the right behavior for libsysfs, I will change the get_device_type("/block") not to return a 'b'-type.

Quoted 6 lines
Quoted 4 lines

Libsysfs validates the path given to it for opening a class_device to be a valid directory; it does not however validate if the path is a valid class_device path. So, in the case of udevinfo, a 'b' type should not be returned if the path is just /sys/block or /sys/block/

This may prevent it.

Applied, thanks.

greg k-h

-------------------------------------------------------
This SF.Net email is sponsored by: IBM Linux Tutorials
Free Linux tutorial presented by Daniel Robbins, President and CEO of GenToo technologies. Learn everything from fundamentals to system administration.http://ads.osdn.com/?ad_id70&alloc_id638&op=click
_______________________________________________
Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel