summaryrefslogtreecommitdiffstats
path: root/urunlevel/runlevel/local_fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'urunlevel/runlevel/local_fs.c')
-rw-r--r--urunlevel/runlevel/local_fs.c199
1 files changed, 199 insertions, 0 deletions
diff --git a/urunlevel/runlevel/local_fs.c b/urunlevel/runlevel/local_fs.c
new file mode 100644
index 0000000..17b45f6
--- /dev/null
+++ b/urunlevel/runlevel/local_fs.c
@@ -0,0 +1,199 @@
1/*
2 * Mini $local_fs boot implementation for busybox.
3 *
4 * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 * 02111-1307 USA
20 *
21 */
22
23#include <string.h>
24#include <unistd.h>
25
26#include "busybox.h"
27#include "lib_init_d.h"
28
29
30const static nodes_t nodes[] =
31{
32 {"hda", S_IFBLK, 3, 0, 0},
33 {"hdb", S_IFBLK, 3, 64, 0},
34 {"hdc", S_IFBLK, 22, 0, 0},
35 {"hdd", S_IFBLK, 22, 64, 0},
36 {"ram", S_IFBLK, 1, 0, 9},
37 {"fd", S_IFBLK, 2, 0, 1},
38 {"loop", S_IFBLK, 7, 0,63},
39 {"cloop", S_IFBLK, 240, 0, 7},
40 {"vcs", S_IFBLK, 7, 0, 9},
41 {"vcsa", S_IFBLK, 7, 0, 9},
42 {0, 0, 0, 0, 0}
43};
44
45
46static int start(struct init_d_handle_s *, int);
47static int status(struct init_d_handle_s *, int);
48static int stop(struct init_d_handle_s *, int);
49
50
51static init_d_handle_t my_commands =
52{
53 &start,
54 &stop,
55 NULL,
56 NULL,
57 &no_reload,
58 NULL,
59 &status,
60 NULL,
61 "local_fs",
62 NULL,
63 NULL,
64 NULL,
65 INIT_D_BEGIN \
66 INIT_D_PROV "$local_fs" \
67 INIT_D_DSTART "1 2 3 4 5" \
68 INIT_D_DSTOP "0 6" \
69 INIT_D_SDESC "Mount all local file systems." \
70 INIT_D_DESC "Mount all local file systems." \
71 INIT_D_CONT "Including any left over partitions not otherwise mounted." \
72 INIT_D_END
73};
74
75
76static const char *i386_sys_types[] =
77{
78// " 0Empty",
79// " 1fat",
80// " 4fat",
81// " 6fat",
82// " bvfat",
83 " cvfat",
84// " evfat",
85// " fvfat",
86 "80minix",
87 "81minix",
88 "82swap",
89 "83ext2",
90 "85Linux extended",
91 0
92};
93
94
95int local_fs_main(int argc, char **argv)
96{
97 return do_init_from_main(argc, argv, &my_commands);
98}
99
100
101static int start(struct init_d_handle_s *init_d, int just_checking)
102{
103 int i;
104 char *CMDLINE = 0;
105 char *ROOT = 0;
106 char *CDEV = 0;
107 char *FDEV = 0;
108 char *token;
109 char *strtok_temp;
110
111sleep(5); // delay it for testing purposes
112// Should fsck all non root partitions first.
113 doit(0, "/bin/mount -a");
114 bb_xasprintf(&CMDLINE, "%s", doit(REDIR, "cat /proc/cmdline"));
115 for (token = strtok_r(CMDLINE, " \t\n\r", &strtok_temp); token != NULL; token = strtok_r(NULL, " \t\n\r", &strtok_temp))
116 {
117 if (strncmp(token, "ROOT=", 5) == 0)
118 ROOT = &token[5];
119 }
120
121 bb_xasprintf(&CDEV, "%s", doit(REDIR, "dmesg | grep D-ROM | grep hd | cut -d: -f1 | sort | uniq"));
122
123 bb_xasprintf(&FDEV, "%s %s", doit(REDIR, "dmesg | grep -v LDM | grep \"^ [sh]d[a-f]\" | cut -d':' -f2 | sort | uniq"), (CDEV != 0) ? CDEV : "");
124 token = strtok_r(FDEV, " \r\n", &strtok_temp);
125 for (i = 0; token != NULL; i++)
126 {
127 if (strlen(token) > 2)
128 make_disk(token, nodes);
129 token = strtok_r(NULL, " \r\n", &strtok_temp);
130 }
131
132 bb_xasprintf(&FDEV, "%s", doit(REDIR, "fdisk -l | grep \"^/dev/\" | cut -b6-10,52-55"));
133 token = strtok_r(FDEV, "\r\n", &strtok_temp);
134 for (i = 0; token != NULL; i++)
135 {
136 int j;
137 int found = 0;
138 char *type = &token[6];
139 token[4] = '\0';
140 for (j = 0; i386_sys_types[j] != 0; j++)
141 {
142 if (strncmp(i386_sys_types[j], type, 2) == 0)
143 {
144 char *DEV = 0;
145 char *MOUNT = 0;
146 char *TYPE = 0;
147
148 bb_xasprintf(&DEV, "/dev/%s", token);
149 bb_xasprintf(&MOUNT, "/media/%s", token);
150 bb_xasprintf(&TYPE, "%s", &i386_sys_types[j][2]);
151 found = 1;
152 if (strncmp(&i386_sys_types[j][2], "swap", 4) == 0)
153 {
154 doit(QUIET, "mkswap %s", DEV);
155 doit(QUIET, "swapon %s", DEV);
156 }
157 else
158 {
159// Should not mount it if it is already mounted.
160 if ((ROOT == 0) || strcmp(ROOT, DEV) != 0) /* Don't try to remount ROOT, */
161 {
162 make_disk(token, nodes);
163 quick_mount(TYPE, DEV, MOUNT, "-o ro");
164// quick_mount("auto", DEV, MOUNT, "-o ro");
165 }
166 }
167
168 break;
169 }
170 }
171// if (found == 0)
172// bb_printf(" %s - unknown\n", token);
173
174 token = strtok_r(NULL, "\r\n", &strtok_temp);
175 }
176
177 free(FDEV);
178 free(CDEV);
179 free(ROOT);
180 free(CMDLINE);
181
182 return INIT_D_OK;
183}
184
185
186static int status(struct init_d_handle_s *init_d, int quiet)
187{
188 return print_status(init_d, quiet, INIT_D_STATUS_OK);
189}
190
191
192static int stop(struct init_d_handle_s *init_d, int just_checking)
193{
194// Should only umount things we mounted in the first place.
195// Same for swap
196 doit(0, "/sbin/swapoff -a");
197 doit(0, "/bin/umount -a -r");
198 return INIT_D_OK;
199}