4 Copyright (C) 2006-2009 Jonathan Zarate
10 #include <sys/mount.h>
14 // #define TEST_INTEGRITY
17 static void error(const char *message
)
21 snprintf(s
, sizeof(s
), "Error %s JFFS2. Check the logs to see if they contain more details about this error.", message
);
22 notice_set("jffs2", s
);
25 void start_jffs2(void)
27 if (!nvram_match("jffs2_on", "1")) {
28 notice_set("jffs2", "");
38 if (!wait_action_idle(10)) return;
40 if (!mtd_getinfo("jffs2", &part
, &size
)) return;
42 if (nvram_match("jffs2_format", "1")) {
43 nvram_set("jffs2_format", "0");
45 if (!mtd_erase("jffs2")) {
53 sprintf(s
, "%d", size
);
54 p
= nvram_get("jffs2_size");
55 if ((p
== NULL
) || (strcmp(p
, s
) != 0)) {
57 nvram_set("jffs2_size", s
);
60 else if ((p
!= NULL
) && (*p
!= 0)) {
61 error("verifying known size of");
66 if (!mtd_unlock("jffs2")) {
73 sprintf(s
, "/dev/mtdblock/%d", part
);
74 if (mount(s
, "/jffs", "jffs2", MS_NOATIME
|MS_NODIRATIME
, "") != 0) {
84 if (f_write("/jffs/.tomato_do_not_erase", &size
, sizeof(size
), 0, 0) != sizeof(size
)) {
86 error("setting integrity test for");
91 if ((f_read("/jffs/.tomato_do_not_erase", &test
, sizeof(test
)) != sizeof(test
)) || (test
!= size
)) {
93 error("testing integrity of");
98 notice_set("jffs2", format
? "Formatted." : "");
100 if (((p
= nvram_get("jffs2_exec")) != NULL
) && (*p
!= 0)) {
107 void stop_jffs2(void)
109 if (!wait_action_idle(10)) return;
111 notice_set("jffs2", "");