Date: Fri, 27 Apr 2001 13:48:58 +0100 From: Ian Dowse <iedowse@maths.tcd.ie> To: Igor Shmukler <shmukler@mail.ru> Cc: freebsd-fs@FreeBSD.ORG, iedowse@maths.tcd.ie Subject: Re: more on FFS Message-ID: <200104271348.aa54585@salmon.maths.tcd.ie> In-Reply-To: Your message of "Thu, 26 Apr 2001 21:05:23 EDT." <03b901c0ceb6$27ceae00$7b02a8c0@tp600e>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi? <200104271348.aa54585>