a8505fabb9aa5de4a32af26936e736e84292cb05
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 "libfstools/libfstools.h"
19 #include "libfstools/volume.h"
22 * Called in the early (PREINIT) stage, when we immediately need some writable
26 start(int argc
, char *argv
[1])
28 struct volume
*v
= volume_find("rootfs_data");
30 if (!getenv("PREINIT"))
34 v
= volume_find("rootfs");
36 fprintf(stderr
, "mounting /dev/root\n");
37 mount("/dev/root", "/", NULL
, MS_NOATIME
| MS_REMOUNT
, 0);
42 * Before trying to mount and use "rootfs_data" let's check if there is
43 * extroot configured. Following call will handle reading config from
44 * the "rootfs_data" on its own.
47 if (!mount_extroot()) {
48 fprintf(stderr
, "fs-state: switched to extroot\n");
52 /* There isn't extroot, so just try to mount "rootfs_data" */
53 switch (volume_identify(v
)) {
57 * Filesystem isn't ready yet and we are in the preinit, so we
58 * can't afford waiting for it. Use tmpfs for now and handle it
59 * properly in the "done" call.
77 stop(int argc
, char *argv
[1])
79 if (!getenv("SHUTDOWN"))
86 * Called at the end of init, it can wait for filesystem if needed.
89 done(int argc
, char *argv
[1])
91 struct volume
*v
= volume_find("rootfs_data");
96 switch (volume_identify(v
)) {
99 return jffs2_switch(v
);
105 int main(int argc
, char **argv
)
108 return start(argc
, argv
);
109 if (!strcmp(argv
[1], "stop"))
110 return stop(argc
, argv
);
111 if (!strcmp(argv
[1], "done"))
112 return done(argc
, argv
);