From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id ; Tue, 15 May 2001 15:39:05 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id ; Tue, 15 May 2001 15:38:55 -0400 Received: from neon-gw.transmeta.com ([209.10.217.66]:3846 "EHLO neon-gw.transmeta.com") by vger.kernel.org with ESMTP id ; Tue, 15 May 2001 15:38:35 -0400 Message-ID: <3B018587.ACE8BC12@transmeta.com> Date: Tue, 15 May 2001 12:37:43 -0700 From: "H. Peter Anvin" Organization: Transmeta Corporation X-Mailer: Mozilla 4.76 [en] (X11; U; Linux 2.4.5-pre1-zisofs i686) X-Accept-Language: en, sv, no, da, es, fr, ja MIME-Version: 1.0 To: Richard Gooch CC: Ingo Oeser , Linus Torvalds , Alan Cox , Neil Brown , Jeff Garzik , Linux Kernel Mailing List , viro@math.psu.edu Subject: Re: LANANA: To Pending Device Number Registrants In-Reply-To: <20010515200202.A754@nightmaster.csn.tu-chemnitz.de> <200105151931.f4FJVL830847@vindaloo.ras.ucalgary.ca> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org 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 -- at work, in private! "Unix gives you enough rope to shoot yourself in the foot." http://www.zytor.com/~hpa/puzzle.txt