Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure syntactically correct 'disk' and 'part' entries in disklayout.conf #2804

Merged
merged 1 commit into from
May 18, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions usr/share/rear/layout/save/GNU/Linux/200_partition_layout.sh
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,23 @@ extract_partitions() {

### Write to layout file
while read partition_nr size start type flags junk ; do
### determine the name of the partition using the number
### device=/dev/cciss/c0d0 ; partition_prefix=cciss/c0d0p
### device=/dev/md127 ; partition_prefix=md127p
### device=/dev/sda ; partition_prefix=sda
### device=/dev/mapper/mpathbp1 ; partition_prefix=mpathbp
# determine the name of the partition using the number
# device=/dev/cciss/c0d0 ; partition_prefix=cciss/c0d0p
# device=/dev/md127 ; partition_prefix=md127p
# device=/dev/sda ; partition_prefix=sda
# device=/dev/mapper/mpathbp1 ; partition_prefix=mpathbp
partition_name="${device%/*}/${partition_prefix#*/}$partition_nr"
echo "part $device $size $start $type $flags $(get_device_name $partition_name)"
partition_device="$( get_device_name $partition_name )"
test -b "$partition_device" || Error "Invalid 'part $device' entry (partition device '$partition_device' is no block device)"
# Ensure syntactically correct 'part' entries of the form
# part disk_device partition_size start_byte partition_label flags partition_device
# Each value must exist and each value must be a single non-blank word.
# When $junk contains something one of the values before was more than a single word:
test "$junk" && Error "Invalid 'part $device' entry (some value is more than a single word)"
# When $flags is empty at least one value is missing:
test "$flags" || Error "Invalid 'part $device' entry (at least one value is missing)"
# Some basic checks on the values happen in layout/save/default/950_verify_disklayout_file.sh
echo "part $device $size $start $type $flags $partition_device"
done < $TMP_DIR/partitions
}

Expand Down Expand Up @@ -383,6 +393,11 @@ Log "Saving disks and their partitions"
devname=$(get_device_name $disk)
devsize=$(get_disk_size ${disk#/sys/block/})
disktype=$(parted -s $devname print | grep -E "Partition Table|Disk label" | cut -d ":" -f "2" | tr -d " ")
# Ensure syntactically correct 'disk' entries:
# Each value must exist and each value must be a single non-blank word so we 'test' without quoting the value:
test $devname || Error "Invalid 'disk' entry (no disk device name for '$disk')"
test $devsize || Error "Invalid 'disk $devname' entry (no device size for '$devname')"
test $disktype || Error "Invalid 'disk $devname' entry (no partition table type for '$devname')"

echo "# Disk $devname"
echo "# Format: disk <devname> <size(bytes)> <partition label type>"
Expand Down