/* DF-5012 trigger: read the raw disk at the leak offset (wedges forever)
 * or at the recovery-poke offset (completes the leaked bio). */
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>

int
main(int argc, char **argv)
{
	char buf[512];
	ssize_t r;
	int fd;

	if (argc < 3) {
		fprintf(stderr, "usage: %s wedge|poke <device>\n", argv[0]);
		exit(2);
	}
	fd = open(argv[2], O_RDONLY);
	if (fd < 0) {
		perror("open");
		exit(1);
	}
	if (strcmp(argv[1], "wedge") == 0) {
		r = pread(fd, buf, sizeof(buf), 2UL << 20);
		fprintf(stderr, "wedge: pread@2M RETURNED r=%zd errno=%d "
		    "(only possible after external completion)\n", r, errno);
	} else {
		r = pread(fd, buf, sizeof(buf), 1UL << 20);
		fprintf(stderr, "poke: pread@1M r=%zd errno=%d\n", r, errno);
	}
	return (0);
}
