fix to tomb resize

also included into test script
This commit is contained in:
Jaromil 2013-06-12 03:01:28 +02:00
parent 8f9e9f9d2a
commit bc3177141d
2 changed files with 40 additions and 45 deletions

View File

@ -1,48 +1,46 @@
#/usr/bin/env zsh #!/usr/bin/zsh
T="../../tomb" T="../../tomb"
source utils.sh source utils.sh
source ${T} source
notice() { print; yes "${@}"; print; }
error() { _warning " ${@}"; }
tt() {
start_loops=(`sudo losetup -a |cut -d: -f1`)
${T} ${=@}
res=$?
loops=(`sudo losetup -a |cut -d: -f1`)
{ test "${#start_loops}" = "${#loops}" } || { error "loop device limit change to ${#loops}" }
print " Tomb command returns $res"
return $res
}
rm /tmp/test.tomb{,.key} -f || exit 1 rm /tmp/test.tomb{,.key} -f || exit 1
sudo -k notice "Testing creation"
${T} dig -s 10 /tmp/test.tomb tt dig -s 10 /tmp/test.tomb
sudo losetup -a tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za --use-urandom forge /tmp/test.tomb.key
${T} --ignore-swap --unsecure-dev-mode --tomb-pwd f00za --use-urandom \
forge /tmp/test.tomb.key
sudo losetup -a tt --ignore-swap --unsecure-dev-mode --tomb-pwd f00za lock /tmp/test.tomb -k /tmp/test.tomb.key
${T} --ignore-swap --unsecure-dev-mode --tomb-pwd f00za \
lock /tmp/test.tomb -k /tmp/test.tomb.key
sudo losetup -a
# sanity_tomb /tmp/asd.tomb # sanity_tomb /tmp/asd.tomb
echo notice "Testing open with wrong password"
echo trying to open with wrong password
echo
${T} --unsecure-dev-mode --tomb-pwd wrongpassword \ tt --unsecure-dev-mode --tomb-pwd wrongpassword open /tmp/test.tomb
open /tmp/test.tomb
sudo losetup -a notice "Testing open with good password"
echo tt --unsecure-dev-mode --tomb-pwd f00za open /tmp/test.tomb
echo trying to open with good password
echo
${T} --unsecure-dev-mode --tomb-pwd f00za \ tt --unsecure-dev-mode close test
open /tmp/test.tomb
sudo losetup -a notice "Testing resize to 20MiB"
tt --unsecure-dev-mode --tomb-pwd f00za -k /tmp/test.tomb.key resize /tmp/test.tomb -s 20
${T} --unsecure-dev-mode close test
sudo losetup -a
rm /tmp/test.tomb{,.key} -f || exit 1
# rm /tmp/test.tomb{,.key} -f || exit 1

17
tomb
View File

@ -1648,7 +1648,7 @@ resize_tomb() {
local tmp_resize=`safe_filename tmbrsz` local tmp_resize=`safe_filename tmbrsz`
local newtombsize=$opts[-s] local newtombsize=$opts[-s]
local oldtombsize=`stat -c %s "$1" 2>/dev/null` local oldtombsize=$(( `stat -c %s "$1" 2>/dev/null` / 1048576 ))
local mounted_tomb=`mount -l | local mounted_tomb=`mount -l |
awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 }'` awk -vtomb="[$tombname]" '/^\/dev\/mapper\/tomb/ { if($7==tomb) print $1 }'`
@ -1656,9 +1656,6 @@ resize_tomb() {
_failure "the tomb $tombname is open, to resize it it needs to be close." _failure "the tomb $tombname is open, to resize it it needs to be close."
fi fi
# MB to bytes conversion
newtombsize=`expr \( $newtombsize \* 1024 \) \* 1024 2> /dev/null`
if ! [ "$newtombsize" ] ; then if ! [ "$newtombsize" ] ; then
_failure "You must specify the new size of $tombname" _failure "You must specify the new size of $tombname"
elif [[ $newtombsize != <-> ]]; then elif [[ $newtombsize != <-> ]]; then
@ -1667,12 +1664,12 @@ resize_tomb() {
_failure "the new size must be greater then old tomb size." _failure "the new size must be greater then old tomb size."
fi fi
local delta=`expr $newtombsize \- $oldtombsize` delta="$(( $newtombsize - $oldtombsize ))"
act "Generating ${tombfile} of ${newtombsize}MiB" act "Generating ${tombfile} of ${newtombsize}MiB"
xxx "Data dump using ${DD[1]} from /dev/urandom" xxx "Data dump using ${DD[1]} from /dev/urandom"
${=DD} if=/dev/urandom bs=1048576 count=${tombsize} of="${tmp_resize}" ${=DD} if=/dev/urandom bs=1048576 count=${delta} of="${tmp_resize}"
if [ $? = 0 -a -e "${tmp_resize}" ]; then if [ $? = 0 -a -e "${tmp_resize}" ]; then
xxx "OK: `ls -lh ${tmp_resize}`" xxx "OK: `ls -lh ${tmp_resize}`"
@ -1680,8 +1677,8 @@ resize_tomb() {
_failure "Error creating the extra resize $tmp_resize, operation aborted." _failure "Error creating the extra resize $tmp_resize, operation aborted."
fi fi
cat "${tmp_resize}" >> "$1" cat "${tmp_resize}" >> ${tombdir}/${tombfile}
${=WIPE} "${tmp_resize}" rm "${tmp_resize}"
tombpass=`ask_key_password $tombkey` tombpass=`ask_key_password $tombkey`
@ -1693,7 +1690,7 @@ resize_tomb() {
_failure "too many tomb opened. Please close any of them to open another tomb" _failure "too many tomb opened. Please close any of them to open another tomb"
fi fi
losetup -f "$1" losetup -f ${tombdir}/${tombfile}
local mapdate=`date +%s` local mapdate=`date +%s`
local mapper="tomb.${tombname}.${mapdate}.`basename $nstloop`" local mapper="tomb.${tombname}.${mapdate}.`basename $nstloop`"
@ -1919,7 +1916,7 @@ main() {
subcommands_opts[askpass]="" subcommands_opts[askpass]=""
subcommands_opts[mktemp]="" subcommands_opts[mktemp]=""
subcommands_opts[source]="" subcommands_opts[source]=""
subcommands_opts[resize]="s: -size=s k: -key=k" subcommands_opts[resize]="f -force -ignore-swap s: -size=s k: -key=k -tomb-pwd:"
subcommands_opts[check]="-ignore-swap" subcommands_opts[check]="-ignore-swap"
# subcommands_opts[translate]="" # subcommands_opts[translate]=""