GNOME Bugzilla – Bug 631061
GMappedFile should be able to sync data back to file
Last modified: 2010-10-01 14:13:01 UTC
I am trying to use MappedFile from Vala language and found that there is no easy mutiplatform way to flush modified data back to disk. Vala uses glib so this issue applicable to glib also. I checked g_mapped_file_destroy function and found that is uses munmap, but not msync. I might be wrong but i think there should be 2 changes: 1) Add a method something like g_mapped_file_sync(GMappedFile *file, gboolean sync = true) that allows to write modified data back to disk. 2) Call the method (1) in g_mapped_file_destroy function. Let me know what do you think.
GMappedFile is a strictly read-only mapping. The 'writable' flag may be what is confusing here, but see the docs: If writable is TRUE, the mapped buffer may be modified, otherwise it is an error to modify the mapped buffer. Modifications to the buffer are not visible to other processes mapping the same file, and are not written back to the file. All that is happening here is that the file is being opened copy-on-write so that local modifications can be made (similar to how the static data region of a mmaped program can be modified without other instances of the program seeing the modification). Calling sync() would do absolutely nothing here... What I think you want is a method to map the file with MAP_SHARED. See bug 458796 for that. *** This bug has been marked as a duplicate of bug 458796 ***