It seems obvious to me that we need a transactional filesystem API with methods like:
fbegin()
fwrite() / rename / etc
fcommit()
Most of the write calls wouldn't return errors directly. Then the fcommit() call would atomically flush the locally buffered changes to the filesystem. If an error happened, the API should guarantee that the final state either contains all changes or none of them. The commit call should either block the thread until changes are safely stored on disk, or use a completion callback. This API probably couldn't span multiple filesystems, but thats fine in practice. And bonus points if the API supports snapshot reads within the transaction.This would dramatically simplify the code in every program that wants to safely interact with the filesystem. And it would remove the perennial, justified anxiety database engineers carry that they're doing something subtly wrong without even knowing. Because fsync() is so coarse, I suspect performance would improve with this API, too. (So long as the transactions are mostly small.)
But why don't we have this API already? My theory is that kernel developers don't write enough userspace software to understand how bad the status quo is. And most people writing software in userland don't understand the kernel well enough to feel empowered to change it. Adding an API like this might also need changes in the filesystems.
But wow, it would be a huge boon to humanity to have a filesystem API which isn't so braindead. How many more decades do we need to have our files corrupt by default when errors happen? I wince every time I'm playing a video game and it has that "saving - don't turn off your console!" animation. Or during OS updates. Data corruption happens because we implemented the wrong abstractions 50 years ago and somehow forgot that code is mutable.