Ethin wrote:
rdos wrote:
Ethin wrote:
This is exactly what I was trying to say. Don't implement a cache when your just trying to read/write to disk. Once you've got an FS and partition layer in place, then worry about caching.
That's an pretty inefficient method since it means you quite likely will need to do major updates to the disc drivers (and partition & FS handling) since you were lazy to begin with and didn't plan the design. Both the disc cache and the VFS interface comes before doing anything FS related or partition related.
By this logic, one should completely design all their paging structures and their virtual memory manager before even beginning to learn the basics of OSDev. Oh, and they should also learn how to update CPU microcode and design a complete USB stack too. Even though they're just starting to learn the basics.
In other words, this is a pretty ridiculous idea unless your designing this OS professionally. But if your just starting out with aHCI or NVMe or IDE, implementing an LRU cache (for example) is overkill. A good idea, perhaps, but unnecessary baggage when your just learning how all the parts fit together and your just trying to read and write some data.
If I'm putting down a lot of time on something, then I certainly want it to be of professional quality. Why else would I bother? Just modifying some tutorial, or doing a new Linux distro is completely uninsteresting IMHO. Then I wouldn't be doing anything significant that has some use.
Besides, I didn't claim you needed to write all of that before doing a disc driver, only to consider how it would best operate with a cache. The difference is not big, and it won't take much longer to use a sector interface & aligned physical addresses instead of using a "int 0x13" type of interface. Actually, for AHCI and NVMe it's easier to write a driver that use aligned physical addresses than to write an interface that takes (a potentially) unaligned linear address.
When the disc driver is operational, you logically should write the disc cache function. That's because you want to use the disc cache interface for everything rather than accessing the physical disc directly. If you don't do it in that order, you will need to modify calls to the disc when you want to add the cache, and so adding the cache at the end is a bad idea since an efficient disc interface must have it and it takes more time when you need to rewrite stuff.
As for the VFS, if you start coding your FS directly against your physical disc, then you will need to rewrite even more when you decide you need an VFS, and so you should start with the VFS, defining your interface, and then write the functions for the FS you want to start with. Also note that you don't need to implement or define the comlete VFS before you code anything on FSes. As soon as you have defined a VFS function, you then can code it in the FS you are using.