#!/bin/sh

set -eu

# A mock of kpartx(8) for the ikvswitch unit tests: it pretends the
# image holds a single partition, and records the image name (ie: the
# VM name) in ${IKV_MOCK_CURRENT}, so that the umount mock knows where
# to copy the "mounted" rootfs. Requires IKV_MOCK_CURRENT to be set.

: "${IKV_MOCK_CURRENT:?IKV_MOCK_CURRENT must be set}"

case "${1:-}" in
-asv)
	VM=$(basename "$2" .raw)
	echo "${VM}" >"${IKV_MOCK_CURRENT}"
	echo "add map loop0p1 (253:0): 0 20971520 linear /dev/loop0 2048"
	;;
-d)
	if [ -n "${IKV_MOCK_KPARTX_LOG:-}" ] ; then
		echo "$@" >>"${IKV_MOCK_KPARTX_LOG}"
	fi
	;;
esac
exit 0
