1344d416d2
This is a compromise on consistency and not breaking expected invariants. The problem: rdonly files can become unsynced: 1. file is opened rdonly + desync 2. the same file is opened and written to 3. we try to sync our original file handle What we want: 1. sync should ensure disk + files are in-sync 2. rdonly implies sync should not write to disk Without desync, and in other systems, this is not a problem, because rdonly files can never become unsynced. But with desync, a state (albiet a roundabout one) can be reached where we can't satisfy both of these invariants. I wanted to just assert on syncing a rdonly file, but this is supported on POSIX and other systems, and it makes sense that you would want to unconditionally call sync in certain circumstances (ensuring close can't write to disk for example). So adopts the approach of allowing flush and sync on rdonly files when possible, and when not possible, sync simply returns LFS_ERR_INVAL and makes it the user's problem. For the above example, this has the side effect of making the rdonly file desync again, so close can complete without touching disk. As a plus, a desynced rdonly file can now be used to test if a file has been written to. Though I'm not sure when this would be useful... Or if it's a good idea to suggest this use of the API...