Hi,
zity wrote:I'll change my mount procedure, so the file operations for /dev/fd0 is passed directly to the driver. I'll furthermore try to look into some sort of caching in VFS to avoid unnecessary calls to the filesystem. To begin with, I'll try to cache directories and later on files.
Caching (especially for directory entries) isn't something I'd recommend adding later, as it changes everything.
For example, imagine an application asks to open the file "/mnt/cdrom/bar/foo.txt". The VFS looks in its cache and the directory entry isn't there, so the VFS asks the file system mounted at "/mnt/cdrom" for a complete listing of everything in the "/bar" directory. For each directory entry returned by the file system code there's some sort of reference number, where the VFS doesn't care what this reference number means, and it can have a different meaning for each type of file system (e.g. for FAT it could be the number of the first cluster in the chain of clusters used to store the file or subdirectory; and for ISO9660 it could be the LBA sector number of the first sector used to store the file or subdirectory). Later, when the VFS receives the list of directory entries from the file system it find all requests that where waiting for this information (including the original application's "open()" request, but there may be other requests by this time), and for the application's "open()" request the VFS can tell the application that the file has been opened successfully (without bothering to tell the file system).
The application might just do an "fstat()" then close the file, and in this case the VFS can handle the "fstat()" and the "close()" without caring about the file system (as the file system still doesn't know that any file was opened and therefore doesn't need to know the file was closed, and the VFS would/should still have the directory information needed for the "fstat()" in its cache).
If the application reads from the file and if the data being read is in the VFS cache, then the VFS still doesn't need to tell the file system that the file is opened.
If the application reads data from the file that isn't in the VFS cache, or writes new data to the file; then the VFS can tell the file system that the file was opened (if it didn't already, due to a previous read or write) and ask the file system to read/write the data (and the VFS would also update the data stored in its cache). When the application calls "close()" the VFS checks to see if the file system knows that the file was opened, and only lets the file system know about the "close()" if the file system knew about the "open()".
When the VFS asks the file system to add, delete or rename a directory entry, or when the VFS asks the file system to read or write file data, then VFS tells the file system its own reference number for the directory or file, so that the file system doesn't need to try to figure out where the subdirectory or file is on the disk. For example, the application (after opening "/mnt/cdrom/bar/foo.txt") might want to read 4096 bytes from offset 123456 in the file, so the VFS might ask the ISO 9660 file system to read 4096 bytes from the file associated with the reference number that the ISO9660 previously provided (note: there's no need for the VFS to tell the file system the file name), and the ISO9660 file system (that uses this reference number to track the starting sector) can find the data it needs to read without looking at (or keeping track of) any directory information at all.
Basically there's no need for the file system to keep track the last opened directory on the drive in a structure; because the file system knows that the directory information that was last used by the VFS will be in the VFS cache, and that the VFS will keep track of the file system's reference numbers. Except for managing (one or more) queues of pending requests; you'd be able to implement an ISO9660 file system without tracking any data at all in the file system code, and for FAT file systems the only thing you'd need to track in the file system code is the "FAT" (Cluster Allocation Table) itself.
Cheers,
Brendan