Skip to content

Commit 63d0b5c

Browse files
oe1rfcrobimarko
authored andcommitted
base-files: MAJOR/MINOR not sequential, use DISKSEQ instead
Export the unique, monotonic DISKSEQ sequence drive number instead of its major/minor numbers to identify the boot disk and directly match the partition in export_partdevice with PARTN. The MINOR blockdevice numbers are not guaranteed sequential across disks, it can happen that disks enumerate before their partitions are probed, resulting in interleaved MINOR numbers breaking the partition offset calculation: major minor #blocks name 259 0 250059096 nvme0n1 259 2 8192 nvme0n1p1 259 3 491520 nvme0n1p2 259 4 239 nvme0n1p128 259 1 250059096 nvme1n1 259 5 250057728 nvme1n1p1 Signed-off-by: Clemens Hopfer <openwrt@wireloss.net> Link: openwrt/openwrt#18962 Signed-off-by: Robert Marko <robimarko@gmail.com>
1 parent 45a7dd5 commit 63d0b5c

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

package/base-files/files/lib/upgrade/common.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ part_magic_fat() {
167167

168168
export_bootdevice() {
169169
local cmdline uuid blockdev uevent line class
170-
local MAJOR MINOR DEVNAME DEVTYPE
170+
local MAJOR MINOR DEVNAME DEVTYPE DISKSEQ PARTN
171171
local rootpart="$(cmdline_get_var root)"
172172

173173
case "$rootpart" in
@@ -216,25 +216,26 @@ export_bootdevice() {
216216
while read line; do
217217
export -n "$line"
218218
done < "$uevent"
219-
export BOOTDEV_MAJOR=$MAJOR
220-
export BOOTDEV_MINOR=$MINOR
219+
export BOOTDEV_DISKSEQ=$DISKSEQ
221220
return 0
222221
fi
223222

224223
return 1
225224
}
226225

227226
export_partdevice() {
228-
local var="$1" offset="$2"
229-
local uevent line MAJOR MINOR DEVNAME DEVTYPE
227+
local var="$1" partn="$2"
228+
local uevent line MAJOR MINOR DEVNAME DEVTYPE DISKSEQ PARTN
230229

231230
for uevent in /sys/class/block/*/uevent; do
232231
while read line; do
233232
export -n "$line"
234233
done < "$uevent"
235-
if [ "$BOOTDEV_MAJOR" = "$MAJOR" -a $(($BOOTDEV_MINOR + $offset)) = "$MINOR" -a -b "/dev/$DEVNAME" ]; then
236-
export "$var=$DEVNAME"
237-
return 0
234+
if [ "$BOOTDEV_DISKSEQ" = "$DISKSEQ" -a -b "/dev/$DEVNAME" ]; then
235+
if [ "$PARTN" = "$partn" -a "$DEVTYPE" = "partition" ] || [ "$partn" = "0" -a "$DEVTYPE" = "disk" ]; then
236+
export "$var=$DEVNAME"
237+
return 0
238+
fi
238239
fi
239240
done
240241

target/linux/stm32/base-files/lib/upgrade/platform.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ export_bootdevice() {
3131
while read line; do
3232
export -n "$line"
3333
done < "$uevent"
34-
export BOOTDEV_MAJOR=$MAJOR
35-
export BOOTDEV_MINOR=$MINOR
34+
export BOOTDEV_DISKSEQ=$DISKSEQ
3635
return 0
3736
fi
3837

0 commit comments

Comments
 (0)