There were several memory leaks inside jfsck(), they've probably been there for a...
[libjio.git] / jiofsck.c
blobdb3f6ba4efe241f88b7810dc0356053219859f77
2 /*
3 * jiofsck - A journal checker and recovery tool for libjio
4 * Alberto Bertogli (albertogli@telpin.com.ar)
5 */
7 #include <stdio.h>
8 #include <string.h>
9 #include "libjio.h"
12 void usage()
14 printf("Use: jiofsck [clean] FILE\n\n");
15 printf("Where \"FILE\" is the name of the file "
16 "which you want to check the journal from,\n"
17 "and the optional parameter \"clean\" makes "
18 "jiofsck to clean up the journal after\n"
19 "recovery.\n");
22 int main(int argc, char **argv)
24 int rv, do_cleanup;
25 char *file;
26 struct jfsck_result res;
28 if (argc != 2 && argc != 3) {
29 usage();
30 return 1;
33 if (argc == 3) {
34 if (strcmp("clean", argv[1]) != 0 ) {
35 usage();
36 return 1;
38 file = argv[2];
39 do_cleanup = 1;
40 } else {
41 file = argv[1];
42 do_cleanup = 0;
45 memset(&res, 0, sizeof(res));
47 printf("Checking journal: ");
48 fflush(stdout);
49 rv = jfsck(file, &res);
51 if (rv == J_ENOENT) {
52 printf("No such file or directory\n");
53 return 1;
54 } else if (rv == J_ENOJOURNAL) {
55 printf("No journal associated to the file, "
56 "or journal empty\n");
57 return 1;
60 printf("done\n");
62 if (do_cleanup) {
63 printf("Cleaning journal: ");
64 fflush(stdout);
65 if (!jfsck_cleanup(file)) {
66 printf("Error cleaning journal\n");
67 return 1;
70 printf("done\n");
73 printf("Journal checking results\n");
74 printf("------------------------\n\n");
76 printf("Total:\t\t %d\n", res.total);
77 printf("Invalid:\t %d\n", res.invalid);
78 printf("In progress:\t %d\n", res.in_progress);
79 printf("Broken head:\t %d\n", res.broken_head);
80 printf("Broken body:\t %d\n", res.broken_body);
81 printf("Load error:\t %d\n", res.load_error);
82 printf("Corrupt:\t %d\n", res.corrupt);
83 printf("Apply error:\t %d\n", res.apply_error);
84 printf("Reapplied:\t %d\n", res.reapplied);
85 printf("\n");
87 if (!do_cleanup) {
88 printf("You can now safely remove the journal directory "
89 "completely\nto start a new journal.\n");
90 } else {
91 printf("The journal has been checked and cleaned up.\n");
94 return 0;