VFS, file handles & stdio
Posted: Sun Jan 18, 2015 12:22 pm
Hi there, I've been over this in my head about 500 times or so - but still think I need some input. Back in 2012 I wrote my VFS and FAT12 code, which I then lost while breaking an USB stick in half. Recently I've been going back to an older copy of my code and started to rebuild. I'm pretty sure that my old code had the VFS and FAT12 completed enough for file handles and all that to be done, it's just I can't really remember what I decided on.
Also, back then I hadn't really thought through how the VFS and file handles corresponds to stdin, stdout and stderr. How I'm thinking right now is that my code for VFS will have to register some kind of rudimentary file i/o to the stdio, which will be to busy dealing with screens and keyboards to really care about how stuff is outputted to file.
So far so good? Now to file handles, the most obvious thing would be to stick them into the VFS, making them FS independent. The problem with that is that it would need information like first file cluster and possibly the directory entry if it's FAT12, while probably inode number and stuff if it's ext2/3?
I've been heavily inspired but what I've found on this page: http://stanislavs.org/helppc/file_handles.html since my OS will never be much more then a DOS copy running in 32-bit mode. But it's pretty hardcoded for FAT12/16 in DOS.
It might be better for the filesystem to define filehandles themselves, for a more specific structure based on need. Now, I'm thinking that perhaps the FS driver should define the file handle structure, and be responsible for parsing it, while the VFS just takes a copy of the pre-defined filehandle structure and allocates a buffer for that format and sticks a pointer into the mounted drive structure, allocating more buffer space if it runs out of free handles?
Actually that last part dawned on me as I was typing, so perhaps I'll sort this out after all. I'd still like some input on how you handle stuff like this, and if your OS does things differently from *nix or DOS - what differs?
Also, back then I hadn't really thought through how the VFS and file handles corresponds to stdin, stdout and stderr. How I'm thinking right now is that my code for VFS will have to register some kind of rudimentary file i/o to the stdio, which will be to busy dealing with screens and keyboards to really care about how stuff is outputted to file.
So far so good? Now to file handles, the most obvious thing would be to stick them into the VFS, making them FS independent. The problem with that is that it would need information like first file cluster and possibly the directory entry if it's FAT12, while probably inode number and stuff if it's ext2/3?
I've been heavily inspired but what I've found on this page: http://stanislavs.org/helppc/file_handles.html since my OS will never be much more then a DOS copy running in 32-bit mode. But it's pretty hardcoded for FAT12/16 in DOS.
It might be better for the filesystem to define filehandles themselves, for a more specific structure based on need. Now, I'm thinking that perhaps the FS driver should define the file handle structure, and be responsible for parsing it, while the VFS just takes a copy of the pre-defined filehandle structure and allocates a buffer for that format and sticks a pointer into the mounted drive structure, allocating more buffer space if it runs out of free handles?
Actually that last part dawned on me as I was typing, so perhaps I'll sort this out after all. I'd still like some input on how you handle stuff like this, and if your OS does things differently from *nix or DOS - what differs?