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.
z180
Member
Member
Posts: 32
Joined: Tue Mar 04, 2008 12:32 pm

Post by z180 »

i try giving the vectors of my vfs out of the head back
my vfs is a bit incomplete but is based on various
documentation ,sourcecode of different systems
and my own input (it could be that i forgot some functions)
the vector struct vfsops in struct vfs (and struct vfsinfo) contains
sbread (for mount)
sbwrite
alloc_inode
free_inode
vfsctl (commands like ioctl)
mountroot

struct inode contains struct inodeops
lookup
create ( (can create fifos )unix had only creat)
open
close
rdwr (read and write have same vector)
ioctl
select (for pipes/FIFOs and IFCHR devices,I have no sockets)
rename
unlink
readlink
symlink
link
pagein(like VOP_GETPAGES)
pageout
strategy(for block device inodes)
sync
free
stat
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

Sorry... I didn't explain very well...

If for example I have a ext3 filesystem mounted on '/', how can I mount devfs on '/dev' ?

I must write functions to handle mountpoints in the ext3 filesystem driver?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Hi MarkOS,

All of this is painstakingly explained in the tutorial page I linked you to.

You impement a VFS - a virtual file system. This is a graph of nodes. Each node can represent a file, directory, pipe, socket, symbolic link, character device or block device. Each node has within it function pointers for open()/close()/read/write/ioctl. These function pointers point to the appropriate functions in the driver for the filesystem type that the inode is part of. Mounting a new filesystem is as simple as taking an existing directory node, adding children (your (devfs in your example) driver would do this) and setting those children's function pointers to point to your devfs functions, instead of your ext3 functions.

Cheers,

James
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

JamesM wrote:Hi MarkOS,

All of this is painstakingly explained in the tutorial page I linked you to.

You impement a VFS - a virtual file system. This is a graph of nodes. Each node can represent a file, directory, pipe, socket, symbolic link, character device or block device. Each node has within it function pointers for open()/close()/read/write/ioctl. These function pointers point to the appropriate functions in the driver for the filesystem type that the inode is part of. Mounting a new filesystem is as simple as taking an existing directory node, adding children (your (devfs in your example) driver would do this) and setting those children's function pointers to point to your devfs functions, instead of your ext3 functions.

Cheers,

James
I understand this...
But how can I mount '/dev' on '/' ?
I don't know which filesystem is in '/', there can be ext3, reiserfs, ext2, or another.
How can I create mountpoints not statically but dinamically? The filesystem driver must have a function pointer for a function mount?
What if I want to mount '/media/hda0' on '/dev/hda0'?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

The entire point of a VFS is that it abstracts away the need to know what driver is used to access any particular file.

To mount /dev on /, you first take "/", which will be a VFS node, and find the "dev" directory child node. You then pass that VFS node into your devfs driver's "mount" function. The devfs driver will use that as its root.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

JamesM wrote:The entire point of a VFS is that it abstracts away the need to know what driver is used to access any particular file.

To mount /dev on /, you first take "/", which will be a VFS node, and find the "dev" directory child node. You then pass that VFS node into your devfs driver's "mount" function. The devfs driver will use that as its root.
Ok... This is the answer to my questions!

So I need to add the mount function's pointer in the fs node structure.
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

If you want a good well commented example, written in fasm, see "titan operating system", the OS written by Tomasz Grysztar (coder of fasm ), if you can not finded it let me know, i have a copy on disk some where.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

Dex wrote:If you want a good well commented example, written in fasm, see "titan operating system", the OS written by Tomasz Grysztar (coder of fasm ), if you can not finded it let me know, i have a copy on disk some where.
I can't find it.. Could you send me it by email? (or post it here if you can)
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post by Dex »

Here is a link http://board.flatassembler.net/topic.php?t=153
But you need to be a member to down load it.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

JamesM wrote:The entire point of a VFS is that it abstracts away the need to know what driver is used to access any particular file.

To mount /dev on /, you first take "/", which will be a VFS node, and find the "dev" directory child node. You then pass that VFS node into your devfs driver's "mount" function. The devfs driver will use that as its root.
but when I read the dir /dev, how can the filesystem mounted on '/' know that /dev is a mountpoint?
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Do you even read what I write?
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Post by Brynet-Inc »

MarkOS wrote:but when I read the dir /dev, how can the filesystem mounted on '/' know that /dev is a mountpoint?
Why would it need to? All the root file system would need is an empty directory where DevFS will be mounted (/dev for example..).

The DevFS would essentially claim that point of the hierarchy and populate it with device nodes, none of which would physically read or write to the file system mounted at /.

I think you're having a hard time grasping some of the basic concepts here... not sure how you want us to help you with that. :?
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Jeko
Member
Member
Posts: 500
Joined: Fri Mar 17, 2006 12:00 am
Location: Napoli, Italy

Post by Jeko »

I can't explain myself well because I don't know english very well...

I make an example.
I have ext3 mounted on '/'.
There is a directory in the ext3 filesystem 'dev'.
The DevFS is mounted on '/dev/'.

If I open '/' and I read subdirs, I have:
'.'
SOMEDIRS
'dev'

If I open '/dev' how can I know it's a mountpoint? I must have a list of mountpoints? Or the ext3 filesystem must say it's a mountpoint?
User avatar
JoeKayzA
Member
Member
Posts: 79
Joined: Wed Aug 24, 2005 11:00 pm
Location: Graz/Austria

Post by JoeKayzA »

MarkOS wrote:If I open '/dev' how can I know it's a mountpoint? I must have a list of mountpoints? Or the ext3 filesystem must say it's a mountpoint?
To my knowledge, most *nix-like os maintain a list of mountpoints and check the absolute path against this list to determine which filesystem driver to pass the request to, or they use a seperate tree of inodes above the actual filesystem layer (at vfs level) where you could put this information. In my opinion, the filesystem driver itself shouldn't deal with mountpoints at all, at least not in the traditional unix way of doing things.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Exactly - it's dealt with via the function pointers I explained above again and again...

At the VFS level there is no such thing as a mountpoint - just the inodes in / and the inodes in /dev would have their read()/write()/etc function pointers pointing at different places, the former to the ext3 read/write/etc functions, the latter to the devfs read/write/etc functions.
Post Reply