4 # Copyright (C) 2010 Davidlohr Bueso <dave@gnu.org>
6 # This file is part of util-linux.
8 # This file is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # This file is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
19 TS_TOPDIR
="${0%/*}/../.."
20 TS_DESC
="partitions probing"
23 .
$TS_TOPDIR/functions.sh
26 ts_check_test_command
"$TS_CMD_PARTX"
27 ts_check_test_command
"$TS_CMD_ADDPART"
28 ts_check_test_command
"$TS_CMD_DELPART"
34 function check_partition_count
36 # this function needs shopt -s nullglob
38 local devname
=$
(basename $TS_DEVICE)
39 local parts
=(/sys
/block
/${devname}/${devname}*)
40 local cnt_have
=${#parts[@]}
42 if [ $cnt_have -eq $cnt_want ]; then
45 echo "error: expected $cnt_want partitions, have $cnt_have" >&2
46 echo "${parts[@]}" >&2
50 # set global variable TS_DEVICE
51 ts_scsi_debug_init dev_size_mb
=50
53 ts_init_subtest
"addpart"
55 $TS_CMD_ADDPART ${TS_DEVICE} 1 0 1 &&
57 echo "Unable to add partition"
58 check_partition_count
1
64 ts_init_subtest
"delpart"
66 $TS_CMD_DELPART ${TS_DEVICE} 1 &&
68 echo "Unable to remove partition"
69 check_partition_count
0
75 # set global variable TS_DEVICE
76 ts_scsi_debug_init dev_size_mb
=50 num_parts
=$PARTS
78 ts_init_subtest
"detect-parts"
80 $TS_CMD_PARTX --show $TS_DEVICE &&
82 echo "Unable to list partitions"
83 check_partition_count
$PARTS
89 ts_init_subtest
"delete-all"
92 $TS_CMD_PARTX --delete $TS_DEVICE &&
93 echo "partitions deleted" ||
94 echo "Unable to delete partitions on $TS_DEVICE"
95 check_partition_count
0
101 ts_init_subtest
"add-all"
102 #read TS_DEVICE and restore the partinfo
104 $TS_CMD_PARTX --add $TS_DEVICE &&
105 echo "partitions added" ||
106 echo "Unable to add partitions for $TS_DEVICE"
107 check_partition_count
$PARTS
113 ts_init_subtest
"update-one"
114 #read TS_DEVICE and update second partition
116 $TS_CMD_PARTX --update ${TS_DEVICE}2 &&
117 echo "partitions updated" ||
118 echo "Unable to update 2nd partition for $TS_DEVICE"
119 check_partition_count
$PARTS
125 ts_init_subtest
"delete-one"
126 #remove last partition only
128 $TS_CMD_PARTX -d --nr -1 $TS_DEVICE &&
129 echo "last partition removed" ||
130 echo "Unable to remove a partition on $TS_DEVICE"
131 check_partition_count $
((PARTS-1
))
137 ts_init_subtest
"delete-non-existent"
138 #attempt to remove it again
140 # remove non-existing partitions (ENXIO) is not error
142 # see ab025087f91b66ee8e23a16bc49eb0d9bd421d65 and
143 # 53ae7d60cfeacd4e87bfe6fcc015b58b78ef4555
145 $TS_CMD_PARTX -d --nr $PARTS $TS_DEVICE &&
147 echo "partx failed: removed non-existing partition"
153 ts_init_subtest
"add-existing"
154 #try adding an existing partition
156 $TS_CMD_PARTX -a --nr 1 $TS_DEVICE 2>/dev
/null
&&
157 echo "partx failed: re-added an existing partition" ||
164 ts_init_subtest
"change-by-range"
165 # {-a|-d} --nr 0 should handle all partitions
167 $TS_CMD_PARTX -d --nr 0 $TS_DEVICE &&
168 echo "partitions deleted" ||
169 echo "Unable to delete partitions on $TS_DEVICE"
170 check_partition_count
0
171 $TS_CMD_PARTX -a --nr 0 $TS_DEVICE &&
172 echo "partitions added" ||
173 echo "Failed to add $TS_DEVICE partitions"
174 check_partition_count
$PARTS