summaryrefslogtreecommitdiff
path: root/functions/losetup.sh
diff options
context:
space:
mode:
authorLyndon Brown <jnqnfe@gmail.com>2020-02-20 06:58:11 +0000
committerLyndon Brown <jnqnfe@gmail.com>2020-03-16 22:10:03 +0000
commitc55eb8a0c3ca5b8ed1081e7eb8a423563288fb58 (patch)
tree6ea61f7291b27ce9e22b40c5593c6ab6f54555d2 /functions/losetup.sh
parentaf040d78035b88aaf2f99f38bf5f0db176c92d0a (diff)
downloadvyos-live-build-c55eb8a0c3ca5b8ed1081e7eb8a423563288fb58.tar.gz
vyos-live-build-c55eb8a0c3ca5b8ed1081e7eb8a423563288fb58.zip
use local scope for private function vars
all vars affected have been carefully checked to be quite certain that they are definitely local where variable is assigned the return value of a function/command, the local "declaration" is deliberately done on a separate line, since `local FOO` is actually treated itself as a command rather than a declaration; will thus always cause $? to be zero, and thus if done on the same line as such an assignment can not only clobber $? but in doing so unintentionally blocks failure of a command from triggering the expected exit from having `set -e`. also, from testing, i have found that when assigning "${@}" this must be done on a separate line confusingly as otherwise an error occurs. Gbp-Dch: Short
Diffstat (limited to 'functions/losetup.sh')
-rwxr-xr-xfunctions/losetup.sh30
1 files changed, 20 insertions, 10 deletions
diff --git a/functions/losetup.sh b/functions/losetup.sh
index c3dd59641..c91852f26 100755
--- a/functions/losetup.sh
+++ b/functions/losetup.sh
@@ -10,8 +10,8 @@
Lodetach ()
{
- DEVICE="${1}"
- ATTEMPT="${2:-1}"
+ local DEVICE="${1}"
+ local ATTEMPT="${2:-1}"
if [ "${ATTEMPT}" -gt 3 ]
then
@@ -37,10 +37,12 @@ Lodetach ()
Losetup ()
{
- DEVICE="${1}"
- FILE="${2}"
- PARTITION="${3:-1}"
+ local DEVICE="${1}"
+ local FILE="${2}"
+ local PARTITION="${3:-1}"
+ local FDISK_OUT
+ local LOOPDEVICE
losetup --read-only --partscan "${DEVICE}" "${FILE}"
FDISK_OUT="$(fdisk -l -u ${DEVICE} 2>&1)"
Lodetach "${DEVICE}"
@@ -53,6 +55,8 @@ Losetup ()
losetup --partscan "${DEVICE}" "${FILE}"
else
+ local SECTORS
+ local OFFSET
SECTORS="$(echo "$FDISK_OUT" | sed -ne "s|^$LOOPDEVICE[ *]*\([0-9]*\).*|\1|p")"
OFFSET="$(expr ${SECTORS} '*' 512)"
@@ -65,7 +69,7 @@ Losetup ()
# adapted from lib/ext2fs/mkjournal.c, default block size is 4096 bytes (/etc/mke2fs.conf).
ext2fs_default_journal_size()
{
- SIZE="$1"
+ local SIZE="$1"
if [ "${SIZE}" -lt "8" ]; then # 2048*4096
echo 0
elif [ "${SIZE}" -lt "128" ]; then # 32768*4096
@@ -83,9 +87,10 @@ ext2fs_default_journal_size()
Calculate_partition_size_without_journal ()
{
- WITHOUT_JOURNAL_ORIGINAL_SIZE="${1}"
- WITHOUT_JOURNAL_FILESYSTEM="${2}"
+ local WITHOUT_JOURNAL_ORIGINAL_SIZE="${1}"
+ local WITHOUT_JOURNAL_FILESYSTEM="${2}"
+ local PERCENT
case "${WITHOUT_JOURNAL_FILESYSTEM}" in
ext2|ext3|ext4)
PERCENT="6"
@@ -100,11 +105,16 @@ Calculate_partition_size_without_journal ()
Calculate_partition_size ()
{
- ORIGINAL_SIZE="${1}"
- FILESYSTEM="${2}"
+ local ORIGINAL_SIZE="${1}"
+ local FILESYSTEM="${2}"
case "${FILESYSTEM}" in
ext3|ext4)
+ local NON_JOURNAL_SIZE
+ local PROJECTED_JOURNAL_SIZE
+ local PROJECTED_PARTITION_SIZE
+ local PRE_FINAL_PARTITION_SIZE
+ local JOURNAL_SIZE
NON_JOURNAL_SIZE=$(Calculate_partition_size_without_journal ${ORIGINAL_SIZE} ${FILESYSTEM})
PROJECTED_JOURNAL_SIZE=$(ext2fs_default_journal_size ${NON_JOURNAL_SIZE})
PROJECTED_PARTITION_SIZE=$(expr ${ORIGINAL_SIZE} + ${PROJECTED_JOURNAL_SIZE})