* udev creation/removal of subdirectories
@ 2003-10-31 14:19 Kay Sievers
0 siblings, 0 replies; only message in thread
From: Kay Sievers @ 2003-10-31 14:19 UTC (permalink / raw)
To: linux-hotplug
[-- Attachment #1: Type: text/plain, Size: 1153 bytes --]
Hi,
here is a patch to implement subdirectory creation/removal:
LABEL, BUS="usb", model="Creative Labs WebCam 3", NAME="devfs/scheme/is/crazy"
it does on ADD:
Oct 31 15:00:48 pim udev[21614]: udev_add_device: name = devfs/scheme/is/crazy
Oct 31 15:00:48 pim udev[21614]: create_node: created /udev/devfs
Oct 31 15:00:48 pim udev[21614]: create_node: created /udev/devfs/scheme
Oct 31 15:00:48 pim udev[21614]: create_node: created /udev/devfs/scheme/is
Oct 31 15:00:48 pim udev[21614]: create_node:mknod(/udev/devfs/scheme/is/crazy, 020666, 81, 0)
and on REMOVE:
Oct 31 15:01:40 pim udev[21622]: get_name: name is devfs/scheme/is/crazy
Oct 31 15:01:40 pim udev[21622]: delete_node: unlinking /udev/devfs/scheme/is/crazy
Oct 31 15:01:40 pim udev[21622]: delete_node: removed /udev/devfs/scheme/is
Oct 31 15:01:40 pim udev[21622]: delete_node: removed /udev/devfs/scheme
Oct 31 15:01:40 pim udev[21622]: delete_node: removed /udev/devfs
thanks,
Kay
support for subdirectory creation/removal for NAME="printer/hp"
03-udev-add.c-subdirs.diff
o create parent subdirs for device node if needed
03-udev-remove.c-subdirs.diff
o remove subdirs if empty
[-- Attachment #2: 03-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 #3: 03-udev-remove.c-subdirs.diff --]
[-- Type: text/plain, Size: 1111 bytes --]
--- ../udev/udev-remove.c 2003-10-30 22:46:08.000000000 +0100
+++ udev-remove.c 2003-10-31 14:38:12.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'",
+ strerror(errno));
+ break;
+ }
+ dbg("removed %s", filename);
+ }
+ }
+ return retval;
}
int udev_remove_device(char *device, char *subsystem)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2003-10-31 14:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-31 14:19 udev creation/removal of subdirectories Kay Sievers
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).