Browse Source

Added check to be sure that device is a disk and not some other kind of block device

Matteo Zeccoli Marazzini 5 years ago
parent
commit
d30fbddc36
2 changed files with 6 additions and 0 deletions
  1. 5 0
      check-device.sh
  2. 1 0
      error.sh

+ 5 - 0
check-device.sh

@@ -8,6 +8,11 @@ check_device()
 	if [ ! -b ${DEVICE} ] ; then
 		fatal ${NOTBLK_E} "${DEVICE} is not a block file"
 	fi
+	MAJOR=$(echo $(mountpoint --devno "${DEVICE}") | awk -F: '{print $1}')
+	MINOR=$(echo $(mountpoint --devno "${DEVICE}") | awk -F: '{print $2}')
+	if [ $MAJOR -ne 254 ] && [ $MAJOR -ne 8 ] || [ $(($MINOR % 16)) -ne 0 ]; then  
+		fatal ${WRONGBLK_E} "${DEVICE} is not a regular disk"
+	fi
 	if grep --quiet "${DEVICE}" /proc/mounts ; then
 		fatal ${ISMOUNT_E} "${DEVICE} is mounted"
 	fi

+ 1 - 0
error.sh

@@ -10,6 +10,7 @@ ISMOUNT_E=3
 ISSWAP_E=4
 LVMUSED_E=5
 LVMPV_E=6
+WRONGBLK_E=15
 
 # size errors
 MINSIZE_E=10