New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature wish: Unix.fsync, etc. #2533
Comments
Comment author: @mmottl This has been around for a really long time. I think at least the following POSIX system calls concerning syncing should be supported: sync and fsync. They are available on virtually every Unix system and indispensable for applications that need persistence guarantees. Note that fdatasync is not supported on FreeBSD and Mac OS X. |
Comment author: @avsm fsync(2) is also more relaxed on MacOS X; it needs the F_FULLFSYNC fcntl to ensure it actually hits the disk in-order. |
Comment author: @mshinwell Markus, do you have a pre-existing patch for this (or could you construct one) which could be looked at? |
Comment author: @mmottl Yes, just take a look at our Core-library, file "unix_ext_stubs.c". It contains a function "unix_fsync" that can surely be taken verbatim. There are several other functions there that could probably be added to the OCaml distribution immediately, because they are well-standardized in POSIX and do not require elaborate API additions (types, etc.). E.g. pselect, abort, sync. Some of the others are also well-standardized, but would need extra types, etc. I'm not sure what the OCaml team's preferred procedure for adding those would be. |
Comment author: @mshinwell Damien, do you have an opinion on adding these? (I'm just asking given what you said about Set.map ...) |
Comment author: berenger I'm also surprised today by the lack of fsync in the stdlib's Unix module... |
Comment author: berenger https://github.com/janestreet/core/blob/f96a6f75611713b77b95c62568020f20d8f81ef7/src/unix_stubs.c contains:CAMLprim value unix_fsync(value v_fd)
|
Comment author: berenger |
Comment author: berenger the corresponding PR on github has been merged, so this issue can probably be closed |
Comment author: @nojb The PR only implements the fsync call, there seem to be others that are important by the previous discussion. But since this issue has been open for 14 years, I will go ahead and close it. If needed a new one can be opened for the other functions. |
Original bug ID: 2533
Reporter: administrator
Assigned to: @damiendoligez
Status: resolved (set by @nojb on 2018-07-31T11:41:11Z)
Resolution: fixed
Priority: normal
Severity: feature
Category: otherlibs
Tags: patch
Monitored by: @nojb mfp mehdi @ygrek @dbuenzli @mmottl
Bug description
Hi,
having to write a very filesystem-oriented system, I am in need of system
calls for synchronizing the in-core state of files and directories with
that on disk.
It would be nice to see the following easily implementable system calls
in the Unix-module (currently I'm working with extensions):
val fsync : file_descr -> unit
val fdatasync : file_descr -> unit
val dirfd : dir_handle -> file_descr
The last function (BSD, the other two are POSIX.1b) is needed, because
synchronizing data with fdatasync (and also metadata + data with fsync)
does not synchronize the directory entries as such. For this it is
necessary to extract the file descriptor from the directory stream and
explicitly call fsync on it.
If there are reasons not to exhibit the file_descr associated with a
dir_handle, a function "val dir_sync : dir_handle -> unit" would also
be a possibility.
It may be too inefficient to open files with every write being
synchronized (O_SYNC, etc.). Sometimes I even only want the directory
to be synchronized, not the data.
Best regards,
Markus
--
Markus Mottl http://www.oefai.at/~markus markus@oefai.at
The text was updated successfully, but these errors were encountered: