00001
00002
00003
00004
00005
00006
00007 #include <stdio.h>
00008 #include <string.h>
00009 #include "libjio.h"
00010
00011
00012 static void usage(void)
00013 {
00014 printf("\
00015 Use: jiofsck [clean=1] [dir=DIR] FILE\n\
00016 \n\
00017 Where \"FILE\" is the name of the file you want to check the journal from,\n\
00018 and the optional parameter \"clean\" makes jiofsck to clean up the journal\n\
00019 after recovery.\n\
00020 The parameter \"dir=DIR\", also optional, is used to indicate the position\n\
00021 of the journal directory.\n\
00022 \n\
00023 Examples:\n\
00024 # jiofsck file\n\
00025 # jiofsck clean=1 file\n\
00026 # jiofsck dir=/tmp/journal file\n\
00027 # jiofsck clean=1 dir=/tmp/journal file\n\
00028 \n");
00029 }
00030
00031 int main(int argc, char **argv)
00032 {
00033 int i, do_cleanup;
00034 unsigned int flags;
00035 char *file, *jdir;
00036 struct jfsck_result res;
00037 enum jfsck_return rv;
00038
00039
00040
00041 file = jdir = NULL;
00042 do_cleanup = 0;
00043
00044 if (argc < 2) {
00045 usage();
00046 return 1;
00047 }
00048
00049 for (i = 1; i < argc; i++) {
00050 if (strcmp("clean=1", argv[i]) == 0) {
00051 do_cleanup = 1;
00052 } else if (strncmp("dir=", argv[i], 4) == 0) {
00053 jdir = argv[i] + 4;
00054 } else {
00055 file = argv[i];
00056 }
00057 }
00058
00059 memset(&res, 0, sizeof(res));
00060
00061 flags = 0;
00062 if (do_cleanup)
00063 flags |= J_CLEANUP;
00064
00065 printf("Checking journal: ");
00066 fflush(stdout);
00067 rv = jfsck(file, jdir, &res, flags);
00068
00069 switch (rv) {
00070 case J_ESUCCESS:
00071 printf("done\n");
00072 break;
00073 case J_ENOENT:
00074 printf("No such file or directory\n");
00075 return 1;
00076 case J_ENOJOURNAL:
00077 printf("No journal associated to the file, "
00078 "or journal empty\n");
00079 return 1;
00080 case J_ENOMEM:
00081 printf("Not enough memory\n");
00082 return 1;
00083 case J_ECLEANUP:
00084 printf("Error cleaning up the journal directory\n");
00085 return 1;
00086 case J_EIO:
00087 printf("I/O error\n");
00088 perror(" additional information");
00089 return 1;
00090 default:
00091 printf("Unknown result, please report as a bug\n");
00092 return 1;
00093 }
00094
00095 printf("Journal checking results\n");
00096 printf("------------------------\n\n");
00097
00098 printf("Total:\t\t %d\n", res.total);
00099 printf("Invalid:\t %d\n", res.invalid);
00100 printf("In progress:\t %d\n", res.in_progress);
00101 printf("Broken:\t\t %d\n", res.broken);
00102 printf("Corrupt:\t %d\n", res.corrupt);
00103 printf("Reapplied:\t %d\n", res.reapplied);
00104 printf("\n");
00105
00106 if (do_cleanup) {
00107 printf("The journal has been cleaned up.\n");
00108 }
00109
00110 return 0;
00111 }
00112