[OpenWrt-Devel] [PATCH fstools 1/2] jffs2reset: avoid code duplication in jffs2_reset and jffs2_mark
Rafał Miłecki
zajec5 at gmail.com
Fri Apr 10 15:21:24 EDT 2015
Signed-off-by: Rafał Miłecki <zajec5 at gmail.com>
---
jffs2reset.c | 52 +++++++++++++++++++++-------------------------------
1 file changed, 21 insertions(+), 31 deletions(-)
diff --git a/jffs2reset.c b/jffs2reset.c
index 1080883..d634386 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,24 @@ jffs2_mark(int argc, char **argv)
int main(int argc, char **argv)
{
+ struct volume *v;
+
+ if (ask_user(argc, argv))
+ return -1;
+
+ /* TODO: Check for /overlay filesystem */
+ 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