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