From: ptxdist2 <[email protected]>

pad() wasn't always padding the output file to the correct length. On
some machines dd wasn't reading full blocks which resulted in an
incorrectly padded file. pad() now makes one call to dd to write the
input file using conv=sync to pad to the nearest 512 byte boundry. Then
dd is called again if additional 512 byte '\0' blocks are needed to meet
the padding size.

Signed-off-by: George McCollister <[email protected]>
Tested-by: George McCollister <[email protected]>
---
 scripts/genhdimg |   14 +++++++++++++-
 1 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/scripts/genhdimg b/scripts/genhdimg
index 12a0281..490a43a 100755
--- a/scripts/genhdimg
+++ b/scripts/genhdimg
@@ -42,7 +42,19 @@ pad() {
                echo "warning: $from truncated. Need $fromsize bytes, but have 
only $(($blocks * 512))!"
        fi
 
-       cat $from /dev/zero | dd bs=512 count=$(($blocks)) >> "$to" 2>/dev/null
+       tosize=$(stat -c "%s" "$to")
+       toblocks_before=$(( $tosize / 512 ))
+
+       dd if="$from" bs=512 count=$blocks conv=sync >> "$to" 2> /dev/null
+
+       tosize=$(stat -c "%s" "$to")
+       toblocks=$(( $tosize / 512 ))
+
+       blocksleft=$(( $blocks - $toblocks + $toblocks_before ))
+
+       if [ $blocksleft -gt 0 ]; then
+               dd if=/dev/zero bs=512 count=$blocksleft >> "$to" 2>/dev/null
+       fi
 }
 
 
-- 
1.6.4.2


--
ptxdist mailing list
[email protected]

Reply via email to