Re: LANANA: To Pending Device Number Registrants

H. Peter Anvin
2001-05-15T19:39:05Z

Richard Gooch wrote:
>
> Ingo Oeser writes:
> > On Tue, May 15, 2001 at 08:10:29AM -0700, Linus Torvalds wrote:
> > > and I don't see why we couldn't expose the "driver
> > > name" for any file descriptor.
> >
> > Because we dont like to replace:
> >
> > if (st.device == MAJOR_1)
> > bla
> > else if ...
> >
> > with
> >
> > if (!strcmp(st.device,"driver_1") )
> > bla
> > else if ...
> >
> > ?
> >
> > There is no win doing it this way, because every time we add a
> > new driver that fits or change the name of one, we need add
> > support for it.
>
> Now look at how we can already do these things with devfs. Let's say
> I've opened /dev/cdroms/cdrom0 and it's sitting on fd=3.
> % ls -lF /proc/self/fd/3
> lrwx------ 1 root root 64 May 15 13:24 /proc/self/fd/3 -> /dev/ide/host0/bus0/target1/lun0/cd
>
> So, in my application I do:
> len = readlink ("/proc/self/3", buffer, buflen);
> if (strcmp (buffer + len - 2, "cd") != 0) {
> fprintf (stderr, "Not a CD-ROM! Bugger off.\n");
> exit (1);
> }
> if (strncmp (buffer, "/dev/ide", 8) == 0) do_ide (fd);
> else if (strncmp (buffer, "/dev/scsi", 9) == 0) do_scsi (fd);
> else do_generic (fd);
>
> That's a lot cleaner than relying on magic numbers, IMNSHO.
>

You know, Richard, this was an example on what *NOT* to do!

-hpa

--
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."