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.c238
1 files changed, 111 insertions, 127 deletions
diff --git a/urunlevel/runlevel/local_fs.c b/urunlevel/runlevel/local_fs.c
index 17b45f6..137ff0a 100644
--- a/urunlevel/runlevel/local_fs.c
+++ b/urunlevel/runlevel/local_fs.c
@@ -3,6 +3,8 @@
3 * 3 *
4 * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au 4 * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au
5 * 5 *
6 * Originally based on code from Trinux.
7 *
6 * This program is free software; you can redistribute it and/or modify 8 * 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 9 * 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 10 * the Free Software Foundation; either version 2 of the License, or
@@ -27,62 +29,44 @@
27#include "lib_init_d.h" 29#include "lib_init_d.h"
28 30
29 31
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); 32static int start(struct init_d_handle_s *, int);
47static int status(struct init_d_handle_s *, int); 33static int status(struct init_d_handle_s *, int);
48static int stop(struct init_d_handle_s *, int); 34static int stop(struct init_d_handle_s *, int);
49 35
50 36
51static init_d_handle_t my_commands = 37static init_d_handle_t my_commands = {
52{ 38 &start,
53 &start, 39 &stop,
54 &stop, 40 NULL,
55 NULL, 41 NULL,
56 NULL, 42 &no_reload,
57 &no_reload, 43 NULL,
58 NULL, 44 &status,
59 &status, 45 NULL,
60 NULL, 46 "local_fs",
61 "local_fs", 47 NULL,
62 NULL, 48 NULL,
63 NULL, 49 NULL,
64 NULL, 50 INIT_D_BEGIN
65 INIT_D_BEGIN \ 51 INIT_D_PROV "$local_fs"
66 INIT_D_PROV "$local_fs" \ 52 INIT_D_DSTART "1 2 3 4 5"
67 INIT_D_DSTART "1 2 3 4 5" \ 53 INIT_D_DSTOP "0 6"
68 INIT_D_DSTOP "0 6" \ 54 INIT_D_SDESC "Mount all local file systems."
69 INIT_D_SDESC "Mount all local file systems." \ 55 INIT_D_DESC "Mount all local file systems."
70 INIT_D_DESC "Mount all local file systems." \ 56 INIT_D_CONT
71 INIT_D_CONT "Including any left over partitions not otherwise mounted." \ 57 "Including any left over partitions not otherwise mounted." INIT_D_END
72 INIT_D_END
73}; 58};
74 59
75 60
76static const char *i386_sys_types[] = 61static const char *i386_sys_types[] = {
77{ 62// " 0Empty",
78// " 0Empty", 63// " 1fat",
79// " 1fat", 64// " 4fat",
80// " 4fat", 65// " 6fat",
81// " 6fat", 66// " bvfat",
82// " bvfat",
83 " cvfat", 67 " cvfat",
84// " evfat", 68// " evfat",
85// " fvfat", 69// " fvfat",
86 "80minix", 70 "80minix",
87 "81minix", 71 "81minix",
88 "82swap", 72 "82swap",
@@ -94,98 +78,98 @@ static const char *i386_sys_types[] =
94 78
95int local_fs_main(int argc, char **argv) 79int local_fs_main(int argc, char **argv)
96{ 80{
97 return do_init_from_main(argc, argv, &my_commands); 81 return do_init_from_main(argc, argv, &my_commands);
98} 82}
99 83
100 84
101static int start(struct init_d_handle_s *init_d, int just_checking) 85static int start(struct init_d_handle_s *init_d, int just_checking)
102{ 86{
103 int i; 87 int i;
104 char *CMDLINE = 0; 88 char *CMDLINE = 0;
105 char *ROOT = 0; 89 char *ROOT = 0;
106 char *CDEV = 0; 90 char *CDEV = 0;
107 char *FDEV = 0; 91 char *FDEV = 0;
108 char *token; 92 char *token;
109 char *strtok_temp; 93 char *strtok_temp;
110 94
111sleep(5); // delay it for testing purposes 95 sleep(5); // delay it for testing purposes
112// Should fsck all non root partitions first. 96// Should fsck all non root partitions first.
113 doit(0, "/bin/mount -a"); 97 doit(0, "/bin/mount -a");
114 bb_xasprintf(&CMDLINE, "%s", doit(REDIR, "cat /proc/cmdline")); 98 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)) 99 for (token = strtok_r(CMDLINE, " \t\n\r", &strtok_temp); token != NULL;
116 { 100 token = strtok_r(NULL, " \t\n\r", &strtok_temp)) {
117 if (strncmp(token, "ROOT=", 5) == 0) 101 if (strncmp(token, "ROOT=", 5) == 0)
118 ROOT = &token[5]; 102 ROOT = &token[5];
119 } 103 }
120 104
121 bb_xasprintf(&CDEV, "%s", doit(REDIR, "dmesg | grep D-ROM | grep hd | cut -d: -f1 | sort | uniq")); 105 bb_xasprintf(&CDEV, "%s",
122 106 doit(REDIR,
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 : ""); 107 "dmesg | grep D-ROM | grep hd | cut -d: -f1 | sort | uniq"));
124 token = strtok_r(FDEV, " \r\n", &strtok_temp); 108
125 for (i = 0; token != NULL; i++) 109 bb_xasprintf(&FDEV, "%s %s",
126 { 110 doit(REDIR,
127 if (strlen(token) > 2) 111 "dmesg | grep -v LDM | grep \"^ [sh]d[a-f]\" | cut -d':' -f2 | sort | uniq"),
128 make_disk(token, nodes); 112 (CDEV != 0) ? CDEV : "");
129 token = strtok_r(NULL, " \r\n", &strtok_temp); 113 token = strtok_r(FDEV, " \r\n", &strtok_temp);
130 } 114 for (i = 0; token != NULL; i++) {
131 115 if (strlen(token) > 2)
132 bb_xasprintf(&FDEV, "%s", doit(REDIR, "fdisk -l | grep \"^/dev/\" | cut -b6-10,52-55")); 116 make_disk(token);
133 token = strtok_r(FDEV, "\r\n", &strtok_temp); 117 token = strtok_r(NULL, " \r\n", &strtok_temp);
134 for (i = 0; token != NULL; i++) 118 }
135 { 119
136 int j; 120 bb_xasprintf(&FDEV, "%s",
137 int found = 0; 121 doit(REDIR,
138 char *type = &token[6]; 122 "fdisk -l | grep \"^/dev/\" | cut -b6-10,52-55"));
139 token[4] = '\0'; 123 token = strtok_r(FDEV, "\r\n", &strtok_temp);
140 for (j = 0; i386_sys_types[j] != 0; j++) 124 for (i = 0; token != NULL; i++) {
141 { 125 int j;
142 if (strncmp(i386_sys_types[j], type, 2) == 0) 126 int found = 0;
143 { 127 char *type = &token[6];
144 char *DEV = 0; 128
145 char *MOUNT = 0; 129 token[4] = '\0';
146 char *TYPE = 0; 130 for (j = 0; i386_sys_types[j] != 0; j++) {
147 131 if (strncmp(i386_sys_types[j], type, 2) == 0) {
148 bb_xasprintf(&DEV, "/dev/%s", token); 132 char *DEV = 0;
149 bb_xasprintf(&MOUNT, "/media/%s", token); 133 char *MOUNT = 0;
150 bb_xasprintf(&TYPE, "%s", &i386_sys_types[j][2]); 134 char *TYPE = 0;
151 found = 1; 135
152 if (strncmp(&i386_sys_types[j][2], "swap", 4) == 0) 136 bb_xasprintf(&DEV, "/dev/%s", token);
153 { 137 bb_xasprintf(&MOUNT, "/media/%s", token);
154 doit(QUIET, "mkswap %s", DEV); 138 bb_xasprintf(&TYPE, "%s", &i386_sys_types[j][2]);
155 doit(QUIET, "swapon %s", DEV); 139 found = 1;
156 } 140 if (strncmp(&i386_sys_types[j][2], "swap", 4) == 0) {
157 else 141 doit(QUIET, "mkswap %s", DEV);
158 { 142 doit(QUIET, "swapon %s", DEV);
143 } else {
159// Should not mount it if it is already mounted. 144// Should not mount it if it is already mounted.
160 if ((ROOT == 0) || strcmp(ROOT, DEV) != 0) /* Don't try to remount ROOT, */ 145 if ((ROOT == 0) || strcmp(ROOT, DEV) != 0) { /* Don't try to remount ROOT, */
161 { 146 make_disk(token);
162 make_disk(token, nodes); 147 quick_mount(TYPE, DEV, MOUNT, "-o ro");
163 quick_mount(TYPE, DEV, MOUNT, "-o ro"); 148// quick_mount("auto", DEV, MOUNT, "-o ro");
164// quick_mount("auto", DEV, MOUNT, "-o ro"); 149 }
165 } 150 }
151
152 break;
153 }
166 } 154 }
155// if (found == 0)
156// bb_printf(" %s - unknown\n", token);
167 157
168 break; 158 token = strtok_r(NULL, "\r\n", &strtok_temp);
169 }
170 } 159 }
171// if (found == 0) 160
172// bb_printf(" %s - unknown\n", token); 161 free(FDEV);
173 162 free(CDEV);
174 token = strtok_r(NULL, "\r\n", &strtok_temp); 163 free(ROOT);
175 } 164 free(CMDLINE);
176 165
177 free(FDEV); 166 return INIT_D_OK;
178 free(CDEV);
179 free(ROOT);
180 free(CMDLINE);
181
182 return INIT_D_OK;
183} 167}
184 168
185 169
186static int status(struct init_d_handle_s *init_d, int quiet) 170static int status(struct init_d_handle_s *init_d, int quiet)
187{ 171{
188 return print_status(init_d, quiet, INIT_D_STATUS_OK); 172 return print_status(init_d, quiet, INIT_D_STATUS_OK);
189} 173}
190 174
191 175
@@ -193,7 +177,7 @@ static int stop(struct init_d_handle_s *init_d, int just_checking)
193{ 177{
194// Should only umount things we mounted in the first place. 178// Should only umount things we mounted in the first place.
195// Same for swap 179// Same for swap
196 doit(0, "/sbin/swapoff -a"); 180 doit(0, "/sbin/swapoff -a");
197 doit(0, "/bin/umount -a -r"); 181 doit(0, "/bin/umount -a -r");
198 return INIT_D_OK; 182 return INIT_D_OK;
199} 183}