#include <sys/types.h>
#include <sys/mount.h>
#include <sys/uio.h>

#include <errno.h>
#include <stdio.h>
#include <string.h>

int
main(int argc, char **argv)
{
	struct iovec options[6];
	int result;

	if (argc != 3) {
		fprintf(stderr, "usage: B21-qemu-probe DEVICE MOUNTPOINT\n");
		return (2);
	}
	options[0].iov_base = "fstype";
	options[0].iov_len = sizeof("fstype");
	options[1].iov_base = "erofs";
	options[1].iov_len = sizeof("erofs");
	options[2].iov_base = "fspath";
	options[2].iov_len = sizeof("fspath");
	options[3].iov_base = argv[2];
	options[3].iov_len = strlen(argv[2]) + 1;
	options[4].iov_base = "from";
	options[4].iov_len = sizeof("from");
	options[5].iov_base = argv[1];
	options[5].iov_len = strlen(argv[1]) + 1;
	errno = 0;
	result = nmount(options, sizeof(options) / sizeof(options[0]), MNT_RDONLY);
	printf("rc=%d errno=%d\n", result, result == -1 ? errno : 0);
	return (0);
}
