linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Adam J. Richter" <adam@yggdrasil.com>
To: rgooch@atnf.csiro.au, linux-kernel@vger.kernel.org
Subject: Proposal: devfs names ending in %d or %u
Date: Sun, 24 Dec 2000 19:28:40 -0800	[thread overview]
Message-ID: <20001224192840.A12097@adam.yggdrasil.com> (raw)

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

	It seems that just about everything that uses devfs
contains some logic that attempts to construct an unused
device name with something like:

	static devnum = 0;

	sprintf (name, "lp%d", devnum++);
	devfs_register_device(..., name,...);

	Besides duplicating a lot of logic, making devfs support
more of a pain to add and uglier to look at, the numbering behvior
of these drivers can be inconsistent, especially if some devices
are being removed.  For example, as I insert and remove my PCMCIA
flash card, it becomes /dev/discs/disc1, /dev/discs/disc2,
/dev/discs/disc3, etc.

	I propose to change the devfs registration functions
to allow registrations of devices ending in %d or %u, in which
case it will use the first value, starting at 0, that generates a
string that already registered.  So, if I have disc0, disc1, and disc2,
and I remove the device containing disc1, then disc1 will be next
disc device name to be registered, then disc3, then disc4, etc.

	Just to illustrate, I have attached a patch that should
do it for device files, but I also want to do this for symlinks and
possibly directories.  So, I am not suggesting that anyone should
integrate this patch yet.

	This will make it a bit simpler to add devfs support to
the remaining drivers that do not have it, and it will make
numbering within devfs much simpler by default.  Of course, drivers
that want to do their own thing the current way would not be impeded
from doing so by this change.

	Anyhow, I thought I should post this suggestion to see if
anyone has any objections, better ideas, improvements or comments.

-- 
Adam J. Richter     __     ______________   4880 Stevens Creek Blvd, Suite 104
adam@yggdrasil.com     \ /                  San Jose, California 95129-1034
+1 408 261-6630         | g g d r a s i l   United States of America
fax +1 408 261-6631      "Free Software For The Rest Of Us."

[-- Attachment #2: diffs.devfs --]
[-- Type: text/plain, Size: 940 bytes --]

--- linux-2.4.0-test13-pre4/fs/devfs/base.c	Fri Nov 17 11:36:27 2000
+++ linux/fs/devfs/base.c	Sun Dec 10 13:50:29 2000
@@ -1238,6 +1253,7 @@
 {
     int is_new;
     struct devfs_entry *de;
+    int numeric_suffix;
 
     if (name == NULL)
     {
@@ -1292,8 +1308,16 @@
 	minor = next_devnum_block & 0xff;
 	++next_devnum_block;
     }
-    de = search_for_entry (dir, name, strlen (name), TRUE, TRUE, &is_new,
-			   FALSE);
+    numeric_suffix = 0;
+    do {
+	char realname[strlen(name)+11]; /* max 32-bit decimal integer is 10
+					  characters, plus one for
+					  terminating null. */
+	sprintf(realname, name, numeric_suffix);
+	numeric_suffix++;
+        de = search_for_entry (dir, realname, strlen (realname), TRUE, TRUE,
+			       &is_new, FALSE);
+    } while (!is_new && de != NULL && strcmp(name+strlen(name)-2, "%d") == 0); 
     if (de == NULL)
     {
 	printk ("%s: devfs_register(): could not create entry: \"%s\"\n",

             reply	other threads:[~2000-12-25  3:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-12-25  3:28 Adam J. Richter [this message]
2000-12-25  5:46 ` Proposal: devfs names ending in %d or %u Eric Shattow
2000-12-25  7:02   ` Barry K. Nathan
2000-12-25 15:32     ` idalton

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=20001224192840.A12097@adam.yggdrasil.com \
    --to=adam@yggdrasil.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rgooch@atnf.csiro.au \
    /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).