You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original reporter: JIRAUSER15707
Affected version: OTP-22.0
Fixed in version: OTP-24.0
Component: kernel
Migrated from: https://bugs.erlang.org/browse/ERL-1298
When opening a file with both "ram" and "raw" modes I expect to open a ram file that is interfaced through a file descriptor (hence "raw") instead of via a process, but instead of a ram file what is opened is a disk file; that is, the "ram" mode is simply ignored.
For example, the following code opens the file named "hello" on disk instead of ram, and writes " world" to it,
{code:java}
Erlang/OTP 22 [erts-10.7.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Eshell V10.7.1 (abort with ^G)
1> {ok, File} = file:open(<<"hello">>, [ram, raw, write, read]).
{ok,{file_descriptor,raw_file_io_list,
{file_descriptor,prim_file,
#{handle => #Ref<0.708897726.1743126542.99290>,
owner => <0.80.0>,r_ahead_size => 0,
r_buffer => #Ref<0.708897726.1743126530.99559>}}}}
2> file:position(File, eof).
{ok,36}
3> file:write(File, <<" world">>).
ok
4> {ok, Size} = file:position(File, eof).
{ok,42}
5> file:position(File, bof).
{ok,0}
6> {ok, Bytes} = file:read(File, Size).
{ok," world"}
7> file:close(File).
ok
8>{code}
My expectation was to see Bytes taking the value of "hello world" not " world", and for no disk file to be created.
In the next snippet, observe how the just created file e opened again and grows:
{code:java}
Erlang/OTP 22 [erts-10.7.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Eshell V10.7.1 (abort with ^G)
1> {ok, File} = file:open(<<"hello">>, [ram, raw, write, read]).
{ok,{file_descriptor,raw_file_io_list,
{file_descriptor,prim_file,
#{handle => #Ref<0.1917879854.3013476362.109932>,
owner => <0.80.0>,r_ahead_size => 0,
r_buffer => #Ref<0.1917879854.3013476354.110173>}}}}
2> file:position(File, eof).
{ok,12}
3> file:write(File, <<" world">>).
ok
4> {ok, Size} = file:position(File, eof).
{ok,18}
5> file:position(File, bof).
{ok,0}
6> {ok, Bytes} = file:read(File, Size).
{ok," world world"}
7> file:close(File).
ok
8>
{code}
I am not clear if this is a bug or an undocumented limitation of "file:open" function, so either the codebase must be fixed to support both modes simultaneously or the documentation should take note of this limitation.
Thanks.
The text was updated successfully, but these errors were encountered:
"ram" and "raw" modes are exclusive. What is happening here is that, if both are given, "raw" always wins, as you can see here: [https://github.com/erlang/otp/blob/eaab8962c2f75a286f8e36d278613e308ec7e4bc/lib/kernel/src/file.erl#L518]
Perhaps a clause should be added to raise if both are given, but that could be seen as a breaking change. If that's the case, documenting if both raw and ram is given, raw "wins".
I will be glad to submit a PR either way.
Original reporter:
JIRAUSER15707
Affected version:
OTP-22.0
Fixed in version:
OTP-24.0
Component:
kernel
Migrated from: https://bugs.erlang.org/browse/ERL-1298
The text was updated successfully, but these errors were encountered: