VFS
Posted: Sun Dec 16, 2007 4:47 am
Hey all, I'm back with another question
I have working disk drivers, and a mono-tasking fs/vfs design (which I've scrapd completely since it crashed or froze 50% of the time).
Anyway, my disk drivers are functioning. They inherit from my C++ interface that provides functions such as Read(unsigned long long offset, void *buffer, unsigned int size). I've removed all FS and VFS drivers from my OS. My kernel stores a linked list of disk device instances with common functions such as GetSize, GetName, Read, Write, etc..
How my disk drives work is each driver has a background thread. This thread is sleeping when there is no request on the queue. When a thread calls Read or Write on the device, the disk driver adds a request to the driver's queue, wakes the driver's thread, and places the thread that called Read or Write to sleep. The driver's thread completes the first request on the queue. When the request is completed (or failed), the calling thread is woken. A device driver can only do one request at a time, since the driver goes through each request on the queue one by one, so I am thinking of designing my VFS to split calls up into 64kb/128kb sections, so if someone is copy a 1GB file, all other requests on the device are not held up.
Anyway, on to my FS driver and VFS design. How do I design my VFS system? I know that a VFS is made up of nodes representing files/directories, but when do I update what is in the VFS with what is on the disk? And on a FAT FS driver, always storing the FAT in memory is obvious, but what about storing directories? Like, if I access the file "/a/b/c/d/e/f/g" a lot, would it have to scan through directory a, then directory b, then directory c, etc each time I wanted to access the file? Say directory c had thousands of files which took a 20 seconds to scan through (on a very slow floppy drive) and I wanted to loop through 100 files in a subfolder of c, then starting at the drive's root and going through each folder on each file request would be slow.
I have working disk drivers, and a mono-tasking fs/vfs design (which I've scrapd completely since it crashed or froze 50% of the time).
Anyway, my disk drivers are functioning. They inherit from my C++ interface that provides functions such as Read(unsigned long long offset, void *buffer, unsigned int size). I've removed all FS and VFS drivers from my OS. My kernel stores a linked list of disk device instances with common functions such as GetSize, GetName, Read, Write, etc..
How my disk drives work is each driver has a background thread. This thread is sleeping when there is no request on the queue. When a thread calls Read or Write on the device, the disk driver adds a request to the driver's queue, wakes the driver's thread, and places the thread that called Read or Write to sleep. The driver's thread completes the first request on the queue. When the request is completed (or failed), the calling thread is woken. A device driver can only do one request at a time, since the driver goes through each request on the queue one by one, so I am thinking of designing my VFS to split calls up into 64kb/128kb sections, so if someone is copy a 1GB file, all other requests on the device are not held up.
Anyway, on to my FS driver and VFS design. How do I design my VFS system? I know that a VFS is made up of nodes representing files/directories, but when do I update what is in the VFS with what is on the disk? And on a FAT FS driver, always storing the FAT in memory is obvious, but what about storing directories? Like, if I access the file "/a/b/c/d/e/f/g" a lot, would it have to scan through directory a, then directory b, then directory c, etc each time I wanted to access the file? Say directory c had thousands of files which took a 20 seconds to scan through (on a very slow floppy drive) and I wanted to loop through 100 files in a subfolder of c, then starting at the drive's root and going through each folder on each file request would be slow.