[Prev][Next][Index][Thread]

Re: Linux FS and fopen



> From: Vaughan Knight <vsk01@uow.edu.au>
> Subject: Linux FS and fopen
> Date: Wed, 25 Apr 2001 09:10:03 -0700
> 
> Firstly, I can mount a drive, and read and write using oskits seek, read
> and write functions, but I really would like to use the linux filesystem
> using fopen, fprintf and fclose etc.

Hi. Take a look at examples/x86/more/netbsd_fs_posix.c. This is a program
that does what you want, only it uses the netbsd filesystem component
instead of the linux fs. The important line of that program is:

	start_fs(diskname, partname);

which is a routine in the startup library (oskit/startup/start_fs.c) that
opens up the disk and initializes the netbsd filesystem code. You basically
need to write yourself a little start_fs_linux.c file that does the same
stuff, except with the linux stuff replacing the netbsd stuff. Since you
already have a program of your own that uses the linux fs, it should be
pretty obvious what bits need to change in start_fs.c to make a
start_fs_linux.c. 

> Secondly, when I 'make' the programs, I just use the standard 'make'. 
> Such as, when compiling the example gethostbyname I use 'make
> gethostbyname'.  It compiles and runs from grub, but, it can not access
> the files on /etc/resolve.conf and hense, can't access the nameserver
> variables.

Yes, this is related to the first problem. The gethostbyname example kernel
is using a memory filesystem. Thats the only filesystem it knows about. If
you look in examples/x86/more/gethostbyname.c, you will see this line:

	start_fs_bmod();

which initializes the memory filesystem and copies in the boot modules.
Once this call is made, / points to /bmod, so /etc/resolv.conf is really on
/bmod/etc/resolv.conf. You need to replace this call with your new
start_fs_linux() routine so that /etc is on your disk partition, not in 
/bmod. If you also want boot modules, you can use both a bmod and a real
filesystem. Look in startup/start_world.c. Search for "bmod".

Hope this helps.

Lbs

----------------------------------------
Leigh B. Stoller
University of Utah - Flux Research Group
http://www.cs.utah.edu/~stoller
----------------------------------------

References: