updated man, subdirs, ownership, namedev enum patches
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
home/kay/udev/udev.8 renamed from udev.8 +8 -5
@@ -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 <[email protected]> with much help from +.B udev +was developed by Greg Kroah-Hartman <[email protected]> with much help from Dan Stekloff <[email protected]> and many others.
udev-add.c renamed from udev/udev-add.c +26 -0
@@ -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)
udev-remove.c renamed from udev/udev-remove.c +34 -1
@@ -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)
udev-add.c renamed from tmp/udev-add.c +31 -2
@@ -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; }
namedev.c renamed from udev/namedev.c +3 -7
@@ -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);