linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [udev] updated man, subdirs, ownership, namedev enum patches
@ 2003-11-05 19:38 Kay Sievers
  0 siblings, 0 replies; 16+ messages in thread
From: Kay Sievers @ 2003-11-05 19:38 UTC (permalink / raw)
  To: linux-hotplug

[-- Attachment #1: Type: text/plain, Size: 880 bytes --]

Hi Greg,
here are the updated patches for udev, please ignore all previous sent.
Included is the man page update, support for subdir creation/removal,
basic node ownership support and a namedev correction.

thanks,
Kay


01-udev.8.diff:
  man page style fixes
  present the tiny udev in bold font :)

02-udev-add.c-subdirs.diff:
02-udev-remove.c-subdirs.diff:
  support subdirectory creation/removal for NAME="/devfs/is/crazy/video0"
  create parent subdirs for device node if needed
  remove subdirs when last node is removed

03-udev-add.c-set_owner.diff
  set uid/gid of node specified in udev.permissions
  only numeric id's are supported cause we can't resolve with
  klibc or libc before real /etc is mounted

04-namedev.c-cleanup.diff
  remove part of udev that appends the kernel enumeration to character devices
  in LABEL method: NAME="webcam" results in /udev/webcam0


[-- Attachment #2: 01-udev.8.diff --]
[-- Type: text/plain, Size: 1495 bytes --]

--- udev.8	2003-10-22 01:09:41.000000000 +0200
+++ /home/kay/udev/udev.8	2003-10-24 15:06:41.000000000 +0200
@@ -20,13 +20,15 @@
 like label, serial number or bus device number.
 These attributes are treated as a key 
 to determine a unique name for device file creation.
-udev maintains a database for devices present on the system.
+.B udev
+maintains a database for devices present on the system.
 .br
 On device removal,
 .B udev
 queries the internal database for the name of the device file to be deleted.
 .SH "CONFIGURATION"
-udev expects its configuration at
+.B udev
+expects its configuration at
 .I /etc/udev/udev.config.
 The file consists of a set of lines. All empty lines and
 lines beginning with a '#' will be ignored.
@@ -85,8 +87,8 @@
 # ttyUSB1 should always be called pda
 REPLACE, KERNEL="ttyUSB1", NAME="pda"
 
-# if /sbin/dev_id returns "V0815" device will be called dev0815
-CALLOUT, PROGRAM="/sbin/dev_id", BUS="pci", ID="V0815", NAME="dev0815"
+# if /sbin/scsi_id returns "OEM 0815" device will be called disk1
+CALLOUT, PROGRAM="/sbin/scsi_id" BUS="scsi", ID="OEM 0815" NAME="disk1"
 .fi
 .P
 Permissions and ownership for the created device files may specified at
@@ -120,5 +122,6 @@
 .I http://linux-hotplug.sourceforge.net/
 web site.
 .SH AUTHORS
-udev was developed by Greg Kroah-Hartman <greg@kroah.com> with much help from
+.B udev
+was developed by Greg Kroah-Hartman <greg@kroah.com> with much help from
 Dan Stekloff <dsteklof@us.ibm.com> and many others.

[-- Attachment #3: 02-udev-add.c-subdirs.diff --]
[-- Type: text/plain, Size: 844 bytes --]

--- ../udev/udev-add.c	2003-10-30 22:46:08.000000000 +0100
+++ udev-add.c	2003-10-31 14:38:48.000000000 +0100
@@ -100,6 +100,32 @@
 		return -EINVAL;
 	}
 
+	/* create subdirectories if requested */
+	if (strchr(dev->name, '/')) {
+		char path[255];
+		char *pos;
+		struct stat stats;
+
+		strncpy(path, filename, sizeof(path));
+		pos = strchr(path+1, '/');
+		while (1) {
+			pos = strchr(pos+1, '/');
+			if (pos == NULL)
+				break;
+			*pos = 0x00;
+			if (stat(path, &stats)) {
+				retval = mkdir(path, 0755);
+				if (retval) {
+					dbg("mkdir(%s) failed with error '%s'",
+					    path, strerror(errno));
+					return retval;
+				}
+				dbg("created %s", path);
+			}
+			*pos = '/';
+		}
+	}
+
 	dbg("mknod(%s, %#o, %u, %u)", filename, dev->mode, dev->major, dev->minor);
 	retval = mknod(filename, dev->mode, res);
 	if (retval)

[-- Attachment #4: 02-udev-remove.c-subdirs.diff --]
[-- Type: text/plain, Size: 1121 bytes --]

--- ../udev/udev-remove.c	2003-10-30 22:46:08.000000000 +0100
+++ udev-remove.c	2003-11-04 15:07:35.000000000 +0100
@@ -69,12 +69,45 @@
 static int delete_node(char *name)
 {
 	char filename[255];
+	int retval;
 
 	strncpy(filename, udev_root, sizeof(filename));
 	strncat(filename, name, sizeof(filename));
 
 	dbg("unlinking %s", filename);
-	return unlink(filename);
+	retval = unlink(filename);
+	if (retval) {
+		dbg("unlink(%s) failed with error '%s'",
+			filename, strerror(errno));
+		return retval;
+	}
+
+	/* remove subdirectories */
+	if (strchr(name, '/')) {
+		char *pos;
+
+		pos = strrchr(filename, '/');
+		while (1) {
+			*pos = 0x00;
+			pos = strrchr(filename, '/');
+
+			/* don't remove the last one */
+			if ((pos == filename) || (pos == NULL))
+				break;
+
+			/* remove if empty */
+			retval = rmdir(filename);
+			if (retval) {
+				if (errno == ENOTEMPTY)
+					return 0;
+				dbg("rmdir(%s) failed with error '%s'",
+				    filename, strerror(errno));
+				break;
+			}
+			dbg("removed %s", filename);
+		}
+	}
+	return retval;
 }
 
 int udev_remove_device(char *device, char *subsystem)

[-- Attachment #5: 03-udev-add.c-set_owner.diff --]
[-- Type: text/plain, Size: 1259 bytes --]

--- /tmp/udev-add.c	2003-11-05 18:58:53.000000000 +0100
+++ udev-add.c	2003-11-05 18:58:58.000000000 +0100
@@ -67,7 +67,8 @@
 }
 
 /*
- * We also want to add some permissions here, and possibly some symlinks
+ * we possibly want to add some symlinks here
+ * only numeric owner/group id's are supported
  */
 static int create_node(struct udevice *dev)
 {
@@ -132,7 +133,35 @@
 		dbg("mknod(%s, %#o, %u, %u) failed with error '%s'",
 		    filename, dev->mode, dev->major, dev->minor, strerror(errno));
 
-	// FIXME set the ownership of the node
+	uid_t uid = 0;
+	gid_t gid = 0;
+
+	if (*dev->owner) {
+		char *endptr;
+		unsigned long id = strtoul(dev->owner, &endptr, 10);
+		if (*endptr == 0x00)
+			uid = (uid_t) id;
+		else
+			dbg("only numeric owner id supported: %s", dev->owner);
+	}
+
+	if (*dev->group) {
+		char *endptr;
+		unsigned long id = strtoul(dev->group, &endptr, 10);
+		if (*endptr == 0x00)
+			gid = (gid_t) id;
+		else
+			dbg("only numeric group id supported: %s", dev->group);
+	}
+
+	if (uid || gid) {
+		dbg("chown(%s, %u, %u)", filename, uid, gid);
+		retval = chown(filename, uid, gid);
+		if (retval)
+			dbg("chown(%s, %u, %u) failed with error '%s'", filename,
+			    uid, gid, strerror(errno));
+	}
+
 	return retval;
 }
 

[-- Attachment #6: 04-namedev.c-cleanup.diff --]
[-- Type: text/plain, Size: 960 bytes --]

--- ../udev/namedev.c	2003-10-30 22:46:08.000000000 +0100
+++ namedev.c	2003-11-05 20:13:38.000000000 +0100
@@ -623,10 +623,6 @@
 			}
 
 			strcpy(udev->name, dev->name);
-			if (isdigit(class_dev->path[strlen(class_dev->path)-1])) {
-				temp = &class_dev->path[strlen(class_dev->path)-1];
-				strcat(udev->name, temp);
-			}
 			if (dev->mode != 0) {
 				udev->mode = dev->mode;
 				strcpy(udev->owner, dev->owner);
@@ -671,8 +667,8 @@
 				strcpy(udev->group, dev->group);
 			}
 			dbg_parse("device id '%s' becomes '%s' - owner = %s, group = %s, mode = %#o",
-				dev->id, udev->name, 
-				dev->owner, dev->group, dev->mode);
+				  dev->id, udev->name,
+				  dev->owner, dev->group, dev->mode);
 			goto done;
 			break;
 			}
@@ -683,7 +679,7 @@
 
 			if (!class_dev->sysdevice)
 				continue;
-			found = 0;	
+			found = 0;
 			strcpy(path, class_dev->sysdevice->path);
 			temp = strrchr(path, '/');
 			dbg_parse("TOPOLOGY path = '%s'", path);

^ permalink raw reply	[flat|nested] 16+ messages in thread
* Re: [udev] updated man, subdirs, ownership, namedev enum patches
@ 2003-11-12  3:53 Greg KH
  2003-11-12 13:23 ` Kay Sievers
                   ` (13 more replies)
  0 siblings, 14 replies; 16+ messages in thread
From: Greg KH @ 2003-11-12  3:53 UTC (permalink / raw)
  To: linux-hotplug

On Wed, Nov 05, 2003 at 08:31:28PM +0100, Kay Sievers wrote:
> 
> 01-udev.8.diff:
>   man page style fixes
>   present the tiny udev in bold font :)

Thanks, I've applied this.

> 02-udev-add.c-subdirs.diff:
> 02-udev-remove.c-subdirs.diff:
>   support subdirectory creation/removal for NAME="/devfs/is/crazy/video0"
>   create parent subdirs for device node if needed
>   remove subdirs when last node is removed

Nice, I've applied this.

> 03-udev-add.c-set_owner.diff
>   set uid/gid of node specified in udev.permissions
>   only numeric id's are supported cause we can't resolve with
>   klibc or libc before real /etc is mounted

Thanks, I've applied this, and fixed the patch so that it will build
with older versions of gcc.

> 04-namedev.c-cleanup.diff
>   remove part of udev that appends the kernel enumeration to character devices
>   in LABEL method: NAME="webcam" results in /udev/webcam0

Hm, are you sure this patch is correct?  What happened to your other one
where you could put a '%' in the string to put the number into the name?
I think this patch breaks partition naming, did you try it on them?

Thanks a lot for your changes, I really apprecate them,

greg k-h


-------------------------------------------------------
This SF.Net email sponsored by: ApacheCon 2003,
16-19 November in Las Vegas. Learn firsthand the latest
developments in Apache, PHP, Perl, XML, Java, MySQL,
WebDAV, and more! http://www.apachecon.com/
_______________________________________________
Linux-hotplug-devel mailing list  http://linux-hotplug.sourceforge.net
Linux-hotplug-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2003-11-19 23:42 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-11-05 19:38 [udev] updated man, subdirs, ownership, namedev enum patches Kay Sievers
  -- strict thread matches above, loose matches on Subject: below --
2003-11-12  3:53 Greg KH
2003-11-12 13:23 ` Kay Sievers
2003-11-13  6:23 ` Greg KH
2003-11-13  8:30 ` Kay Sievers
2003-11-13 19:49 ` Greg KH
2003-11-15 16:09 ` Kay Sievers
2003-11-17 17:33 ` Arnd Bergmann
2003-11-18  1:00 ` Greg KH
2003-11-18  1:14 ` Greg KH
2003-11-18  3:15 ` Kay Sievers
2003-11-18 12:09 ` Arnd Bergmann
2003-11-18 12:17 ` Arnd Bergmann
2003-11-19  0:24 ` Greg KH
2003-11-19 23:40 ` Greg KH
2003-11-19 23:42 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).