ubi: remove voltype left-over variable
[project/fstools.git] / mount_root.c
1 /*
2 * Copyright (C) 2014 John Crispin <blogic@openwrt.org>
3 *
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
7 *
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.
12 */
13
14 #include <sys/mount.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17
18 #include "libfstools/libfstools.h"
19 #include "libfstools/volume.h"
20
21 static int
22 start(int argc, char *argv[1])
23 {
24 struct volume *v = volume_find("rootfs_data");
25
26 if (!getenv("PREINIT"))
27 return -1;
28
29 if (!v) {
30 v = volume_find("rootfs");
31 volume_init(v);
32 fprintf(stderr, "mounting /dev/root\n");
33 mount("/dev/root", "/", NULL, MS_NOATIME | MS_REMOUNT, 0);
34 return 0;
35 }
36
37 extroot_prefix = "";
38 if (!mount_extroot()) {
39 fprintf(stderr, "fs-state: switched to extroot\n");
40 return 0;
41 }
42
43 switch (volume_identify(v)) {
44 case FS_NONE:
45 case FS_DEADCODE:
46 return ramoverlay();
47
48 case FS_JFFS2:
49 case FS_UBIFS:
50 mount_overlay();
51 break;
52
53 case FS_SNAPSHOT:
54 mount_snapshot();
55 break;
56 }
57
58 return 0;
59 }
60
61 static int
62 stop(int argc, char *argv[1])
63 {
64 if (!getenv("SHUTDOWN"))
65 return -1;
66
67 return 0;
68 }
69
70 static int
71 done(int argc, char *argv[1])
72 {
73 struct volume *v = volume_find("rootfs_data");
74
75 if (!v)
76 return -1;
77
78 switch (volume_identify(v)) {
79 case FS_NONE:
80 case FS_DEADCODE:
81 return jffs2_switch(argc, argv);
82 }
83
84 return 0;
85 }
86
87 int main(int argc, char **argv)
88 {
89 if (argc < 2)
90 return start(argc, argv);
91 if (!strcmp(argv[1], "stop"))
92 return stop(argc, argv);
93 if (!strcmp(argv[1], "done"))
94 return done(argc, argv);
95 return -1;
96 }