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