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