Virtual File System Functions

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Virtual File System Functions

Post 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
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Post by piranha »

fread, fopen, fclose, fwrite, fseek, etc.
stdio.h should give you some ideas.
-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

how can I implement the virtual file system?

Have you any guide or tutorial?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Well actually, I happen to have one I cooked up earlier...

http://www.jamesmolloy.co.uk/tutorial_h ... nitrd.html
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post 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)
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post 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
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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?
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post 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?
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

and how can, for example, I mount a filesystem somewhere?
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

However I think I'll implement VFS functions same as FUSE.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post 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
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post 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?
User avatar
lukem95
Member
Member
Posts: 536
Joined: Fri Aug 03, 2007 6:03 am
Location: Cambridge, UK

Post 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.
~ Lukem95 [ Cake ]
Release: 0.08b
Image
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

Asking smart questions is part of the rules :roll:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Post 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.
Post Reply