4 Copyright (C) 2006-2009 Jonathan Zarate
10 #include <sys/mount.h>
14 // #define TEST_INTEGRITY
17 #define JFFS_NAME "jffs2"
19 #define JFFS_NAME "jffs"
22 static void error(const char *message
)
26 snprintf(s
, sizeof(s
), "Error %s JFFS. Check the logs to see if they contain more details about this error.", message
);
27 notice_set("jffs", s
);
30 void start_jffs2(void)
32 if (!nvram_match("jffs2_on", "1")) {
33 notice_set("jffs", "");
43 if (!wait_action_idle(10)) return;
45 if (!mtd_getinfo("jffs2", &part
, &size
)) return;
47 if (nvram_match("jffs2_format", "1")) {
48 nvram_set("jffs2_format", "0");
50 if (!mtd_erase("jffs2")) {
58 sprintf(s
, "%d", size
);
59 p
= nvram_get("jffs2_size");
60 if ((p
== NULL
) || (strcmp(p
, s
) != 0)) {
62 nvram_set("jffs2_size", s
);
65 else if ((p
!= NULL
) && (*p
!= 0)) {
66 error("verifying known size of");
71 if (!mtd_unlock("jffs2")) {
78 sprintf(s
, MTD_BLKDEV(%d
), part
);
79 if (mount(s
, "/jffs", JFFS_NAME
, MS_NOATIME
|MS_NODIRATIME
, "") != 0) {
80 modprobe_r(JFFS_NAME
);
89 if (f_write("/jffs/.tomato_do_not_erase", &size
, sizeof(size
), 0, 0) != sizeof(size
)) {
91 error("setting integrity test for");
96 if ((f_read("/jffs/.tomato_do_not_erase", &test
, sizeof(test
)) != sizeof(test
)) || (test
!= size
)) {
98 error("testing integrity of");
103 notice_set("jffs", format
? "Formatted." : "Loaded.");
105 if (((p
= nvram_get("jffs2_exec")) != NULL
) && (*p
!= 0)) {
112 void stop_jffs2(void)
114 if (!wait_action_idle(10)) return;
116 notice_set("jffs", "stopped");
118 modprobe_r(JFFS_NAME
);