From: John Crispin Date: Mon, 24 Aug 2015 08:11:47 +0000 (+0200) Subject: jffs2reset: add a -r (reboot) option to jffs2reset X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b439678db59311c697b3d93c42f763406567a7f3;p=oweals%2Ffstools.git jffs2reset: add a -r (reboot) option to jffs2reset Signed-off-by: John Crispin --- diff --git a/jffs2reset.c b/jffs2reset.c index 0410466..97fd0ab 100644 --- a/jffs2reset.c +++ b/jffs2reset.c @@ -14,7 +14,7 @@ #include #include #include - +#include #include #include @@ -23,6 +23,8 @@ #include #include #include +#include + #include "libfstools/libfstools.h" #include "libfstools/volume.h" @@ -30,18 +32,15 @@ static int jffs2_mark(struct volume *v); static int -ask_user(int argc, char **argv) +ask_user(void) { - if ((argc < 2) || strcmp(argv[1], "-y")) { - ULOG_WARN("This will erase all settings and remove any installed packages. Are you sure? [N/y]\n"); - if (getchar() != 'y') - return -1; - } + ULOG_WARN("This will erase all settings and remove any installed packages. Are you sure? [N/y]\n"); + if (getchar() != 'y') + return -1; return 0; - } -static int jffs2_reset(struct volume *v) +static int jffs2_reset(struct volume *v, int reset) { char *mp; @@ -56,6 +55,14 @@ static int jffs2_reset(struct volume *v) return jffs2_mark(v); } + if (reset) { + sync(); + sleep(2); + reboot(RB_AUTOBOOT); + while (1) + ; + } + return 0; } @@ -86,8 +93,20 @@ static int jffs2_mark(struct volume *v) int main(int argc, char **argv) { struct volume *v; + int ch, yes = 0, reset = 0; + while ((ch = getopt(argc, argv, "yr")) != -1) { + switch(ch) { + case 'y': + yes = 1; + break; + case 'r': + reset = 1; + break; + } + + } - if (ask_user(argc, argv)) + if (!yes && ask_user()) return -1; /* @@ -108,5 +127,5 @@ int main(int argc, char **argv) if (!strcmp(*argv, "jffs2mark")) return jffs2_mark(v); - return jffs2_reset(v); + return jffs2_reset(v, reset); }