Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!umcp-cs!chris From: chris@umcp-cs.UUCP (Chris Torek) Newsgroups: net.unix Subject: Re: Anything like getpwent() for inodes? Message-ID: <4035@umcp-cs.UUCP> Date: Tue, 28-Oct-86 06:29:25 EST Article-I.D.: umcp-cs.4035 Posted: Tue Oct 28 06:29:25 1986 Date-Received: Tue, 28-Oct-86 19:00:45 EST References: <117@BASKIN.UUCP> Reply-To: chris@umcp-cs.UUCP (Chris Torek) Organization: University of Maryland, Dept. of Computer Sci. Lines: 84 Summary: how to find inodes in a 4.2BSD-style file system In article <117@BASKIN.UUCP> peter@BASKIN.UUCP (Peter Klosky) writes: >I have been trying to get this [...] to work on the 4.2 file >system layout, but I am confused about this new file system. Finding inodes is not too hard. The main trick is that you must first read the super-block: #include #ifdef sun /* really NFS */ #include #include #else #include #endif #include union { struct fs sblk; char pad[SBSIZE]; } un; #define sblock un.sblk int diskfd; struct dinode *iget(); ... diskfd = open(rawdisk, 0); if (diskfd < 0) error... bread(SBLOCK, (char *)&sblock, SBSIZE); ... ip = iget(inode_number); ... struct dinode * iget(ino) ino_t ino; { static daddr_t iblk; static struct dinode *itab; static u_int itabsize; register daddr_t b; #ifdef fancy if (ino < ROOTINO) return (NULL); #endif if (itab == NULL) { /* * Allocate a table of the appropriate size. */ iblk = (daddr_t) -1; itabsize = INOPB(&sblock) * sizeof (*itab); itab = (struct dinode *) malloc(itabsize); if (itab == NULL) error... } /* * Inode is in block `File System Block to Disk Block' of * file system block `Inode to Disk block' of inode. */ b = fsbtodb(&sblock, itod(&sblock, ino)); if (b != iblk) { b = iblk; bread(b, (char *)itab, itabsize); } return (&itab[ino % INOPB(&sblock)]); } bread(bno, buf, cnt) daddr_t bno; char *buf; { lseek(diskfd, (off_t) dbtob(bno), 0); if (read(diskfd, buf, cnt) != cnt) error... } -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690) UUCP: seismo!umcp-cs!chris CSNet: chris@umcp-cs ARPA: chris@mimsy.umd.edu