diff options
author | Filipe David Manana <[email protected]> | 2010-04-22 23:40:26 +0100 |
---|---|---|
committer | Raimo Niskanen <[email protected]> | 2010-05-20 15:48:17 +0200 |
commit | 3f53a96a8bd0cd4a18f819b6857e6a764706ede5 (patch) | |
tree | 04841cd714a6e23ac664a05ff9219dd8e5da474e /lib/kernel/src/file.erl | |
parent | 80b231a0874aa5cd68c3d9f0dc7e13b6736a5dd3 (diff) | |
download | otp-3f53a96a8bd0cd4a18f819b6857e6a764706ede5.tar.gz otp-3f53a96a8bd0cd4a18f819b6857e6a764706ede5.tar.bz2 otp-3f53a96a8bd0cd4a18f819b6857e6a764706ede5.zip |
Add file:datasync/1 for syncing file contents only
file:datasync/1 invokes the POSIX system call "int fdatasync(int fd)".
This system call is similar to "fsync" but, unlike fsync, it does not
update the metadata associated with the file (like the access time for
example). It's used by many DBMSs (MySQL and SQLite of example) to
increase disk IO performance, as it avoids disk seeks and disk write
operations compared to fsync.
More details on it at:
http://linux.die.net/man/2/fdatasync
An example, from the MySQL source:
http://bazaar.launchpad.net/~mysql/mysql-server/mysql-5.1-telco-6.1/annotate/head%3A/mysys/my_sync.c#L61
This new function just calls fsync on systems not implementing fdatasync.
Diffstat (limited to 'lib/kernel/src/file.erl')
-rw-r--r-- | lib/kernel/src/file.erl | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl index 46ffa9d708..5da359fdf1 100644 --- a/lib/kernel/src/file.erl +++ b/lib/kernel/src/file.erl @@ -40,7 +40,7 @@ read/2, write/2, pread/2, pread/3, pwrite/2, pwrite/3, read_line/1, - position/2, truncate/1, sync/1, + position/2, truncate/1, datasync/1, sync/1, copy/2, copy/3]). %% High level operations -export([consult/1, path_consult/2]). @@ -472,6 +472,16 @@ pwrite(#file_descriptor{module = Module} = Handle, Offs, Bytes) -> pwrite(_, _, _) -> {error, badarg}. +-spec datasync(File :: io_device()) -> 'ok' | {'error', posix()}. + +datasync(File) when is_pid(File) -> + R = file_request(File, datasync), + wait_file_reply(File, R); +datasync(#file_descriptor{module = Module} = Handle) -> + Module:datasync(Handle); +datasync(_) -> + {error, badarg}. + -spec sync(File :: io_device()) -> 'ok' | {'error', posix()}. sync(File) when is_pid(File) -> |