Support for creating and writing files was pretty much finished on the weekend, but my power test of copying the entire system to a FAT partition would cause things to explode in myriad ways, but not until a few hundred files has been copied. I've spent this week tracking down and fixes these problems:
- There was some problems in my linked-list managment code inside the cache which would occassionally cause an infinite loop.
- A different bug in the same code would sometimes cause a segfault as a NULL pointer was dereferenced.
- Following that, I noticed that something was leaking cache blocks. I implemented a function that dumps the internal cache state including block use counts after every FAT operation. The usage wasn't coming down properly when create directory entries (ie making a directory or new file). Turns out I wasn't releasing a directory handle when finished.
- Next, writing file contents was leaking blocks too. Again, I wasn't releasing a directory handle when updating the file size in the directory.
- Finally, I skimmed through and found a number of other places in error handling code where directory handles weren't being released.
So, I'm pleased to announce that file writing is stable. I haven't seen any corruption in my testing, but obviously take care on real data (like your Windows 98 partition). As I noted previously, there's still a few little things left to implement to declare write "done", but for the most part you won't care ;)