4 Copyright (C) 2006-2009 Jonathan Zarate
10 #include <sys/mount.h>
12 #include <sys/statfs.h>
15 #define MNT_DETACH 0x00000002
18 // #define TEST_INTEGRITY
21 #define JFFS_NAME "jffs"
23 #define JFFS_NAME "jffs2"
26 static void error(const char *message
)
30 snprintf(s
, sizeof(s
), "Error %s JFFS. Check the logs to see if they contain more details about this error.", message
);
31 notice_set("jffs", s
);
34 void start_jffs2(void)
36 if (!nvram_match("jffs2_on", "1")) {
37 notice_set("jffs", "");
48 if (!wait_action_idle(10)) return;
50 if (!mtd_getinfo("jffs2", &part
, &size
)) return;
52 if (nvram_match("jffs2_format", "1")) {
53 nvram_set("jffs2_format", "0");
55 if (!mtd_erase("jffs2")) {
63 sprintf(s
, "%d", size
);
64 p
= nvram_get("jffs2_size");
65 if ((p
== NULL
) || (strcmp(p
, s
) != 0)) {
67 nvram_set("jffs2_size", s
);
70 else if ((p
!= NULL
) && (*p
!= 0)) {
71 error("verifying known size of");
76 if ((statfs("/jffs", &sf
) == 0) && (sf
.f_type
!= 0x73717368 /* squashfs */)) {
78 notice_set("jffs", format
? "Formatted" : "Loaded");
82 if (!mtd_unlock("jffs2")) {
89 sprintf(s
, MTD_BLKDEV(%d
), part
);
90 if (mount(s
, "/jffs", JFFS_NAME
, MS_NOATIME
, "") != 0) {
91 modprobe_r(JFFS_NAME
);
100 if (f_write("/jffs/.tomato_do_not_erase", &size
, sizeof(size
), 0, 0) != sizeof(size
)) {
102 error("setting integrity test for");
107 if ((f_read("/jffs/.tomato_do_not_erase", &test
, sizeof(test
)) != sizeof(test
)) || (test
!= size
)) {
109 error("testing integrity of");
114 notice_set("jffs", format
? "Formatted" : "Loaded");
116 if (((p
= nvram_get("jffs2_exec")) != NULL
) && (*p
!= 0)) {
121 run_userfile("/jffs", ".autorun", "/jffs", 3);
124 void stop_jffs2(void)
128 if (!wait_action_idle(10)) return;
130 if ((statfs("/jffs", &sf
) == 0) && (sf
.f_type
!= 0x73717368)) {
132 run_userfile("/jffs", ".autostop", "/jffs", 5);
133 run_nvscript("script_autostop", "/jffs", 5);
136 notice_set("jffs", "Stopped");
137 umount2("/jffs", MNT_DETACH
);
138 modprobe_r(JFFS_NAME
);