File 0535-Change-efile_allocate-in-Linux-to-change-file-size.patch of Package erlang
From 49395ed9c10dfa8b4583d688e088994cc49d2e98 Mon Sep 17 00:00:00 2001
From: Julius Putra Tanu Setiaji <indocomsoft@gmail.com>
Date: Wed, 2 Oct 2019 10:30:01 +0800
Subject: [PATCH] Change efile_allocate in Linux to change file size
Skip allocate_file_size test if allocate is not supported
---
erts/emulator/nifs/unix/unix_prim_file.c | 2 +-
lib/kernel/doc/src/file.xml | 5 +----
lib/kernel/test/file_SUITE.erl | 31 ++++++++++++++++++++-----------
3 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/erts/emulator/nifs/unix/unix_prim_file.c b/erts/emulator/nifs/unix/unix_prim_file.c
index e5099dd921..e6ddaa3479 100644
--- a/erts/emulator/nifs/unix/unix_prim_file.c
+++ b/erts/emulator/nifs/unix/unix_prim_file.c
@@ -562,7 +562,7 @@ int efile_allocate(efile_data_t *d, Sint64 offset, Sint64 length) {
#if defined(HAVE_FALLOCATE)
/* Linux-specific */
do {
- ret = fallocate(u->fd, FALLOC_FL_KEEP_SIZE, offset, length);
+ ret = fallocate(u->fd, 0, offset, length);
} while(ret < 0 && errno == EINTR);
#elif defined(F_PREALLOCATE)
/* Mac-specific */
diff --git a/lib/kernel/doc/src/file.xml b/lib/kernel/doc/src/file.xml
index 2c09c84b25..c4073f13a2 100644
--- a/lib/kernel/doc/src/file.xml
+++ b/lib/kernel/doc/src/file.xml
@@ -202,10 +202,7 @@
<desc>
<p><c>allocate/3</c> can be used to preallocate space for a file.</p>
<p>This function only succeeds in platforms that provide this
- feature. When it succeeds, space is preallocated for the file but
- the file size might not be updated. This behaviour depends on the
- preallocation implementation. To guarantee that the file size is updated,
- truncate the file to the new size.</p>
+ feature.</p>
</desc>
</func>
<func>
diff --git a/lib/kernel/test/file_SUITE.erl b/lib/kernel/test/file_SUITE.erl
index e4299cd346..f432eec708 100644
--- a/lib/kernel/test/file_SUITE.erl
+++ b/lib/kernel/test/file_SUITE.erl
@@ -2233,24 +2233,33 @@ allocate_and_assert(Fd, Offset, Length) ->
allocate_file_size(Config) when is_list(Config) ->
case os:type() of
{unix, darwin} ->
- PrivDir = proplists:get_value(priv_dir, Config),
- Allocate = filename:join(PrivDir, atom_to_list(?MODULE)++"_allocate_file"),
-
- {ok, Fd} = ?FILE_MODULE:open(Allocate, [write]),
- ok = ?FILE_MODULE:allocate(Fd, 0, 1024),
- {ok, 1024} = ?FILE_MODULE:position(Fd, eof),
- ok = ?FILE_MODULE:close(Fd),
-
- [] = flush(),
- ok;
+ do_allocate_file_size(Config);
{unix, linux} ->
- {skip, "file:allocate/3 on Linux does not change file size"};
+ do_allocate_file_size(Config);
{win32, _} ->
{skip, "Windows does not support file:allocate/3"};
_ ->
{skip, "Support for allocate/3 is spotty in our test platform at the moment."}
end.
+do_allocate_file_size(Config) when is_list(Config) ->
+ PrivDir = proplists:get_value(priv_dir, Config),
+ Allocate = filename:join(PrivDir, atom_to_list(?MODULE)++"_allocate_file"),
+
+ {ok, Fd} = ?FILE_MODULE:open(Allocate, [write]),
+ Result =
+ case ?FILE_MODULE:allocate(Fd, 0, 1024) of
+ ok ->
+ {ok, 1024} = ?FILE_MODULE:position(Fd, eof),
+ ok;
+ {error, enotsup} ->
+ {skip, "Filesystem does not support file:allocate/3"}
+ end,
+ ok = ?FILE_MODULE:close(Fd),
+
+ [] = flush(),
+ Result.
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
delete(Config) when is_list(Config) ->
--
2.16.4