⬢ DragonFlyBSD Kernel Audit
DF-3241 / fhstat_once.c
← back to finding ↓ download raw
/*
 * DF-3241 sanity helper: resolve a captured fh once while the fs is
 * mounted; exit 0 only if fhstat succeeds.
 */
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/stat.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <err.h>

int
main(int argc, char **argv)
{
	fhandle_t fh;
	struct stat sb;
	int fd;

	if (argc != 2)
		errx(1, "usage: fhstat_once fh.bin");
	fd = open(argv[1], O_RDONLY);
	if (fd < 0)
		err(1, "open");
	if (read(fd, &fh, sizeof(fh)) != sizeof(fh))
		err(1, "read");
	close(fd);
	if (fhstat(&fh, &sb) < 0)
		err(1, "fhstat (expected success on mounted fs)");
	printf("fhstat OK: ino=%ju size=%lld\n", (uintmax_t)sb.st_ino,
	    (long long)sb.st_size);
	return (0);
}