File: pad

package info (click to toggle)
debian-installer 20150422
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 5,008 kB
  • sloc: xml: 10,107; sh: 1,960; makefile: 948; perl: 613; awk: 100
file content (21 lines) | stat: -rwxr-xr-x 413 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh

FILE=$1
SIZE=$2

if [ -z "$FILE" ]; then
	echo "Usage: "pad FILE SIZE""
	exit 1
fi

fsize=$(wc -c $FILE | cut -d " " -f 1)
pad=$(expr $SIZE - $fsize)
if [ $pad -lt 0 ]; then
	echo "File size $fsize is larger than total, padded size $SIZE."
	exit 1
fi
echo "Padding $FILE from $fsize to $SIZE... padding with $pad bytes"
if [ $pad -gt 0 ]; then
	dd if=/dev/zero bs=$pad count=1 2>/dev/null >> $FILE
fi