Subject: Re: Where/how is rootvp set in kernel initialisation?
To: None <nigel@ind.tansu.com.au>
From: Bill Studenmund <wrstuden@zembu.com>
List: tech-kern
Date: 09/19/2000 12:57:45
On Tue, 19 Sep 2000 nigel@ind.tansu.com.au wrote:

> 
> Background: I am the maintainer of the Booter program for the Mac68k
> 	    port, and I am trying to build a MacOS program which uses
> 	    the actual kernel code for doing FFS volume manipulation
> 	    (instead of the hacked old UFS code it uses now).

Yea!

> Status: I have a few libraries of the relevant files from the syssrc
> 	archive, and a hacked together main. When my main does the
> 	guts of vfs_mountroot(), it accesses non-existant memory when
> 	ffs_mountroot() calls ffs_mountfs() with rootvp.
> 
> 	(basically, vinvalbuf() does a VSYNC, but because
> 	 rootvp is not set to anything but NULL, v_op is invalid)

The routine you need to look at is in ffs_mountroot(). A few lines above
the ffs_mountfs() call is a call to bdevvp(rootdev, &rootvp);. That's the
call which will set up rootvp. Make sure it works right, and you'll have a
good vnode. bdevvp() will call into kern/vfs_subr.c and you'll need files
from miscfs/specfs so that spec_vnode_p is set up. Then the v_op table
will be ok.

> 	I have searched through the kernel source, and these are the
> only three places that seem to set rootvp:
> 
> coda_vfsops.c   : coda_mount()

Note that there is a local variable in this routine named rootvp, so it's
not changing the global rootvp. :-)

> vfs_getcwd.c    : sys___getcwd()

As best I could tell, this one was just reading rootvp. ??

> kernfs_vfsops.c : kernfs_unmount()

This one too has a local variable for rootvp. I think both it and the coda
code are refering to the root of the file system, not the system's overall
root vnode.

> 	Assuming that I haven't stuffed up in my searching,
> which of these is called (indirectly) from init_main(), and why ?

You'll need to make sure that your init_main() has the vfs initialization
in it, then all should be well.

Take care,

Bill