Page 1 of 3

Virtual File System Functions

Posted: Wed Mar 26, 2008 1:37 pm
by Jeko
Which functions I need to implement a good Virtual File System?

I have (for now) these funcions:

Code: Select all

read
write
open
close
readdir
finddir

Posted: Wed Mar 26, 2008 1:51 pm
by piranha
fread, fopen, fclose, fwrite, fseek, etc.
stdio.h should give you some ideas.
-JL

Posted: Wed Mar 26, 2008 3:20 pm
by Jeko
how can I implement the virtual file system?

Have you any guide or tutorial?

Posted: Wed Mar 26, 2008 3:26 pm
by JamesM
Well actually, I happen to have one I cooked up earlier...

http://www.jamesmolloy.co.uk/tutorial_h ... nitrd.html

Posted: Wed Mar 26, 2008 4:22 pm
by Jeko
JamesM wrote:Well actually, I happen to have one I cooked up earlier...

http://www.jamesmolloy.co.uk/tutorial_h ... nitrd.html
But I don't understand how can I open for example a file like '/usr/lib/file.txt' (if there is this file) with this method...

For example if I have the function open("/usr/lib/file.txt"), how can this function open the file?

(assuming this file exists)

Posted: Wed Mar 26, 2008 5:08 pm
by AJ
Hi,

You need to have a VFS function which recurses through each path, stopping if it gets to a point where the next item does not exist. For example - first, check if 'usr' exists. If so, search the 'usr' directory for the 'lib' item. If that exists, find 'file.txt' and return a valid handle for that in the selected mode (read/write/append/etc...). If any stage of this fails, you stop and return an error code.

Although this isn't difficult, you need to think carefully about error checking, how errors are handled and exactly what mode types your OS will allow...

Cheers,
Adam

Posted: Thu Mar 27, 2008 1:09 am
by JamesM
MarkOS wrote:
JamesM wrote:Well actually, I happen to have one I cooked up earlier...

http://www.jamesmolloy.co.uk/tutorial_h ... nitrd.html
But I don't understand how can I open for example a file like '/usr/lib/file.txt' (if there is this file) with this method...

For example if I have the function open("/usr/lib/file.txt"), how can this function open the file?

(assuming this file exists)
That is actually explained in detail on that page - did you actually read it or just skim it?

Posted: Thu Mar 27, 2008 8:25 am
by Jeko
AJ wrote:Hi,

You need to have a VFS function which recurses through each path, stopping if it gets to a point where the next item does not exist. For example - first, check if 'usr' exists. If so, search the 'usr' directory for the 'lib' item. If that exists, find 'file.txt' and return a valid handle for that in the selected mode (read/write/append/etc...). If any stage of this fails, you stop and return an error code.

Although this isn't difficult, you need to think carefully about error checking, how errors are handled and exactly what mode types your OS will allow...

Cheers,
Adam
It's the only method to do this?

Posted: Thu Mar 27, 2008 8:46 am
by Jeko
and how can, for example, I mount a filesystem somewhere?

Posted: Thu Mar 27, 2008 8:57 am
by Jeko
However I think I'll implement VFS functions same as FUSE.

Posted: Thu Mar 27, 2008 9:04 am
by AJ
It is pretty much the only method until you have some kind of inode cache, but I would suggest that it some time in the future.

For FS mounting and so on, please see JamesM's link.

Cheers,
Adam

Posted: Thu Mar 27, 2008 9:05 am
by JamesM
MarkOS wrote:and how can, for example, I mount a filesystem somewhere?
Oh my God! It's in the link I posted! Do you not read?

Posted: Thu Mar 27, 2008 9:12 am
by lukem95
I think hes asking for a step by step :roll:

MarkOS, read the page james linked you to, SEVERAL TIMES. Then download the code, get it working, customise it so your sure you know how it works, and then re-think the question. I guarantee you you will have at least some of the answers then.

Posted: Thu Mar 27, 2008 9:20 am
by Combuster
Asking smart questions is part of the rules :roll:

Posted: Fri Mar 28, 2008 1:28 am
by bewing
I would add quite a few more, myself.

I'd say there need to be two versions of read and write -- one that does a buffered operation into a file descriptor buffer, and another that is filesystem specific for when you want to load/unload the file descriptor buffer. If you want to handle filesystems like mine, you even need a third (pre-read) read function that is called during the open() function.

You are going to need a routine to cache directory entries (as JamesM said); a routine to do sanity checks on raw directories, the full directory tree, and the inode structure; a defrag routine; a routine to return general info about the FS (volume name, # of free clusters and free inodes); a routine to allocate new "nodes" (directory or file) in the VFS; a routine to delete nodes, routines to allocate and free inodes; and, of course, open, close, finddir, readdir, seek, and stat.