From owner-freebsd-fs Fri Apr 27 5:49: 2 2001 Delivered-To: freebsd-fs@freebsd.org Received: from salmon.maths.tcd.ie (salmon.maths.tcd.ie [134.226.81.11]) by hub.freebsd.org (Postfix) with SMTP id D4C4E37B423 for ; Fri, 27 Apr 2001 05:48:59 -0700 (PDT) (envelope-from iedowse@maths.tcd.ie) Received: from walton.maths.tcd.ie by salmon.maths.tcd.ie with SMTP id ; 27 Apr 2001 13:48:58 +0100 (BST) To: Igor Shmukler Cc: freebsd-fs@FreeBSD.ORG, iedowse@maths.tcd.ie Subject: Re: more on FFS In-Reply-To: Your message of "Thu, 26 Apr 2001 21:05:23 EDT." <03b901c0ceb6$27ceae00$7b02a8c0@tp600e> Date: Fri, 27 Apr 2001 13:48:58 +0100 From: Ian Dowse Message-ID: <200104271348.aa54585@salmon.maths.tcd.ie> Sender: owner-freebsd-fs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org In message <03b901c0ceb6$27ceae00$7b02a8c0@tp600e>, Igor Shmukler writes: > >How do I find where on disk ROOT inode is located. >I tried to thru sources, but FS structure quite large and I get lost in = >offsets. The `ino_to_fsba' and `ino_to_fsbo' macros defined in fs.h are probably what you want. `ino_to_fsba' returns the offset from the start of the partition of the block containing the specified inode. This offset is in units of the filesystem fragment size, and you are expected to read a full fs_bsize block starting at that offset. Then `ino_to_fsbo' tells you the inode number within that block. e.g. (untested, and has no error checking): struct fs *fs; char *sbbuf; char *blockbuf; struct dinode *dip; off_t offset; fd = open("/dev/da0s1a", O_RDONLY); /* read superblock and point `fs' at it. */ sbbuf = malloc(SBSIZE); pread(fd, sbbuf, SBSIZE, SBOFF); fs = (struct fs *)sbbuf; /* Get the root inode */ offset = (off_t)ino_to_fsba(fs, ROOTINO) * (off_t)fs->fs_fsize; blockbuf = malloc(fs->fs_bsize); pread(fd, blockbuf, fs->fs_bsize, offset); dip = &((struct dinode *)blockbuf)[ino_to_fsbo(fs, ROOTINO)]; /* `dip' now points to the root inode */ Ian To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-fs" in the body of the message