/*
 * DF-2675 pindir: pin self to <cpu>, then getdents(2) the given directory
 * (forces the msdosfs directory cluster read on the chosen cpu).
 * Prints the number of dirents seen.
 */
#include <sys/types.h>
#include <sys/usched.h>
#include <dirent.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int
main(int argc, char **argv)
{
	DIR *d;
	struct dirent *de;
	int n = 0;

	if (argc != 3) {
		fprintf(stderr, "usage: pindir cpu dir\n");
		return 1;
	}
	{ int pin_cpu = atoi(argv[1]);
	if (usched_set(0, USCHED_SET_CPU, &pin_cpu, sizeof(pin_cpu)) < 0)
		err(1, "usched_set"); }
	d = opendir(argv[2]);
	if (!d) err(1, "opendir");
	while ((de = readdir(d)) != NULL)
		n++;
	closedir(d);
	printf("PINDIR cpu=%s %s entries=%d\n", argv[1], argv[2], n);
	return 0;
}
