diff options
author | Simon Rettberg | 2022-04-20 16:12:51 +0200 |
---|---|---|
committer | Simon Rettberg | 2022-04-20 16:12:51 +0200 |
commit | 5c14c929768b82c0f992207cf60a26542097d17d (patch) | |
tree | 1536135ee36c99d465e04167ce93fdcc310f55c0 | |
parent | [download] fix {x..y} not supported in ash (diff) | |
download | slx-tools-5c14c929768b82c0f992207cf60a26542097d17d.tar.gz slx-tools-5c14c929768b82c0f992207cf60a26542097d17d.tar.xz slx-tools-5c14c929768b82c0f992207cf60a26542097d17d.zip |
[dev] dev_find_partitions: Workaround for missing PARTN/NAME on CentOS 7
This is quick and dirty and only properly handles ASCII partition labels
-rw-r--r-- | modules/dev.inc | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/modules/dev.inc b/modules/dev.inc index 4f0ee51..ce58075 100644 --- a/modules/dev.inc +++ b/modules/dev.inc @@ -74,6 +74,7 @@ dev_get_type() { pstart="$( cat "/sys/block/${devn}/${partn}/start" )" # For validation label="$( grep -Po '(?<=^PARTNAME=).*$' "/sys/block/${devn}/${partn}/uevent" )" number="$( grep -Po '(?<=^PARTN=).*$' "/sys/block/${devn}/${partn}/uevent" )" + number="$( cat "/sys/block/${devn}/${partn}/partition" )" local gpt= if [ "$( dd if="$dev" bs=1 count=8 skip=512 )" = "EFI PART" ]; then gpt=512 @@ -145,7 +146,7 @@ dev_get_type() { fi if [ -n "$gpt" ]; then # GPT - local table_start current entries no entry_size log_start + local table_start current entries no entry_size log_start readoff num byte table_start="$( __read_le "$dev" "$(( gpt + 72 ))" 8 )" entries="$( __read_le "$dev" "$(( gpt + 80 ))" 4 )" entry_size="$( __read_le "$dev" "$(( gpt + 84 ))" 4 )" @@ -163,6 +164,19 @@ dev_get_type() { # Convert raw hex stream to proper string representation. First 3 groups are little endian. uuid="$( dd if="$dev" bs=1 count=16 skip="$(( current + entry_size * (number - 1) ))" 2> /dev/null \ | __bin2hex | sed -r 's/^(..)(..)(..)(..)(..)(..)(..)(..)(....)/\4\3\2\1-\6\5-\8\7-\9-/' )" + if [ -z "$label" ]; then + readoff="$(( current + entry_size * (number - 1) + 56 ))" + num=0 + while [ "$num" -lt 36 ]; do + byte="$( __read_le "$dev" "$readoff" "1" )" + if [ "$byte" -ge 32 ] && [ "$byte" -le 126 ]; then + byte="$( dd if="$dev" bs=1 count="1" skip="$readoff" 2> /dev/null )" + label="$label$byte" + fi + readoff=$(( readoff + 2 )) + num=$(( num + 1 )) + done + fi return 0 fi # Unknown |