@@ -15,7 +15,6 @@ check_and_install_commands() {
1515 # List of required commands and their packages (for RHEL/CentOS)
1616 local commands_and_packages=(
1717 " losetup:util-linux"
18- " parted:parted"
1918 " mount:util-linux"
2019 " umount:util-linux"
2120 )
@@ -136,7 +135,7 @@ setup_config() {
136135 # Create a KBS volume config (using mock values for CI)
137136 cat > " ${CONFIG_DIR} /volumes/kbs-test.toml" << EOF
138137volume = "kbs-test"
139- dev = "/dev/loop99p1 "
138+ dev = "${LOOP_DEV} "
140139auto_open = true
141140makefs = "ext4"
142141integrity = true
@@ -155,36 +154,18 @@ create_test_disk() {
155154 dd if=/dev/zero of=test-disk.img bs=1M count=100
156155
157156 # Detach loop device if already attached
158- for i in {0..9}; do
159- if losetup -a | grep -q " test-disk.img" ; then
160- LOOP_DEV=$( losetup -a | grep " test-disk.img" | cut -d: -f1)
161- losetup -d " $LOOP_DEV " 2> /dev/null || true
162- fi
163- done
157+ LOOP_DEVICE=$( losetup --associated " $IMAGE " | awk ' {print $1}' )
158+ if [ -n " $LOOP_DEVICE " ]; then
159+ losetup -d " $LOOP_DEV " 2> /dev/null || true
160+ fi
164161
165162 # Set up loop device (try different numbers if /dev/loop99 is busy)
166- LOOP_DEV=" "
167- for i in {99..90}; do
168- if ! losetup -P /dev/loop" $i " test-disk.img 2> /dev/null; then
169- continue
170- else
171- LOOP_DEV=" /dev/loop$i "
172- break
173- fi
174- done
163+ LOOP_DEV=$( losetup --find)
175164
176165 if [[ -z " $LOOP_DEV " ]]; then
177166 error " Failed to set up loop device"
178167 fi
179168
180- # Update the config file to use the actual loop device
181- sed -i " s|/dev/loop99|${LOOP_DEV} |g" ${CONFIG_DIR} /volumes/kbs-test.toml
182-
183- # Create GPT partition table and one partition
184- parted --script " $LOOP_DEV " \
185- mktable gpt \
186- mkpart primary 1MiB 100%
187-
188169 # Wait for partition to be ready
189170 sleep 2
190171
@@ -298,12 +279,12 @@ main() {
298279
299280 log " Starting KBS volume encryption test"
300281
301- # Setup config
302- setup_config
303-
304282 # Create test disk
305283 create_test_disk
306284
285+ # Setup config
286+ setup_config
287+
307288 # Test volume operations
308289 if ! test_volume_init; then
309290 error " Volume initialization failed"
0 commit comments