linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kay Sievers <lkml001@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: udev creation/removal of subdirectories
Date: Fri, 31 Oct 2003 14:19:46 +0000	[thread overview]
Message-ID: <marc-linux-hotplug-106761018427743@msgid-missing> (raw)

[-- 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)

                 reply	other threads:[~2003-10-31 14:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=marc-linux-hotplug-106761018427743@msgid-missing \
    --to=lkml001@vrfy.org \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).