From owner-freebsd-hackers Thu May 9 18:28:33 1996 Return-Path: owner-hackers Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id SAA26795 for hackers-outgoing; Thu, 9 May 1996 18:28:33 -0700 (PDT) Received: from godzilla.zeta.org.au (godzilla.zeta.org.au [203.2.228.19]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id SAA26785 for ; Thu, 9 May 1996 18:28:29 -0700 (PDT) Received: (from bde@localhost) by godzilla.zeta.org.au (8.6.12/8.6.9) id LAA20111; Fri, 10 May 1996 11:21:39 +1000 Date: Fri, 10 May 1996 11:21:39 +1000 From: Bruce Evans Message-Id: <199605100121.LAA20111@godzilla.zeta.org.au> To: hackers@FreeBSD.ORG, rnordier@iafrica.com Subject: Re: [Q] Raw interface to block devices Sender: owner-hackers@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk >I have a function > int process(const char *fs); >which expects 'fs' to refer to a device which may hold a filesystem. >The function actually works with the raw device, but allows the >user some flexibility. Eg: > process("/dev/rfd0"); or > process("/dev/fd0"); >An obvious, though clumsy, approach is: > stat() > if {S_IFCHR, S_IFBLK} > derive the other name by deleting/inserting an 'r' somewhere > stat() > check for (reversed) {S_IFCHR, S_IFBLK} devname(3) seems to be almost what you want. You can stat the first name to get the dev number and then call devname() to get the other name. It searches quickly through all the names in /var/run/dev.db. devname() seems to be used only in ps and pstat. It should be used in badsect, fsck ... (fsck has its own functions rawname() and unrawname()). ps has a bogus private copy of /usr/src/lib/libc/gen/devname.c. Bruce