bug-cpio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 7/8] ensure uniform post-trailer-zeros length


From: David Disseldorp
Subject: [PATCH 7/8] ensure uniform post-trailer-zeros length
Date: Fri, 12 Mar 2021 02:30:18 +0100

After the trailer entry, copy-out currently writes out zeros up to the
next block boundary. When reflink is enabled, writes may be unbuffered.
To ensure that the post-trailer-zeros length matches with and without
reflink_flag, calculate the zeros length based on where the I/O buffer
offset would be instead of where it currently is.

Signed-off-by: David Disseldorp <ddiss@suse.de>
---
 src/copyout.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/copyout.c b/src/copyout.c
index 076478e..48ba6a9 100644
--- a/src/copyout.c
+++ b/src/copyout.c
@@ -63,13 +63,17 @@ read_for_checksum (int in_file_des, int file_size, char 
*file_name)
 }
 
 /* Write out NULs to fill out the rest of the current block on
-   OUT_FILE_DES.  */
+   OUT_FILE_DES.  With reflink_flag, I/O may not have been buffered.  To ensure
+   that the post-trailer-zeros length matches with and without reflink_flag,
+   calculate the length based on where the I/O buffer offset would be.  */
 
 static void
 tape_clear_rest_of_block (int out_file_des)
 {
-  write_nuls_to_file (io_block_size - output_size, out_file_des, 
-                      tape_buffered_write);
+  off_t boff = (output_bytes + output_size) % io_block_size;
+  if (boff)
+    write_nuls_to_file (io_block_size - boff, out_file_des,
+                       tape_buffered_write);
 }
 
 /* Write NULs on OUT_FILE_DES to move from OFFSET (the current location)
-- 
2.26.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]