2 * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2.1
6 * as published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <sys/mount.h>
15 #include <sys/types.h>
17 #include <sys/reboot.h>
18 #include <libubox/ulog.h>
29 #include "libfstools/libfstools.h"
30 #include "libfstools/volume.h"
32 static int jffs2_mark(struct volume *v);
37 ULOG_WARN("This will erase all settings and remove any installed packages. Are you sure? [N/y]\n");
43 static int jffs2_reset(struct volume *v, int reset)
47 mp = find_mount_point(v->blk, 1);
49 ULOG_INFO("%s is mounted as %s, only erasing files\n", v->blk, mp);
50 fs_state_set("/overlay", FS_STATE_PENDING);
51 overlay_delete(mp, false);
52 mount(mp, "/", NULL, MS_REMOUNT, 0);
54 ULOG_INFO("%s is not mounted\n", v->blk);
69 static int jffs2_mark(struct volume *v)
71 __u32 deadc0de = __cpu_to_be32(0xdeadc0de);
75 fd = open(v->blk, O_WRONLY);
76 ULOG_INFO("%s will be erased on next mount\n", v->blk);
78 ULOG_ERR("opening %s failed\n", v->blk);
82 sz = write(fd, &deadc0de, sizeof(deadc0de));
86 ULOG_ERR("writing %s failed: %s\n", v->blk, strerror(errno));
93 int main(int argc, char **argv)
96 int ch, yes = 0, reset = 0;
97 while ((ch = getopt(argc, argv, "yr")) != -1) {
109 if (!yes && ask_user())
113 * TODO: Currently this only checks if kernel supports OverlayFS. We
114 * should check if there is a mount point using it with rootfs_data
117 if (find_filesystem("overlay")) {
118 ULOG_ERR("overlayfs not supported by kernel\n");
122 v = volume_find("rootfs_data");
124 ULOG_ERR("MTD partition 'rootfs_data' not found\n");
129 if (!strcmp(*argv, "jffs2mark"))
130 return jffs2_mark(v);
131 return jffs2_reset(v, reset);