Browse Source

Added check ti verify that the size passed is multiple of 512 bytes

Matteo Zeccoli Marazzini 5 years ago
parent
commit
f630021e73
3 changed files with 7 additions and 2 deletions
  1. 2 1
      error.sh
  2. 3 0
      parse-arguments.sh
  3. 2 1
      utils.sh

+ 2 - 1
error.sh

@@ -1,5 +1,7 @@
 # arguments errors
 USAGE_E=10
+UNIT_E=13
+CHUNK_E=14
 
 # device errors
 NOTEX_E=1
@@ -13,7 +15,6 @@ LVMPV_E=6
 MINSIZE_E=10
 BESTSIZE_E=11
 MANUALSIZE_E=12
-UNIT_E=13
 
 fatal()
 {

+ 3 - 0
parse-arguments.sh

@@ -44,6 +44,9 @@ default()
 manual()
 {
 	TEMP_SIZE=$(to_bytes $2)
+	if [ $(($TEMP_SIZE % 512)) -ne 0 ] ; then
+		fatal ${CHUNK_E} "size must be multiple of 512 bytes"
+	fi
 	CONDOR_SIZE=$(to_bytes $3)
 	SWAP_SIZE=$(to_bytes $4)
 	VM_SIZE=$(to_bytes $5)

+ 2 - 1
utils.sh

@@ -21,7 +21,8 @@ bytes_to_gibibytes()
 to_bytes()
 {
 	case "${1: -1}" in
-	b | [0-9]) echo "${1:0: -1}" ;;
+	b) echo "${1:0: -1}" ;;
+	[0-9]) echo "${1}" ;;
 	K) kibibytes_to_bytes "${1:0: -1}" ;;
 	M) mebibytes_to_bytes "${1:0: -1}" ;;
 	G) gibibytes_to_bytes "${1:0: -1}" ;;