ckckp.c revision 1.6 1 1.6 martin /* $NetBSD: ckckp.c,v 1.6 2008/04/28 20:23:06 martin Exp $ */
2 1.3 perseant
3 1.3 perseant /*-
4 1.3 perseant * Copyright (c) 2006 The NetBSD Foundation, Inc.
5 1.3 perseant * All rights reserved.
6 1.3 perseant *
7 1.3 perseant * This code is derived from software contributed to The NetBSD Foundation
8 1.3 perseant * by Konrad E. Schroder <perseant (at) hhhh.org>.
9 1.3 perseant *
10 1.3 perseant * Redistribution and use in source and binary forms, with or without
11 1.3 perseant * modification, are permitted provided that the following conditions
12 1.3 perseant * are met:
13 1.3 perseant * 1. Redistributions of source code must retain the above copyright
14 1.3 perseant * notice, this list of conditions and the following disclaimer.
15 1.3 perseant * 2. Redistributions in binary form must reproduce the above copyright
16 1.3 perseant * notice, this list of conditions and the following disclaimer in the
17 1.3 perseant * documentation and/or other materials provided with the distribution.
18 1.3 perseant *
19 1.3 perseant * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.3 perseant * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.3 perseant * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.3 perseant * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.3 perseant * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.3 perseant * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.3 perseant * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.3 perseant * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.3 perseant * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.3 perseant * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.3 perseant * POSSIBILITY OF SUCH DAMAGE.
30 1.3 perseant */
31 1.3 perseant
32 1.1 perseant #include <err.h>
33 1.1 perseant #include <fcntl.h>
34 1.1 perseant #include <stdio.h>
35 1.1 perseant #include <stdlib.h>
36 1.1 perseant #include <sys/param.h>
37 1.1 perseant #include <sys/mount.h>
38 1.1 perseant #include <ufs/ufs/dinode.h>
39 1.1 perseant #include <ufs/lfs/lfs.h>
40 1.1 perseant
41 1.1 perseant int main(int argc, char **argv)
42 1.1 perseant {
43 1.1 perseant int fd, e, sno;
44 1.1 perseant char cmd[BUFSIZ], s[BUFSIZ];
45 1.1 perseant FILE *pp;
46 1.5 perseant int dowait = 1;
47 1.1 perseant
48 1.2 perseant if (argc < 5)
49 1.2 perseant errx(1, "usage: %s <fs-root> <raw-dev> <save-filename> "
50 1.2 perseant "<work-filename>\n", argv[0]);
51 1.1 perseant
52 1.1 perseant fd = open(argv[1], 0, 0);
53 1.1 perseant if (fd < 0)
54 1.1 perseant err(1, argv[1]);
55 1.1 perseant
56 1.5 perseant /* Give the writer a head start */
57 1.1 perseant sleep(5);
58 1.1 perseant
59 1.1 perseant /* Loop forever calling LFCNWRAP{STOP,GO} */
60 1.1 perseant sno = 0;
61 1.1 perseant while(1) {
62 1.1 perseant printf("Waiting until fs wraps\n");
63 1.5 perseant fcntl(fd, LFCNWRAPSTOP, &dowait);
64 1.1 perseant
65 1.1 perseant /*
66 1.1 perseant * When the fcntl exits, the wrap is about to occur (but
67 1.1 perseant * is waiting for the signal to go). Call our mass-check
68 1.1 perseant * script, and if all is well, continue. The output
69 1.1 perseant * of the script should end with a line that begins with a
70 1.1 perseant * numeric code: zero for okay, nonzero for a failure.
71 1.1 perseant */
72 1.1 perseant printf("Verifying all checkpoints from s/n %d\n", sno);
73 1.2 perseant sprintf(cmd, "./check-all %s %s %s %d", argv[2], argv[3],
74 1.2 perseant argv[4], sno);
75 1.1 perseant pp = popen(cmd, "r");
76 1.1 perseant s[0] = '\0';
77 1.1 perseant while(fgets(s, BUFSIZ, pp) != NULL)
78 1.1 perseant printf(" %s", s);
79 1.1 perseant if (s[0] == '\0') {
80 1.1 perseant printf("No checkpoints found or script exited\n");
81 1.1 perseant return 0;
82 1.1 perseant }
83 1.1 perseant sscanf(s, "%d %d", &e, &sno);
84 1.1 perseant if (e) {
85 1.5 perseant printf("Script exited with error code %d\n", e);
86 1.5 perseant return 1;
87 1.1 perseant }
88 1.1 perseant pclose(pp);
89 1.1 perseant
90 1.1 perseant ++sno;
91 1.1 perseant printf("Waiting until fs continues\n");
92 1.5 perseant fcntl(fd, LFCNWRAPGO, &dowait);
93 1.1 perseant }
94 1.1 perseant
95 1.1 perseant return 0;
96 1.1 perseant }
97