Home | History | Annotate | Line # | Download | only in ckckp
ckckp.c revision 1.1
      1 #include <err.h>
      2 #include <fcntl.h>
      3 #include <stdio.h>
      4 #include <stdlib.h>
      5 #include <sys/param.h>
      6 #include <sys/mount.h>
      7 #include <ufs/ufs/dinode.h>
      8 #include <ufs/lfs/lfs.h>
      9 
     10 int main(int argc, char **argv)
     11 {
     12 	int fd, e, sno;
     13 	char cmd[BUFSIZ], s[BUFSIZ];
     14 	FILE *pp;
     15 
     16 	if (argv[1] == NULL || argv[2] == NULL)
     17 		errx(1, "usage: %s <fs-root> <raw-dev>\n", argv[0]);
     18 
     19 	fd = open(argv[1], 0, 0);
     20 	if (fd < 0)
     21 		err(1, argv[1]);
     22 
     23 	fcntl(fd, LFCNWRAPGO, NULL);
     24 	sleep(5);
     25 
     26 	/* Loop forever calling LFCNWRAP{STOP,GO} */
     27 	sno = 0;
     28 	while(1) {
     29 		printf("Waiting until fs wraps\n");
     30 		fcntl(fd, LFCNWRAPSTOP, NULL);
     31 
     32 		/*
     33 		 * When the fcntl exits, the wrap is about to occur (but
     34 		 * is waiting for the signal to go).  Call our mass-check
     35 		 * script, and if all is well, continue.  The output
     36 		 * of the script should end with a line that begins with a
     37 		 * numeric code: zero for okay, nonzero for a failure.
     38 		 */
     39 		printf("Verifying all checkpoints from s/n %d\n", sno);
     40 		sprintf(cmd, "./check-all %s %d", argv[2], sno);
     41 		pp = popen(cmd, "r");
     42 		s[0] = '\0';
     43 		while(fgets(s, BUFSIZ, pp) != NULL)
     44 			printf("  %s", s);
     45 		if (s[0] == '\0') {
     46 			printf("No checkpoints found or script exited\n");
     47 			return 0;
     48 		}
     49 		sscanf(s, "%d %d", &e, &sno);
     50 		if (e) {
     51 			return 0;
     52 		}
     53 		pclose(pp);
     54 
     55 		++sno;
     56 		printf("Waiting until fs continues\n");
     57 		fcntl(fd, LFCNWRAPGO, NULL);
     58 	}
     59 
     60 	return 0;
     61 }
     62