Messages in this thread |  | | Date | Tue, 15 May 2001 13:31:21 -0600 | From | Richard Gooch <> | Subject | Re: LANANA: To Pending Device Number Registrants |
| |
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.
Regards,
Richard.... Permanent: rgooch@atnf.csiro.au Current: rgooch@ras.ucalgary.ca - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
|  |