lkml.org 
[lkml]   [2000]   [Dec]   [24]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectProposal: devfs names ending in %d or %u
	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."
--- 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",
\
 
 \ /
  Last update: 2005-03-22 12:52    [W:0.045 / U:1.444 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site