| 1 |
#!/bin/bash |
| 2 |
|
| 3 |
# |
| 4 |
# This file is part of util-linux. |
| 5 |
# |
| 6 |
# This file is free software; you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation; either version 2 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This file is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
|
| 17 |
|
| 18 |
TS_TOPDIR="${0%/*}/../.." |
| 19 |
TS_DESC="resize" |
| 20 |
|
| 21 |
. "$TS_TOPDIR"/functions.sh |
| 22 |
ts_init "$*" |
| 23 |
|
| 24 |
ts_check_test_command "$TS_CMD_SFDISK" |
| 25 |
ts_check_test_command "$TS_CMD_WIPEFS" |
| 26 |
|
| 27 |
ts_skip_nonroot |
| 28 |
|
| 29 |
# set global variable TS_DEVICE |
| 30 |
ts_scsi_debug_init dev_size_mb=100 sector_size=512 |
| 31 |
|
| 32 |
declare -a COMM |
| 33 |
declare -a NAME |
| 34 |
|
| 35 |
COMM[0]="3000," |
| 36 |
NAME[0]="move-up-absolute" |
| 37 |
|
| 38 |
COMM[1]="2048," |
| 39 |
NAME[1]="move-down-absolute" |
| 40 |
|
| 41 |
COMM[2]="+1M," |
| 42 |
NAME[2]="move-up-relative" |
| 43 |
|
| 44 |
COMM[3]="-1M," |
| 45 |
NAME[3]="move-down-relative" |
| 46 |
|
| 47 |
COMM[4]="-,15M" |
| 48 |
NAME[4]="enlarge-absolute" |
| 49 |
|
| 50 |
COMM[5]=",5M," |
| 51 |
NAME[5]="reduce-absolute" |
| 52 |
|
| 53 |
COMM[6]=", +10M" |
| 54 |
NAME[6]="enlarge-relative" |
| 55 |
|
| 56 |
NAME[7]="reduce-relative" |
| 57 |
COMM[7]=", -10M" |
| 58 |
|
| 59 |
NAME[8]="enlarge-all" |
| 60 |
COMM[8]=",+" |
| 61 |
|
| 62 |
NAME[9]="up-preduce" |
| 63 |
COMM[9]="+10M,-10M" |
| 64 |
|
| 65 |
NAME[10]="down-enlarge" |
| 66 |
COMM[10]="-10M,+10M,,*" |
| 67 |
|
| 68 |
NAME[11]="absolute-move-resize" |
| 69 |
COMM[11]="2048,10M,L" |
| 70 |
|
| 71 |
function test_label_resize { |
| 72 |
local label="$1" |
| 73 |
|
| 74 |
$TS_CMD_WIPEFS -a ${TS_DEVICE} &> /dev/null |
| 75 |
udevadm settle |
| 76 |
|
| 77 |
# create a partition |
| 78 |
echo ',10M,L' | $TS_CMD_SFDISK --no-reread --label ${label} ${TS_DEVICE} &> /dev/null |
| 79 |
udevadm settle |
| 80 |
|
| 81 |
for idx in $(seq 0 $(( ${#COMM[*]} - 1 ))); do |
| 82 |
|
| 83 |
cmd=${COMM[$idx]} |
| 84 |
name=${NAME[$idx]} |
| 85 |
|
| 86 |
ts_init_subtest "$label-$idx-$name" |
| 87 |
echo -e "$cmd\n" >> $TS_OUTPUT |
| 88 |
echo "$cmd" | $TS_CMD_SFDISK --no-reread -N1 ${TS_DEVICE} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 89 |
ts_fdisk_clean $TS_DEVICE |
| 90 |
udevadm settle |
| 91 |
ts_finalize_subtest |
| 92 |
done |
| 93 |
|
| 94 |
echo ',10M,L' | $TS_CMD_SFDISK --no-reread --append ${TS_DEVICE} &> /dev/null |
| 95 |
udevadm settle |
| 96 |
|
| 97 |
echo ',10M,L' | $TS_CMD_SFDISK --no-reread --append ${TS_DEVICE} &> /dev/null |
| 98 |
udevadm settle |
| 99 |
|
| 100 |
idx=$(( $idx + 1 )) |
| 101 |
ts_init_subtest "$label-$idx-reduce-midle" |
| 102 |
cmd=',-5M' |
| 103 |
echo -e "$cmd\n" >> $TS_OUTPUT |
| 104 |
echo "$cmd" | $TS_CMD_SFDISK --no-reread -N2 ${TS_DEVICE} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 105 |
ts_fdisk_clean $TS_DEVICE |
| 106 |
udevadm settle |
| 107 |
ts_finalize_subtest |
| 108 |
|
| 109 |
idx=$(( $idx + 1 )) |
| 110 |
ts_init_subtest "$label-$idx-max-last" |
| 111 |
cmd='-5M,+' |
| 112 |
echo -e "$cmd\n" >> $TS_OUTPUT |
| 113 |
echo $cmd | $TS_CMD_SFDISK --no-reread -N3 ${TS_DEVICE} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 114 |
ts_fdisk_clean $TS_DEVICE |
| 115 |
udevadm settle |
| 116 |
ts_finalize_subtest |
| 117 |
} |
| 118 |
|
| 119 |
# MBR |
| 120 |
test_label_resize dos |
| 121 |
|
| 122 |
# GPT |
| 123 |
test_label_resize gpt |
| 124 |
|
| 125 |
|
| 126 |
$TS_CMD_WIPEFS -a ${TS_DEVICE} &> /dev/null |
| 127 |
udevadm settle |
| 128 |
|
| 129 |
ts_init_subtest "dos-unsorted" |
| 130 |
# create layout where partition #4 is the last on disk (by offset) |
| 131 |
# and there is freespace at the end of the disk. Note that #4 is not the last |
| 132 |
# partno on the disk. The libfdisk has to be able to check for the free space |
| 133 |
# independently on the partno, only offset+size matters. |
| 134 |
$TS_CMD_SFDISK --no-reread ${TS_DEVICE} >> $TS_OUTPUT 2>> $TS_ERRLOG <<EOF |
| 135 |
label: dos |
| 136 |
label-id: 0xda2e45ac |
| 137 |
device: ${TS_DEVICE} |
| 138 |
unit: sectors |
| 139 |
|
| 140 |
${TS_DEVICE}1 : start= 2048, size= 2048, type=83 |
| 141 |
${TS_DEVICE}2 : start= 4096, size= 2048, type=83 |
| 142 |
${TS_DEVICE}3 : start= 6144, size= 102400, type=5 |
| 143 |
${TS_DEVICE}4 : start= 108544, size= 2048, type=83 |
| 144 |
${TS_DEVICE}5 : start= 8192, size= 2048, type=83 |
| 145 |
${TS_DEVICE}6 : start= 12288, size= 96256, type=83 |
| 146 |
EOF |
| 147 |
udevadm settle |
| 148 |
# enlarge to use all space behind partition #4 |
| 149 |
echo ',+,' | $TS_CMD_SFDISK --no-reread -N 4 ${TS_DEVICE} >> $TS_OUTPUT 2>> $TS_ERRLOG |
| 150 |
ts_fdisk_clean $TS_DEVICE |
| 151 |
udevadm settle |
| 152 |
ts_finalize_subtest |
| 153 |
|
| 154 |
ts_finalize |