add support for nbd device (PR #746)

This commit is contained in:
longpanda 2021-02-18 09:43:27 +08:00
parent 3541735796
commit 82977d9b8a
8 changed files with 10 additions and 8 deletions

View File

@ -36,7 +36,7 @@ if [ "$vtdiskname" = "unknown" ]; then
exit 0 exit 0
fi fi
if echo $vtdiskname | egrep -q "nvme.*p[0-9]$|mmc.*p[0-9]$"; then if echo $vtdiskname | egrep -q "nvme.*p[0-9]$|mmc.*p[0-9]$|nbd.*p[0-9]$"; then
vPart="${vtdiskname}p2" vPart="${vtdiskname}p2"
else else
vPart="${vtdiskname}2" vPart="${vtdiskname}2"

View File

@ -87,7 +87,7 @@ wait_for_usb_disk_ready() {
usb_disk=$(get_ventoy_disk_name) usb_disk=$(get_ventoy_disk_name)
vtlog "wait_for_usb_disk_ready $usb_disk ..." vtlog "wait_for_usb_disk_ready $usb_disk ..."
if echo $usb_disk | $EGREP -q "nvme|mmc"; then if echo $usb_disk | $EGREP -q "nvme|mmc|nbd"; then
vtpart2=${usb_disk}p2 vtpart2=${usb_disk}p2
else else
vtpart2=${usb_disk}2 vtpart2=${usb_disk}2
@ -103,7 +103,7 @@ wait_for_usb_disk_ready() {
} }
check_usb_disk_ready() { check_usb_disk_ready() {
if echo $1 | $EGREP -q "nvme|mmc"; then if echo $1 | $EGREP -q "nvme|mmc|nbd"; then
vtpart2=${1}p2 vtpart2=${1}p2
else else
vtpart2=${1}2 vtpart2=${1}2
@ -121,7 +121,7 @@ is_ventoy_disk() {
} }
not_ventoy_disk() { not_ventoy_disk() {
if echo $1 | $EGREP -q "nvme.*p$|mmc.*p$"; then if echo $1 | $EGREP -q "nvme.*p$|mmc.*p$|nbd.*p$"; then
vtDiskName=${1:0:-1} vtDiskName=${1:0:-1}
else else
vtDiskName=$1 vtDiskName=$1
@ -486,7 +486,7 @@ ventoy_create_persistent_link() {
} }
ventoy_udev_disk_common_hook() { ventoy_udev_disk_common_hook() {
if echo $1 | $EGREP -q "nvme.*p[0-9]$|mmc.*p[0-9]$"; then if echo $1 | $EGREP -q "nvme.*p[0-9]$|mmc.*p[0-9]$|nbd.*p[0-9]$"; then
VTDISK="${1:0:-2}" VTDISK="${1:0:-2}"
else else
VTDISK="${1:0:-1}" VTDISK="${1:0:-1}"
@ -558,7 +558,7 @@ is_inotify_ventoy_part() {
if echo $1 | $GREP -q "2$"; then if echo $1 | $GREP -q "2$"; then
if ! [ -e /sys/block/$1 ]; then if ! [ -e /sys/block/$1 ]; then
if [ -e /sys/class/block/$1 ]; then if [ -e /sys/class/block/$1 ]; then
if echo $1 | $EGREP -q "nvme|mmc"; then if echo $1 | $EGREP -q "nvme|mmc|nbd"; then
vtShortName=${1:0:-2} vtShortName=${1:0:-2}
else else
vtShortName=${1:0:-1} vtShortName=${1:0:-1}

View File

@ -90,6 +90,8 @@ get_disk_part_name() {
echo ${DISK}p${2} echo ${DISK}p${2}
elif echo $DISK | grep -q "/dev/mmcblk[0-9]"; then elif echo $DISK | grep -q "/dev/mmcblk[0-9]"; then
echo ${DISK}p${2} echo ${DISK}p${2}
elif echo $DISK | grep -q "/dev/nbd[0-9]"; then
echo ${DISK}p${2}
else else
echo ${DISK}${2} echo ${DISK}${2}
fi fi

View File

@ -20,7 +20,7 @@ get_disk_size() {
enum_disk() { enum_disk() {
id=1 id=1
rm -f /device.list rm -f /device.list
ls /sys/block/ | egrep 'd[a-z]|nvme|mmc' | while read dev; do ls /sys/block/ | egrep 'd[a-z]|nvme|mmc|nbd' | while read dev; do
if ! [ -b /dev/$dev ]; then if ! [ -b /dev/$dev ]; then
continue continue
fi fi

View File

@ -507,7 +507,7 @@ static int vtoydm_print_linear_table(const char *img_map_file, const char *diskn
(sector_start << 2), disk_sector_num, (sector_start << 2), disk_sector_num,
diskname, (unsigned long long)chunk[i].disk_start_sector); diskname, (unsigned long long)chunk[i].disk_start_sector);
#else #else
if (strstr(diskname, "nvme") || strstr(diskname, "mmc")) if (strstr(diskname, "nvme") || strstr(diskname, "mmc") || strstr(diskname, "nbd"))
{ {
printf("%u %u linear %sp1 %llu\n", printf("%u %u linear %sp1 %llu\n",
(sector_start << 2), disk_sector_num, (sector_start << 2), disk_sector_num,

Binary file not shown.

Binary file not shown.

Binary file not shown.