void stop_jffs2(int stop) { struct statfs sf; #if defined(RTCONFIG_PSISTLOG) || defined(RTCONFIG_JFFS2LOG) int restart_syslogd = 0; #endif if (!wait_action_idle(10)) return; if ((statfs("/jffs", &sf) == 0) && (sf.f_type != 0x73717368) && (sf.f_type != 0x71736873)) { // is mounted run_userfile("/jffs", ".autostop", "/jffs", 5); run_nvscript("script_autostop", "/jffs", 5); } #if defined(RTCONFIG_PSISTLOG) || defined(RTCONFIG_JFFS2LOG) if (!stop && !strncmp(get_syslog_fname(0), "/jffs/", 6)) { restart_syslogd = 1; stop_syslogd(); eval("cp", "/jffs/syslog.log", "/jffs/syslog.log-1", "/tmp"); } #endif notice_set("jffs", "Stopped"); if (umount("/jffs")) umount2("/jffs", MNT_DETACH); else modprobe_r(JFFS_NAME); #if defined(RTCONFIG_PSISTLOG) || defined(RTCONFIG_JFFS2LOG) if (restart_syslogd) start_syslogd(); #endif }
void format_mount_2nd_jffs2(void) { int format = 0; char s[256]; int size; int part; const char *p; if (!wait_action_idle(10)) return; if (!mtd_getinfo(SECOND_JFFS2_PARTITION, &part, &size)) return; _dprintf("Format 2nd jffs2: %d, %d\n", part, size); if(!check_in_rootfs(SECOND_JFFS2_PATH, "2nd_jffs", format)) return; if (!mtd_unlock(SECOND_JFFS2_PARTITION)) { error("unlocking"); return; } modprobe(JFFS_NAME); sprintf(s, MTD_BLKDEV(%d), part); if (mount(s, SECOND_JFFS2_PATH, JFFS_NAME, MS_NOATIME, "") != 0) { if( (get_model()==MODEL_RTAC56U || get_model()==MODEL_RTAC56S || get_model()==MODEL_RTAC3200 || get_model()==MODEL_RTAC68U || get_model()==MODEL_RPAC68U || get_model()==MODEL_DSLAC68U || get_model()==MODEL_RTAC87U || get_model()==MODEL_RTAC88U || get_model()==MODEL_RTAC3100 || get_model()==MODEL_RTAC5300 || get_model==MODEL_RTAC5300R || get_model()==MODEL_RTN18U || get_model()==MODEL_RTAC1200G || get_model()==MODEL_RTAC1200GP) ^ (mtd_erase(SECOND_JFFS2_PARTITION)) ){ error("formatting"); return; } format = 1; if (mount(s, SECOND_JFFS2_PATH, JFFS_NAME, MS_NOATIME, "") != 0) { _dprintf("*** jffs2 2-nd mount error\n"); //modprobe_r(JFFS_NAME); error("mounting"); return; } } sprintf(s, "rm -rf %s/*", SECOND_JFFS2_PATH); system(s); notice_set("2nd_jffs", format ? "Formatted" : "Loaded"); if (((p = nvram_get("jffs2_exec")) != NULL) && (*p != 0)) { chdir(SECOND_JFFS2_PATH); system(p); chdir("/"); } run_userfile(SECOND_JFFS2_PATH, ".asusrouter", SECOND_JFFS2_PATH, 3); }
void stop_jffs2(void) { struct statfs sf; if (!wait_action_idle(10)) return; if ((statfs("/jffs", &sf) == 0) && (sf.f_type != 0x71736873)) { // is mounted run_userfile("/jffs", ".autostop", "/jffs", 5); run_nvscript("script_autostop", "/jffs", 5); } notice_set("jffs", "Stopped"); umount2("/jffs", MNT_DETACH); modprobe_r(JFFS_NAME); }
void start_jffs2(void) { if (!nvram_match("jffs2_on", "1")) { notice_set("jffs", ""); return; } int format = 0; char s[256]; int size; int part; const char *p; struct statfs sf; int model = 0; int i = 0; while(1) { if (wait_action_idle(10)) break; else i++; if(i>=10) { _dprintf("Mount jffs2 failed!"); return; } } if (!mtd_getinfo(JFFS2_PARTITION, &part, &size)) return; model = get_model(); _dprintf("start jffs2: %d, %d\n", part, size); if (nvram_match("jffs2_format", "1")) { nvram_set("jffs2_format", "0"); nvram_commit_x(); if (!mtd_erase(JFFS_NAME)) { error("formatting"); return; } format = 1; } sprintf(s, "%d", size); p = nvram_get("jffs2_size"); if ((p == NULL) || (strcmp(p, s) != 0)) { if (format) { nvram_set("jffs2_size", s); nvram_commit_x(); } else if ((p != NULL) && (*p != 0)) { error("verifying known size of"); return; } } if (statfs("/jffs", &sf) == 0) { switch(model) { case MODEL_RTAC56S: case MODEL_RTAC56U: case MODEL_RTAC3200: case MODEL_DSLAC68U: case MODEL_RPAC68U: case MODEL_RTAC68U: case MODEL_RTAC87U: case MODEL_RTN18U: case MODEL_RTN65U: case MODEL_RTN14U: // it should be better to use LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,6,36) { if (sf.f_type != 0x73717368 /* squashfs */) { // already mounted notice_set("jffs", format ? "Formatted" : "Loaded"); return; } break; } default: { if (sf.f_type != 0x71736873 /* squashfs */) { // already mounted notice_set("jffs", format ? "Formatted" : "Loaded"); return; } break; } } } if (nvram_get_int("jffs2_clean_fs")) { if (!mtd_unlock(JFFS2_PARTITION)) { error("unlocking"); return; } } modprobe(JFFS_NAME); sprintf(s, MTD_BLKDEV(%d), part); if (mount(s, "/jffs", JFFS_NAME, MS_NOATIME, "") != 0) { if (!mtd_erase(JFFS_NAME)) { error("formatting"); return; } format = 1; if (mount(s, "/jffs", JFFS_NAME, MS_NOATIME, "") != 0) { _dprintf("*** jffs2 2-nd mount error\n"); //modprobe_r(JFFS_NAME); error("mounting"); return; } } #ifdef TEST_INTEGRITY int test; if (format) { if (f_write("/jffs/.tomato_do_not_erase", &size, sizeof(size), 0, 0) != sizeof(size)) { stop_jffs2(0); error("setting integrity test for"); return; } } if ((f_read("/jffs/.tomato_do_not_erase", &test, sizeof(test)) != sizeof(test)) || (test != size)) { stop_jffs2(0); error("testing integrity of"); return; } #endif if (nvram_get_int("jffs2_clean_fs")) { _dprintf("Clean /jffs/*\n"); system("rm -fr /jffs/*"); nvram_unset("jffs2_clean_fs"); nvram_commit_x(); } notice_set("jffs", format ? "Formatted" : "Loaded"); if (((p = nvram_get("jffs2_exec")) != NULL) && (*p != 0)) { chdir("/jffs"); system(p); chdir("/"); } run_userfile("/jffs", ".asusrouter", "/jffs", 3); if (!check_if_dir_exist("/jffs/scripts/")) mkdir("/jffs/scripts/", 0755); if (!check_if_dir_exist("/jffs/configs/")) mkdir("/jffs/configs/", 0755); }
void format_mount_2nd_jffs2(void) { int format = 0; char s[256]; int size; int part; const char *p; struct statfs sf; int model = 0; if (!wait_action_idle(10)) return; if (!mtd_getinfo(SECOND_JFFS2_PARTITION, &part, &size)) return; _dprintf("Format 2nd jffs2: %d, %d\n", part, size); model = get_model(); sprintf(s, "%d", size); if (statfs(SECOND_JFFS2_PATH, &sf) == 0) { switch(model) { case MODEL_RTAC56S: case MODEL_RTAC56U: case MODEL_RTAC3200: case MODEL_DSLAC68U: case MODEL_RPAC68U: case MODEL_RTAC68U: case MODEL_RTAC87U: case MODEL_RTN18U: case MODEL_RTN65U: case MODEL_RTN14U: // it should be better to use LINUX_KERNEL_VERSION >= KERNEL_VERSION(2,6,36) { if (sf.f_type != 0x73717368 /* squashfs */) { // already mounted notice_set("2nd_jffs", format ? "Formatted" : "Loaded"); return; } break; } default: { if (sf.f_type != 0x71736873 /* squashfs */) { // already mounted notice_set("2nd_jffs", format ? "Formatted" : "Loaded"); return; } break; } } } if (!mtd_unlock(SECOND_JFFS2_PARTITION)) { error("unlocking"); return; } modprobe(JFFS_NAME); sprintf(s, MTD_BLKDEV(%d), part); if (mount(s, SECOND_JFFS2_PATH, JFFS_NAME, MS_NOATIME, "") != 0) { if( (get_model()==MODEL_RTAC56U || get_model()==MODEL_RTAC56S || get_model()==MODEL_RTAC3200 || get_model()==MODEL_RTAC68U || get_model()==MODEL_RPAC68U || get_model()==MODEL_DSLAC68U || get_model()==MODEL_RTAC87U || get_model()==MODEL_RTN18U) ^ (!mtd_erase(JFFS_NAME)) ){ error("formatting"); return; } format = 1; if (mount(s, SECOND_JFFS2_PATH, JFFS_NAME, MS_NOATIME, "") != 0) { _dprintf("*** jffs2 2-nd mount error\n"); //modprobe_r(JFFS_NAME); error("mounting"); return; } } sprintf(s, "rm -rf %s/*", SECOND_JFFS2_PATH); system(s); notice_set("2nd_jffs", format ? "Formatted" : "Loaded"); if (((p = nvram_get("jffs2_exec")) != NULL) && (*p != 0)) { chdir(SECOND_JFFS2_PATH); system(p); chdir("/"); } run_userfile(SECOND_JFFS2_PATH, ".asusrouter", SECOND_JFFS2_PATH, 3); }
void start_jffs2(void) { if (!nvram_match("jffs2_on", "1")) { notice_set("jffs", ""); return; } int format = 0; char s[256]; int size; int part; const char *p; struct statfs sf; if (!wait_action_idle(10)) return; if (!mtd_getinfo("jffs2", &part, &size)) return; _dprintf("*** jffs2: %d, %d\n", part, size); if (nvram_match("jffs2_format", "1")) { nvram_set("jffs2_format", "0"); if (!mtd_erase("jffs2")) { error("formatting"); return; } format = 1; } sprintf(s, "%d", size); p = nvram_get("jffs2_size"); if ((p == NULL) || (strcmp(p, s) != 0)) { if (format) { nvram_set("jffs2_size", s); nvram_commit_x(); } else if ((p != NULL) && (*p != 0)) { error("verifying known size of"); return; } } if ((statfs("/jffs", &sf) == 0) && (sf.f_type != 0x71736873 /* squashfs */)) { // already mounted notice_set("jffs", format ? "Formatted" : "Loaded"); return; } if (!mtd_unlock("jffs2")) { error("unlocking"); return; } modprobe(JFFS_NAME); sprintf(s, MTD_BLKDEV(%d), part); if (mount(s, "/jffs", JFFS_NAME, MS_NOATIME, "") != 0) { _dprintf("*** jffs2 mount error\n"); //modprobe_r(JFFS_NAME); error("mounting"); return; } #ifdef TEST_INTEGRITY int test; if (format) { if (f_write("/jffs/.tomato_do_not_erase", &size, sizeof(size), 0, 0) != sizeof(size)) { stop_jffs2(); error("setting integrity test for"); return; } } if ((f_read("/jffs/.tomato_do_not_erase", &test, sizeof(test)) != sizeof(test)) || (test != size)) { stop_jffs2(); error("testing integrity of"); return; } #endif notice_set("jffs", format ? "Formatted" : "Loaded"); if (((p = nvram_get("jffs2_exec")) != NULL) && (*p != 0)) { chdir("/jffs"); system(p); chdir("/"); } run_userfile("/jffs", ".asusrouter", "/jffs", 3); if (!check_if_dir_exist("/jffs/scripts/")) mkdir("/jffs/scripts/", 0755); if (!check_if_dir_exist("/jffs/configs/")) mkdir("/jffs/configs/", 0755); }
void start_jffs2(void) { if (!nvram_match("jffs2_enable", "1")) { notice_set("jffs", ""); return; } int format = 0; char s[256]; int size; int part; const char *p; int model = 0; int i = 0; while(1) { if (wait_action_idle(10)) break; else i++; if(i>=10) { _dprintf("Mount jffs2 failed!"); return; } } if (!mtd_getinfo(JFFS2_PARTITION, &part, &size)) return; model = get_model(); _dprintf("start jffs2: %d, %d\n", part, size); if (nvram_match("jffs2_format", "1")) { nvram_set("jffs2_format", "0"); nvram_commit_x(); if (mtd_erase(JFFS2_MTD_NAME)) { error("formatting"); return; } format = 1; } sprintf(s, "%d", size); p = nvram_get("jffs2_size"); if ((p == NULL) || (strcmp(p, s) != 0)) { if (format) { nvram_set("jffs2_size", s); nvram_commit_x(); } else if ((p != NULL) && (*p != 0)) { error("verifying known size of"); return; } } if(!check_in_rootfs("/jffs", "jffs", format)) return; if (nvram_get_int("jffs2_clean_fs")) { if (!mtd_unlock(JFFS2_PARTITION)) { error("unlocking"); return; } } modprobe(JFFS_NAME); sprintf(s, MTD_BLKDEV(%d), part); if (mount(s, "/jffs", JFFS_NAME, MS_NOATIME, "") != 0) { if (mtd_erase(JFFS2_MTD_NAME)) { jffs2_fail = 1; error("formatting"); return; } format = 1; if (mount(s, "/jffs", JFFS_NAME, MS_NOATIME, "") != 0) { _dprintf("*** jffs2 2-nd mount error\n"); //modprobe_r(JFFS_NAME); error("mounting"); jffs2_fail = 1; return; } } if(nvram_match("force_erase_jffs2", "1")) { _dprintf("\n*** force erase jffs2 ***\n"); mtd_erase(JFFS2_MTD_NAME); nvram_set("jffs2_clean_fs", "1"); nvram_commit(); reboot(RB_AUTOBOOT); } #ifdef TEST_INTEGRITY int test; if (format) { if (f_write("/jffs/.tomato_do_not_erase", &size, sizeof(size), 0, 0) != sizeof(size)) { stop_jffs2(0); error("setting integrity test for"); return; } } if ((f_read("/jffs/.tomato_do_not_erase", &test, sizeof(test)) != sizeof(test)) || (test != size)) { stop_jffs2(0); error("testing integrity of"); return; } #endif if (nvram_get_int("jffs2_clean_fs")) { _dprintf("Clean /jffs/*\n"); system("rm -fr /jffs/*"); nvram_unset("jffs2_clean_fs"); nvram_commit_x(); } notice_set("jffs", format ? "Formatted" : "Loaded"); jffs2_fail = 0; if (((p = nvram_get("jffs2_exec")) != NULL) && (*p != 0)) { chdir("/jffs"); system(p); chdir("/"); } run_userfile("/jffs", ".asusrouter", "/jffs", 3); if (!check_if_dir_exist("/jffs/scripts/")) mkdir("/jffs/scripts/", 0755); if (!check_if_dir_exist("/jffs/configs/")) mkdir("/jffs/configs/", 0755); }