istoreos: blockmount use busybox grep and sed

avoid unexpected result
This commit is contained in:
Liangbin Lian 2024-04-25 16:32:09 +08:00
parent 894f6f50db
commit 241801ea65
1 changed files with 15 additions and 15 deletions

View File

@ -6,16 +6,16 @@ DEVNAME=${1#/dev/}
getdisk() {
local DISK=$1
local path=`readlink /sys/block/$DISK`
local usb=`echo "$path" | grep -oE '/usb\d+/[^:]+'`
local usb=`echo "$path" | busybox grep -oE '/usb\d+/[^:]+'`
if [ -n "$usb" ]; then
usb=${usb##*/}
usb=${usb%%-1}
echo usb`echo "$usb" | sed 's/[-.]/_/g'`
echo usb`echo "$usb" | busybox sed 's/[-.]/_/g'`
return 0
fi
case "$DISK" in
mmcblk*)
echo "$path" | grep -oE '/mmc\d+/'
echo "$path" | busybox grep -oE '/mmc\d+/'
return 0
;;
nvme*)
@ -24,38 +24,38 @@ getdisk() {
;;
esac
# sata
local sata=`echo "$path" | grep -oE '/ata\d+/host\d+/target\d+:\d+'`
local sata=`echo "$path" | busybox grep -oE '/ata\d+/host\d+/target\d+:\d+'`
if [ -n "$sata" ]; then
sata=`echo "$sata" | sed -r 's#/ata(\d+)/host\d+/target\d+:(\d+)#sata\1.\2#'`
sata=`echo "$sata" | busybox sed -r 's#/ata(\d+)/host\d+/target\d+:(\d+)#sata\1.\2#'`
sata=${sata%%.0}
echo "/$sata/"
return 0
fi
# virtio
sata=`echo "$path" | grep -oE '/virtio\d+/host\d+/target\d+:\d+:\d+'`
sata=`echo "$path" | busybox grep -oE '/virtio\d+/host\d+/target\d+:\d+:\d+'`
if [ -n "$sata" ]; then
sata=`echo "$sata" | sed -r 's#/virtio(\d+)/host\d+/target\d+:\d+:(\d+)#vio\1.\2#'`
sata=`echo "$sata" | busybox sed -r 's#/virtio(\d+)/host\d+/target\d+:\d+:(\d+)#vio\1.\2#'`
sata=${sata%%.0}
echo "/$sata/"
return 0
fi
# sas
sata=`echo "$path" | grep -oE '/host\d+/port-\d+:\d+'`
sata=`echo "$path" | busybox grep -oE '/host\d+/port-\d+:\d+'`
if [ -n "$sata" ]; then
sata=`echo "$sata" | sed -r 's#/host(\d+)/port-\d+:(\d+)#sas\1.\2#'`
sata=`echo "$sata" | busybox sed -r 's#/host(\d+)/port-\d+:(\d+)#sas\1.\2#'`
sata=${sata%%.0}
echo "/$sata/"
return 0
fi
# scsi
sata=`echo "$path" | grep -oE '/host\d+/target\d+:\d+:\d+'`
sata=`echo "$path" | busybox grep -oE '/host\d+/target\d+:\d+:\d+'`
if [ -n "$sata" ]; then
sata=`echo "$sata" | sed -r 's#/host(\d+)/target\d+:\d+:(\d+)#scsi\1.\2#'`
sata=`echo "$sata" | busybox sed -r 's#/host(\d+)/target\d+:\d+:(\d+)#scsi\1.\2#'`
sata=${sata%%.0}
echo "/$sata/"
return 0
fi
echo "$path" | grep -oE '/host\d+/' | sed 's/host/sata/g'
echo "$path" | busybox grep -oE '/host\d+/' | busybox sed 's/host/sata/g'
return 0
}
@ -72,11 +72,11 @@ getphy() {
case "$DEVNAME" in
sd*)
getphy `echo "$DEVNAME" | sed -r 's/^(sd[a-z]+)([0-9]+)?$/\1 \2/g'` ;;
getphy `echo "$DEVNAME" | busybox sed -r 's/^(sd[a-z]+)([0-9]+)?$/\1 \2/g'` ;;
mmcblk*)
getphy `echo "$DEVNAME" | sed -r 's/^(mmcblk[0-9]+)(p([0-9]+))?$/\1 \3/g'` ;;
getphy `echo "$DEVNAME" | busybox sed -r 's/^(mmcblk[0-9]+)(p([0-9]+))?$/\1 \3/g'` ;;
nvme*)
getphy `echo "$DEVNAME" | sed -r 's/^(nvme[0-9]+n[0-9]+)(p([0-9]+))?$/\1 \3/g'` ;;
getphy `echo "$DEVNAME" | busybox sed -r 's/^(nvme[0-9]+n[0-9]+)(p([0-9]+))?$/\1 \3/g'` ;;
*)
exit 1;
esac