ckckp.c revision 1.3 1 1.3 perseant /* $NetBSD: ckckp.c,v 1.3 2006/04/27 22:37:54 perseant 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 * 3. All advertising materials mentioning features or use of this software
19 1.3 perseant * must display the following acknowledgement:
20 1.3 perseant * This product includes software developed by the NetBSD
21 1.3 perseant * Foundation, Inc. and its contributors.
22 1.3 perseant * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.3 perseant * contributors may be used to endorse or promote products derived
24 1.3 perseant * from this software without specific prior written permission.
25 1.3 perseant *
26 1.3 perseant * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.3 perseant * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.3 perseant * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.3 perseant * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.3 perseant * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.3 perseant * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.3 perseant * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.3 perseant * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.3 perseant * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.3 perseant * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.3 perseant * POSSIBILITY OF SUCH DAMAGE.
37 1.3 perseant */
38 1.3 perseant
39 1.1 perseant #include <err.h>
40 1.1 perseant #include <fcntl.h>
41 1.1 perseant #include <stdio.h>
42 1.1 perseant #include <stdlib.h>
43 1.1 perseant #include <sys/param.h>
44 1.1 perseant #include <sys/mount.h>
45 1.1 perseant #include <ufs/ufs/dinode.h>
46 1.1 perseant #include <ufs/lfs/lfs.h>
47 1.1 perseant
48 1.1 perseant int main(int argc, char **argv)
49 1.1 perseant {
50 1.1 perseant int fd, e, sno;
51 1.1 perseant char cmd[BUFSIZ], s[BUFSIZ];
52 1.1 perseant FILE *pp;
53 1.1 perseant
54 1.2 perseant if (argc < 5)
55 1.2 perseant errx(1, "usage: %s <fs-root> <raw-dev> <save-filename> "
56 1.2 perseant "<work-filename>\n", argv[0]);
57 1.1 perseant
58 1.1 perseant fd = open(argv[1], 0, 0);
59 1.1 perseant if (fd < 0)
60 1.1 perseant err(1, argv[1]);
61 1.1 perseant
62 1.1 perseant fcntl(fd, LFCNWRAPGO, NULL);
63 1.1 perseant sleep(5);
64 1.1 perseant
65 1.1 perseant /* Loop forever calling LFCNWRAP{STOP,GO} */
66 1.1 perseant sno = 0;
67 1.1 perseant while(1) {
68 1.1 perseant printf("Waiting until fs wraps\n");
69 1.1 perseant fcntl(fd, LFCNWRAPSTOP, NULL);
70 1.1 perseant
71 1.1 perseant /*
72 1.1 perseant * When the fcntl exits, the wrap is about to occur (but
73 1.1 perseant * is waiting for the signal to go). Call our mass-check
74 1.1 perseant * script, and if all is well, continue. The output
75 1.1 perseant * of the script should end with a line that begins with a
76 1.1 perseant * numeric code: zero for okay, nonzero for a failure.
77 1.1 perseant */
78 1.1 perseant printf("Verifying all checkpoints from s/n %d\n", sno);
79 1.2 perseant sprintf(cmd, "./check-all %s %s %s %d", argv[2], argv[3],
80 1.2 perseant argv[4], sno);
81 1.1 perseant pp = popen(cmd, "r");
82 1.1 perseant s[0] = '\0';
83 1.1 perseant while(fgets(s, BUFSIZ, pp) != NULL)
84 1.1 perseant printf(" %s", s);
85 1.1 perseant if (s[0] == '\0') {
86 1.1 perseant printf("No checkpoints found or script exited\n");
87 1.1 perseant return 0;
88 1.1 perseant }
89 1.1 perseant sscanf(s, "%d %d", &e, &sno);
90 1.1 perseant if (e) {
91 1.1 perseant return 0;
92 1.1 perseant }
93 1.1 perseant pclose(pp);
94 1.1 perseant
95 1.1 perseant ++sno;
96 1.1 perseant printf("Waiting until fs continues\n");
97 1.1 perseant fcntl(fd, LFCNWRAPGO, NULL);
98 1.1 perseant }
99 1.1 perseant
100 1.1 perseant return 0;
101 1.1 perseant }
102