On 02/13/2012 06:41 PM, Jérémy Compostella wrote:
> Pádraig,
> 
> I took a closer look to the last test case. I wrote it during the
> development phase. At this time, I forced the skip() function to failed
> in order to test the line 1896 algorithm.
> 
> I just made some test and was unable to make the lseek() call failed on
> my system. So I guess we could remove this last test case. Except if
> someone have a good idea to easily make this call failed.

Ok I replaced that test with one checking the truncate functionality.

I've pushed the attached.

cheers,
Pádraig.
>From 4bb5dbcfef55c4f66755dd3c48b906e4e9030b96 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C3=A1draig=20Brady?= <p...@draigbrady.com>
Date: Mon, 13 Feb 2012 21:47:28 +0000
Subject: [PATCH] dd: fix issues in the count_bytes and seek_bytes flags
 change

These edge cases were missed in the previous commit 140eca15c.

* src/dd.c (main): Include the bytes slop when truncating
without further I/O.  Don't invalidate the whole file cache
in the case where 0 < count < ibs.
* tests/dd/bytes: Change to using the independent truncate
command to generate the file for comparison.  Remove a redundant
test case and replace with one testing the truncation only logic.
---
 src/dd.c       |    8 ++++----
 tests/dd/bytes |   11 +++++------
 2 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/src/dd.c b/src/dd.c
index e7f4037..fe44a30 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -1917,7 +1917,7 @@ dd_copy (void)
 
   while (1)
     {
-      if (r_partial + r_full >= max_records + (max_bytes ? 1 : 0))
+      if (r_partial + r_full >= max_records + !!max_bytes)
         break;
 
       /* Zero the buffer before reading, so that if we get a read error,
@@ -2170,7 +2170,7 @@ main (int argc, char **argv)
 
       if (seek_records != 0 && !(conversions_mask & C_NOTRUNC))
         {
-          uintmax_t size = seek_records * output_blocksize;
+          uintmax_t size = seek_records * output_blocksize + seek_bytes;
           unsigned long int obs = output_blocksize;
 
           if (OFF_T_MAX / output_blocksize < seek_records)
@@ -2207,7 +2207,7 @@ main (int argc, char **argv)
 
   exit_status = dd_copy ();
 
-  if (max_records == 0)
+  if (max_records == 0 && max_bytes == 0)
     {
       /* Special case to invalidate cache to end of file.  */
       if (i_nocache && !invalidate_cache (STDIN_FILENO, 0))
@@ -2225,7 +2225,7 @@ main (int argc, char **argv)
     }
   else if (max_records != (uintmax_t) -1)
     {
-      /* Invalidate any pending region less that page size,
+      /* Invalidate any pending region less than page size,
          in case the kernel might round up.  */
       if (i_nocache)
         invalidate_cache (STDIN_FILENO, 0);
diff --git a/tests/dd/bytes b/tests/dd/bytes
index 6038742..15755aa 100755
--- a/tests/dd/bytes
+++ b/tests/dd/bytes
@@ -45,13 +45,12 @@ esac
 # seek bytes
 echo abcdefghijklm |
  dd bs=5 seek=8 oflag=seek_bytes > out 2> /dev/null || fail=1
-echo abcdefghijklm |
- dd bs=4 seek=2 > expected 2> /dev/null || fail=1
+printf '\0\0\0\0\0\0\0\0abcdefghijklm\n' > expected
 compare expected out || fail=1
 
-# seek bytes on empty file
-echo abcdefghijklm |
- dd bs=5 seek=8 oflag=seek_bytes > out2 2> /dev/null || fail=1
-compare expected out2 || fail=1
+# Just truncation, no I/O
+dd bs=5 seek=8 oflag=seek_bytes of=out2 count=0 2> /dev/null || fail=1
+truncate -s8 expected2
+compare expected2 out2 || fail=1
 
 Exit $fail
-- 
1.7.6.4

Reply via email to