diff options
author | Erlang/OTP <[email protected]> | 2010-06-07 14:24:46 +0000 |
---|---|---|
committer | Erlang/OTP <[email protected]> | 2010-06-07 14:24:46 +0000 |
commit | 3e97f3dc6ad63707d283e7b9924df5cc8eb13a84 (patch) | |
tree | 0e66d4f9eeb04605fde8089332bd38aed8fdc653 /erts | |
parent | 4f63a79d28435659af11fa94ed93f670a6759f4a (diff) | |
parent | bac96ae5bb5bfaa0c160a603c6db01dbcd7c83df (diff) | |
download | otp-3e97f3dc6ad63707d283e7b9924df5cc8eb13a84.tar.gz otp-3e97f3dc6ad63707d283e7b9924df5cc8eb13a84.tar.bz2 otp-3e97f3dc6ad63707d283e7b9924df5cc8eb13a84.zip |
Merge branch 'ms/file-exclusive-mode' into dev
* ms/file-exclusive-mode:
Update preloaded modules
Support opening files in exclusive mode
OTP-8670 ms/file-exclusive-mode
There is a new option 'exclusive' to file:open/2 that uses the OS O_EXCL
flag where supported to open the file in exclusive mode.
Diffstat (limited to 'erts')
-rw-r--r-- | erts/emulator/drivers/common/erl_efile.h | 3 | ||||
-rw-r--r-- | erts/emulator/drivers/unix/unix_efile.c | 3 | ||||
-rw-r--r-- | erts/emulator/drivers/win32/win_efile.c | 3 | ||||
-rw-r--r-- | erts/preloaded/ebin/prim_file.beam | bin | 30452 -> 30548 bytes | |||
-rw-r--r-- | erts/preloaded/src/prim_file.erl | 5 |
5 files changed, 12 insertions, 2 deletions
diff --git a/erts/emulator/drivers/common/erl_efile.h b/erts/emulator/drivers/common/erl_efile.h index bbc973d58b..ac95c1f949 100644 --- a/erts/emulator/drivers/common/erl_efile.h +++ b/erts/emulator/drivers/common/erl_efile.h @@ -32,7 +32,8 @@ #define EFILE_MODE_READ_WRITE 3 #define EFILE_MODE_APPEND 4 #define EFILE_COMPRESSED 8 -#define EFILE_NO_TRUNCATE 16 /* Special for reopening on VxWorks */ +#define EFILE_MODE_EXCL 16 +#define EFILE_NO_TRUNCATE 32 /* Special for reopening on VxWorks */ /* * Seek modes for efile_seek(). diff --git a/erts/emulator/drivers/unix/unix_efile.c b/erts/emulator/drivers/unix/unix_efile.c index ea016526ef..0052ac0739 100644 --- a/erts/emulator/drivers/unix/unix_efile.c +++ b/erts/emulator/drivers/unix/unix_efile.c @@ -706,6 +706,9 @@ efile_openfile(Efile_error* errInfo, /* Where to return error codes. */ #endif } + if (flags & EFILE_MODE_EXCL) { + mode |= O_EXCL; + } #ifdef VXWORKS if (*name != '/') { diff --git a/erts/emulator/drivers/win32/win_efile.c b/erts/emulator/drivers/win32/win_efile.c index 24b6fb30dc..04bd1139f5 100644 --- a/erts/emulator/drivers/win32/win_efile.c +++ b/erts/emulator/drivers/win32/win_efile.c @@ -689,6 +689,9 @@ Sint64* pSize; /* Where to store the size of the file. */ if (flags & EFILE_MODE_APPEND) { crFlags = OPEN_ALWAYS; } + if (flags & EFILE_MODE_EXCL) { + crFlags = CREATE_NEW; + } fd = CreateFile(name, access, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, crFlags, FILE_ATTRIBUTE_NORMAL, NULL); diff --git a/erts/preloaded/ebin/prim_file.beam b/erts/preloaded/ebin/prim_file.beam Binary files differindex d39d2d1135..7e99523527 100644 --- a/erts/preloaded/ebin/prim_file.beam +++ b/erts/preloaded/ebin/prim_file.beam diff --git a/erts/preloaded/src/prim_file.erl b/erts/preloaded/src/prim_file.erl index 2d177bf80e..7f24889bb2 100644 --- a/erts/preloaded/src/prim_file.erl +++ b/erts/preloaded/src/prim_file.erl @@ -116,9 +116,10 @@ -define(EFILE_MODE_READ_WRITE, 3). -define(EFILE_MODE_APPEND, 4). -define(EFILE_COMPRESSED, 8). +-define(EFILE_MODE_EXCL, 16). %% Use this mask to get just the mode bits to be passed to the driver. --define(EFILE_MODE_MASK, 15). +-define(EFILE_MODE_MASK, 31). %% Seek modes for the driver's seek function. -define(EFILE_SEEK_SET, 0). @@ -958,6 +959,8 @@ open_mode([compressed|Rest], Mode, Portopts, Setopts) -> open_mode([append|Rest], Mode, Portopts, Setopts) -> open_mode(Rest, Mode bor ?EFILE_MODE_APPEND bor ?EFILE_MODE_WRITE, Portopts, Setopts); +open_mode([exclusive|Rest], Mode, Portopts, Setopts) -> + open_mode(Rest, Mode bor ?EFILE_MODE_EXCL, Portopts, Setopts); open_mode([delayed_write|Rest], Mode, Portopts, Setopts) -> open_mode([{delayed_write, 64*1024, 2000}|Rest], Mode, Portopts, Setopts); |