projects
/
project
/
fstools.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
block: fix ubi?_? glob pattern
[project/fstools.git]
/
jffs2reset.c
diff --git
a/jffs2reset.c
b/jffs2reset.c
index
778a97e
..
97fd0ab
100644
(file)
--- a/
jffs2reset.c
+++ b/
jffs2reset.c
@@
-14,7
+14,7
@@
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <sys/stat.h>
-
+#include <sys/reboot.h>
#include <libubox/ulog.h>
#include <fcntl.h>
#include <libubox/ulog.h>
#include <fcntl.h>
@@
-23,23
+23,24
@@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <getopt.h>
+
#include "libfstools/libfstools.h"
#include "libfstools/volume.h"
#include "libfstools/libfstools.h"
#include "libfstools/volume.h"
+static int jffs2_mark(struct volume *v);
+
static int
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;
return 0;
-
}
}
-static int jffs2_reset(struct volume *v)
+static int jffs2_reset(struct volume *v
, int reset
)
{
char *mp;
{
char *mp;
@@
-50,8
+51,16
@@
static int jffs2_reset(struct volume *v)
overlay_delete(mp, false);
mount(mp, "/", NULL, MS_REMOUNT, 0);
} else {
overlay_delete(mp, false);
mount(mp, "/", NULL, MS_REMOUNT, 0);
} else {
- ULOG_INFO("%s is not mounted, erasing it\n", v->blk);
- volume_erase_all(v);
+ ULOG_INFO("%s is not mounted\n", v->blk);
+ return jffs2_mark(v);
+ }
+
+ if (reset) {
+ sync();
+ sleep(2);
+ reboot(RB_AUTOBOOT);
+ while (1)
+ ;
}
return 0;
}
return 0;
@@
-64,7
+73,7
@@
static int jffs2_mark(struct volume *v)
int fd;
fd = open(v->blk, O_WRONLY);
int fd;
fd = open(v->blk, O_WRONLY);
- ULOG_INFO("%s
- marking with deadc0de
\n", v->blk);
+ ULOG_INFO("%s
will be erased on next mount
\n", v->blk);
if (!fd) {
ULOG_ERR("opening %s failed\n", v->blk);
return -1;
if (!fd) {
ULOG_ERR("opening %s failed\n", v->blk);
return -1;
@@
-84,8
+93,20
@@
static int jffs2_mark(struct volume *v)
int main(int argc, char **argv)
{
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;
/*
return -1;
/*
@@
-106,5
+127,5
@@
int main(int argc, char **argv)
if (!strcmp(*argv, "jffs2mark"))
return jffs2_mark(v);
if (!strcmp(*argv, "jffs2mark"))
return jffs2_mark(v);
- return jffs2_reset(v);
+ return jffs2_reset(v
, reset
);
}
}