2 * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2.1
6 * as published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <sys/mount.h>
18 #include "../lib/mtd.h"
19 #include "../fs-state.h"
22 backend_mount(char *name)
24 struct backend *b = find_backend(name);
33 backend_info(char *name)
35 struct backend *b = find_backend(name);
44 start(int argc, char **argv)
48 if (!getenv("PREINIT"))
51 if (find_mtd_char("rootfs_data", mtd, sizeof(mtd))) {
52 if (!find_mtd_char("rootfs", mtd, sizeof(mtd))) {
53 int fd = mtd_load(mtd);
57 fprintf(stderr, "mounting /dev/root\n");
58 mount("/dev/root", "/", NULL, MS_NOATIME | MS_REMOUNT, 0);
63 if (!backend_mount("extroot")) {
64 fprintf(stderr, "fs-state: switched to extroot\n");
68 switch (mtd_identify(mtd)) {
74 backend_mount("overlay");
78 backend_mount("snapshot");
86 stop(int argc, char **argv)
88 if (!getenv("SHUTDOWN"))
95 done(int argc, char **argv)
99 if (find_mtd_char("rootfs_data", mtd, sizeof(mtd)))
102 switch (mtd_identify(mtd)) {
105 return jffs2_switch(argc, argv);
112 info(int argc, char **argv)
116 if (find_mtd_char("rootfs_data", mtd, sizeof(mtd)))
119 switch (mtd_identify(mtd)) {
121 backend_info("snapshot");
128 static struct backend start_backend = {
132 BACKEND(start_backend);
134 static struct backend stop_backend = {
138 BACKEND(stop_backend);
140 static struct backend done_backend = {
144 BACKEND(done_backend);
146 static struct backend info_backend = {
150 BACKEND(info_backend);