mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Proposal: devfs names ending in %d or %u
@ 2000-12-25  3:28 Adam J. Richter
  2000-12-25  5:46 ` Eric Shattow
  0 siblings, 1 reply; 4+ messages in thread
From: Adam J. Richter @ 2000-12-25  3:28 UTC (permalink / raw)
  To: rgooch, linux-kernel

[-- 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",

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-12-25 16:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-25  3:28 Proposal: devfs names ending in %d or %u Adam J. Richter
2000-12-25  5:46 ` Eric Shattow
2000-12-25  7:02   ` Barry K. Nathan
2000-12-25 15:32     ` idalton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®