From: torvalds@klaava.Helsinki.FI (Linus Benedict Torvalds) Subject: Re: VFS - Where can I read about it? Date: 22 May 1992 05:09:33 GMT
In article <BoMFDB.6wD@ais.org> lcd@ais.org (Leon Dent) writes:
>I read comp.os.linux, but don't (can't) yet run it. The VFS concept
>interests me, but I don't know what books or papers explain it.
>Pointers anyone?
As with the rest of the kernel internals, linux VFS doesn't exactly look
like anything else: the ideas are the same as in SunOS etc, but the
implementation is linux-specific (the first alpha-release used similar
macros as SunOS I think, but after my rewrites...)
So the only place to learn about linux VFS is the source code. It's not
really that bad: it's pretty simple. The different routines are
selected by following pointers to structures containg function-pointers.
For example if you want to find out which inode the name "/usr" points
to, you can use something like this (simplified, but you get the idea):
...
dir = current->root;
if (!dir->i_ops || !dir->i_ops->lookup)
return -ENOTDIR;
inode = dir->i_ops->lookup(dir,"usr");
...
Similarly, if you wanted to create the directory of "src/linux" relative
to the current pwd, you'd use something like this:
dir = current->pwd;
if (!dir....
inode = dir->i_ops->lookup(dir,"src");
if (!inode || !inode->i_ops || !inode->i_ops->mkdir)
return -ENOENT;
return inode->i_ops->mkdir(inode,"linux");
(when I use a string in the above, the real routines actually use a
pointer+length combination instead of the normal C strings. This means
there is no need to copy names around: we use the name the user supplied
directly, and the VFS routines parse away the slashes.. And as the
pointers are relative to the %fs segment, we can choose user/kernel
space strings just by changing the segment)
So the VFS layer just translates the unix system calls to these kinds of
indirect calls, keeping track of mount points/root/pwd etc. Thus the fs
is effectively in two separate pieces: the VFS which parses complete
filenames, and the filesystem-specific parts which just work on one part
at a time. The VFS doesn't care about the disk layout, and the
fs-specific parts don't have to know anything about mount-points/current
root/pwd etc idiosyncracies.
Linus