[OpenWrt-Devel] [PATCH V3 fstools 1/2] jffs2reset: avoid code duplication in jffs2_reset and jffs2_mark
Rafał Miłecki
zajec5 at gmail.com
Sat Apr 11 03:56:43 EDT 2015
Signed-off-by: Rafał Miłecki <zajec5 at gmail.com>
---
V3: Update TODO comment to be more clear.
---
jffs2reset.c | 56 +++++++++++++++++++++++++-------------------------------
1 file changed, 25 insertions(+), 31 deletions(-)
diff --git a/jffs2reset.c b/jffs2reset.c
index 1080883..778a97e 100644
--- a/jffs2reset.c
+++ b/jffs2reset.c
@@ -39,26 +39,10 @@ ask_user(int argc, char **argv)
}
-static int
-jffs2_reset(int argc, char **argv)
+static int jffs2_reset(struct volume *v)
{
- struct volume *v;
char *mp;
- if (ask_user(argc, argv))
- return -1;
-
- if (find_filesystem("overlay")) {
- ULOG_ERR("overlayfs not supported by kernel\n");
- return -1;
- }
-
- v = volume_find("rootfs_data");
- if (!v) {
- ULOG_ERR("MTD partition 'rootfs_data' not found\n");
- return -1;
- }
-
mp = find_mount_point(v->blk, 1);
if (mp) {
ULOG_INFO("%s is mounted as %s, only erasing files\n", v->blk, mp);
@@ -73,23 +57,12 @@ jffs2_reset(int argc, char **argv)
return 0;
}
-static int
-jffs2_mark(int argc, char **argv)
+static int jffs2_mark(struct volume *v)
{
__u32 deadc0de = __cpu_to_be32(0xdeadc0de);
- struct volume *v;
size_t sz;
int fd;
- if (ask_user(argc, argv))
- return -1;
-
- v = volume_find("rootfs_data");
- if (!v) {
- ULOG_ERR("MTD partition 'rootfs_data' not found\n");
- return -1;
- }
-
fd = open(v->blk, O_WRONLY);
ULOG_INFO("%s - marking with deadc0de\n", v->blk);
if (!fd) {
@@ -110,7 +83,28 @@ jffs2_mark(int argc, char **argv)
int main(int argc, char **argv)
{
+ struct volume *v;
+
+ if (ask_user(argc, argv))
+ return -1;
+
+ /*
+ * TODO: Currently this only checks if kernel supports OverlayFS. We
+ * should check if there is a mount point using it with rootfs_data
+ * as upperdir.
+ */
+ if (find_filesystem("overlay")) {
+ ULOG_ERR("overlayfs not supported by kernel\n");
+ return -1;
+ }
+
+ v = volume_find("rootfs_data");
+ if (!v) {
+ ULOG_ERR("MTD partition 'rootfs_data' not found\n");
+ return -1;
+ }
+
if (!strcmp(*argv, "jffs2mark"))
- return jffs2_mark(argc, argv);
- return jffs2_reset(argc, argv);
+ return jffs2_mark(v);
+ return jffs2_reset(v);
}
--
1.8.4.5
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list