From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kay Sievers Date: Wed, 05 Nov 2003 19:38:04 +0000 Subject: [udev] updated man, subdirs, ownership, namedev enum patches MIME-Version: 1 Content-Type: multipart/mixed; boundary="VbJkn9YxBvnuCH5J" Message-Id: List-Id: To: linux-hotplug@vger.kernel.org --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="01-udev.8.diff" --- 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 with much help from +.B udev +was developed by Greg Kroah-Hartman with much help from Dan Stekloff and many others. --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="02-udev-add.c-subdirs.diff" --- ../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) --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="02-udev-remove.c-subdirs.diff" --- ../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) --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="03-udev-add.c-set_owner.diff" --- /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; } --VbJkn9YxBvnuCH5J Content-Type: text/plain; charset=us-ascii Content-Disposition: inline; filename="04-namedev.c-cleanup.diff" --- ../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); --VbJkn9YxBvnuCH5J-- ------------------------------------------------------- This SF.net email is sponsored by: SF.net Giveback Program. Does SourceForge.net help you be more productive? Does it help you create better code? SHARE THE LOVE, and help us help YOU! Click Here: http://sourceforge.net/donate/ _______________________________________________ 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