unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] sysdeps/posix/posix_fallocate*: Make emulated posix_fallocate() work properly
@ 2020-01-14 12:53 Xiao Yang
  2020-01-15  1:12 ` Xiao Yang
  0 siblings, 1 reply; 2+ messages in thread
From: Xiao Yang @ 2020-01-14 12:53 UTC (permalink / raw)
  To: libc-alpha; +Cc: Xiao Yang

Emulated posix_fallocate() only writes data in one block if block
size is 4096, offset is 4095 and len is 2.  The emulated code should
write data in two blocks in the case because it actually crosses two
blocks.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
---
 sysdeps/posix/posix_fallocate.c   | 14 ++++++++++++++
 sysdeps/posix/posix_fallocate64.c | 14 ++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/sysdeps/posix/posix_fallocate.c b/sysdeps/posix/posix_fallocate.c
index e7fccfc1c8..f661124c0f 100644
--- a/sysdeps/posix/posix_fallocate.c
+++ b/sysdeps/posix/posix_fallocate.c
@@ -93,6 +93,20 @@ posix_fallocate (int fd, __off_t offset, __off_t len)
       increment = 4096;
   }
 
+  if (offset % increment + len % increment > increment)
+    {
+      if (offset < st.st_size)
+        {
+          unsigned char b;
+          ssize_t rdsize = __pread (fd, &b, 1, offset);
+          if (rdsize < 0)
+            return errno;
+        } else {
+          if (__pwrite (fd, "", 1, offset) != 1)
+            return errno;
+        }
+    }
+
   /* Write a null byte to every block.  This is racy; we currently
      lack a better option.  Compare-and-swap against a file mapping
      might additional local races, but requires interposition of a
diff --git a/sysdeps/posix/posix_fallocate64.c b/sysdeps/posix/posix_fallocate64.c
index f9d4fe5ca3..2d75ce2786 100644
--- a/sysdeps/posix/posix_fallocate64.c
+++ b/sysdeps/posix/posix_fallocate64.c
@@ -93,6 +93,20 @@ __posix_fallocate64_l64 (int fd, __off64_t offset, __off64_t len)
       increment = 4096;
   }
 
+  if (offset % increment + len % increment > increment)
+    {
+      if (offset < st.st_size)
+        {
+          unsigned char b;
+          ssize_t rdsize = __pread (fd, &b, 1, offset);
+          if (rdsize < 0)
+            return errno;
+        } else {
+          if (__pwrite (fd, "", 1, offset) != 1)
+            return errno;
+        }
+    }
+
   /* Write a null byte to every block.  This is racy; we currently
      lack a better option.  Compare-and-swap against a file mapping
      might address local races, but requires interposition of a signal
-- 
2.21.0




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] sysdeps/posix/posix_fallocate*: Make emulated posix_fallocate() work properly
  2020-01-14 12:53 [PATCH] sysdeps/posix/posix_fallocate*: Make emulated posix_fallocate() work properly Xiao Yang
@ 2020-01-15  1:12 ` Xiao Yang
  0 siblings, 0 replies; 2+ messages in thread
From: Xiao Yang @ 2020-01-15  1:12 UTC (permalink / raw)
  To: Xiao Yang; +Cc: libc-alpha

On 2020/1/14 20:53, Xiao Yang wrote:
> Emulated posix_fallocate() only writes data in one block if block
> size is 4096, offset is 4095 and len is 2.  The emulated code should
> write data in two blocks in the case because it actually crosses two
> blocks.
> 
Hi,

Please ignore this patch because there are some issues on it.
I will send v2 patch shortly.

Thanks,
Xiao Yang



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-15  1:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14 12:53 [PATCH] sysdeps/posix/posix_fallocate*: Make emulated posix_fallocate() work properly Xiao Yang
2020-01-15  1:12 ` Xiao Yang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).