]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #include <linux/module.h> |
2 | #include <linux/sched.h> | |
3 | #include <linux/ctype.h> | |
4 | #include <linux/fd.h> | |
5 | #include <linux/tty.h> | |
6 | #include <linux/suspend.h> | |
7 | #include <linux/root_dev.h> | |
8 | #include <linux/security.h> | |
9 | #include <linux/delay.h> | |
dd2a345f | 10 | #include <linux/genhd.h> |
d53d9f16 | 11 | #include <linux/mount.h> |
d779249e | 12 | #include <linux/device.h> |
46595390 | 13 | #include <linux/init.h> |
011e3fcd | 14 | #include <linux/fs.h> |
1da177e4 LT |
15 | |
16 | #include <linux/nfs_fs.h> | |
17 | #include <linux/nfs_fs_sb.h> | |
18 | #include <linux/nfs_mount.h> | |
19 | ||
20 | #include "do_mounts.h" | |
21 | ||
1da177e4 LT |
22 | int __initdata rd_doload; /* 1 = load RAM disk, 0 = don't load */ |
23 | ||
9b04c997 | 24 | int root_mountflags = MS_RDONLY | MS_SILENT; |
1da177e4 LT |
25 | char * __initdata root_device_name; |
26 | static char __initdata saved_root_name[64]; | |
cc1ed754 | 27 | static int __initdata root_wait; |
1da177e4 | 28 | |
1da177e4 LT |
29 | dev_t ROOT_DEV; |
30 | ||
1da177e4 LT |
31 | static int __init load_ramdisk(char *str) |
32 | { | |
33 | rd_doload = simple_strtol(str,NULL,0) & 3; | |
34 | return 1; | |
35 | } | |
36 | __setup("load_ramdisk=", load_ramdisk); | |
37 | ||
38 | static int __init readonly(char *str) | |
39 | { | |
40 | if (*str) | |
41 | return 0; | |
42 | root_mountflags |= MS_RDONLY; | |
43 | return 1; | |
44 | } | |
45 | ||
46 | static int __init readwrite(char *str) | |
47 | { | |
48 | if (*str) | |
49 | return 0; | |
50 | root_mountflags &= ~MS_RDONLY; | |
51 | return 1; | |
52 | } | |
53 | ||
54 | __setup("ro", readonly); | |
55 | __setup("rw", readwrite); | |
56 | ||
1da177e4 LT |
57 | /* |
58 | * Convert a name into device number. We accept the following variants: | |
59 | * | |
60 | * 1) device number in hexadecimal represents itself | |
61 | * 2) /dev/nfs represents Root_NFS (0xff) | |
62 | * 3) /dev/<disk_name> represents the device number of disk | |
63 | * 4) /dev/<disk_name><decimal> represents the device number | |
64 | * of partition - device number of disk plus the partition number | |
65 | * 5) /dev/<disk_name>p<decimal> - same as the above, that form is | |
66 | * used when disk name of partitioned disk ends on a digit. | |
67 | * | |
edfaa7c3 KS |
68 | * If name doesn't have fall into the categories above, we return (0,0). |
69 | * block_class is used to check if something is a disk name. If the disk | |
70 | * name contains slashes, the device name has them replaced with | |
71 | * bangs. | |
1da177e4 LT |
72 | */ |
73 | ||
74 | dev_t name_to_dev_t(char *name) | |
75 | { | |
76 | char s[32]; | |
77 | char *p; | |
78 | dev_t res = 0; | |
1da177e4 LT |
79 | |
80 | if (strncmp(name, "/dev/", 5) != 0) { | |
81 | unsigned maj, min; | |
82 | ||
83 | if (sscanf(name, "%u:%u", &maj, &min) == 2) { | |
84 | res = MKDEV(maj, min); | |
85 | if (maj != MAJOR(res) || min != MINOR(res)) | |
86 | goto fail; | |
87 | } else { | |
88 | res = new_decode_dev(simple_strtoul(name, &p, 16)); | |
89 | if (*p) | |
90 | goto fail; | |
91 | } | |
92 | goto done; | |
93 | } | |
edfaa7c3 | 94 | |
1da177e4 LT |
95 | name += 5; |
96 | res = Root_NFS; | |
97 | if (strcmp(name, "nfs") == 0) | |
98 | goto done; | |
99 | res = Root_RAM0; | |
100 | if (strcmp(name, "ram") == 0) | |
101 | goto done; | |
102 | ||
103 | if (strlen(name) > 31) | |
104 | goto fail; | |
105 | strcpy(s, name); | |
106 | for (p = s; *p; p++) | |
107 | if (*p == '/') | |
108 | *p = '!'; | |
edfaa7c3 | 109 | res = blk_lookup_devt(s); |
1da177e4 LT |
110 | if (res) |
111 | goto done; | |
112 | ||
edfaa7c3 KS |
113 | fail: |
114 | return 0; | |
1da177e4 | 115 | done: |
1da177e4 | 116 | return res; |
1da177e4 LT |
117 | } |
118 | ||
119 | static int __init root_dev_setup(char *line) | |
120 | { | |
121 | strlcpy(saved_root_name, line, sizeof(saved_root_name)); | |
122 | return 1; | |
123 | } | |
124 | ||
125 | __setup("root=", root_dev_setup); | |
126 | ||
cc1ed754 PO |
127 | static int __init rootwait_setup(char *str) |
128 | { | |
129 | if (*str) | |
130 | return 0; | |
131 | root_wait = 1; | |
132 | return 1; | |
133 | } | |
134 | ||
135 | __setup("rootwait", rootwait_setup); | |
136 | ||
1da177e4 LT |
137 | static char * __initdata root_mount_data; |
138 | static int __init root_data_setup(char *str) | |
139 | { | |
140 | root_mount_data = str; | |
141 | return 1; | |
142 | } | |
143 | ||
144 | static char * __initdata root_fs_names; | |
145 | static int __init fs_names_setup(char *str) | |
146 | { | |
147 | root_fs_names = str; | |
148 | return 1; | |
149 | } | |
150 | ||
151 | static unsigned int __initdata root_delay; | |
152 | static int __init root_delay_setup(char *str) | |
153 | { | |
154 | root_delay = simple_strtoul(str, NULL, 0); | |
155 | return 1; | |
156 | } | |
157 | ||
158 | __setup("rootflags=", root_data_setup); | |
159 | __setup("rootfstype=", fs_names_setup); | |
160 | __setup("rootdelay=", root_delay_setup); | |
161 | ||
162 | static void __init get_fs_names(char *page) | |
163 | { | |
164 | char *s = page; | |
165 | ||
166 | if (root_fs_names) { | |
167 | strcpy(page, root_fs_names); | |
168 | while (*s++) { | |
169 | if (s[-1] == ',') | |
170 | s[-1] = '\0'; | |
171 | } | |
172 | } else { | |
173 | int len = get_filesystem_list(page); | |
174 | char *p, *next; | |
175 | ||
176 | page[len] = '\0'; | |
177 | for (p = page-1; p; p = next) { | |
178 | next = strchr(++p, '\n'); | |
179 | if (*p++ != '\t') | |
180 | continue; | |
181 | while ((*s++ = *p++) != '\n') | |
182 | ; | |
183 | s[-1] = '\0'; | |
184 | } | |
185 | } | |
186 | *s = '\0'; | |
187 | } | |
188 | ||
189 | static int __init do_mount_root(char *name, char *fs, int flags, void *data) | |
190 | { | |
191 | int err = sys_mount(name, "/root", fs, flags, data); | |
192 | if (err) | |
193 | return err; | |
194 | ||
195 | sys_chdir("/root"); | |
6ac08c39 | 196 | ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev; |
1da177e4 | 197 | printk("VFS: Mounted root (%s filesystem)%s.\n", |
6ac08c39 JB |
198 | current->fs->pwd.mnt->mnt_sb->s_type->name, |
199 | current->fs->pwd.mnt->mnt_sb->s_flags & MS_RDONLY ? | |
1da177e4 LT |
200 | " readonly" : ""); |
201 | return 0; | |
202 | } | |
203 | ||
204 | void __init mount_block_root(char *name, int flags) | |
205 | { | |
206 | char *fs_names = __getname(); | |
207 | char *p; | |
9361401e | 208 | #ifdef CONFIG_BLOCK |
1da177e4 | 209 | char b[BDEVNAME_SIZE]; |
9361401e DH |
210 | #else |
211 | const char *b = name; | |
212 | #endif | |
1da177e4 LT |
213 | |
214 | get_fs_names(fs_names); | |
215 | retry: | |
216 | for (p = fs_names; *p; p += strlen(p)+1) { | |
217 | int err = do_mount_root(name, p, flags, root_mount_data); | |
218 | switch (err) { | |
219 | case 0: | |
220 | goto out; | |
221 | case -EACCES: | |
222 | flags |= MS_RDONLY; | |
223 | goto retry; | |
224 | case -EINVAL: | |
225 | continue; | |
226 | } | |
227 | /* | |
228 | * Allow the user to distinguish between failed sys_open | |
229 | * and bad superblock on root device. | |
dd2a345f | 230 | * and give them a list of the available devices |
1da177e4 | 231 | */ |
9361401e | 232 | #ifdef CONFIG_BLOCK |
1da177e4 | 233 | __bdevname(ROOT_DEV, b); |
9361401e | 234 | #endif |
1da177e4 LT |
235 | printk("VFS: Cannot open root device \"%s\" or %s\n", |
236 | root_device_name, b); | |
dd2a345f | 237 | printk("Please append a correct \"root=\" boot option; here are the available partitions:\n"); |
1da177e4 | 238 | |
dd2a345f | 239 | printk_all_partitions(); |
1da177e4 LT |
240 | panic("VFS: Unable to mount root fs on %s", b); |
241 | } | |
be6e028b | 242 | |
dd2a345f DG |
243 | printk("List of all partitions:\n"); |
244 | printk_all_partitions(); | |
be6e028b AW |
245 | printk("No filesystem could mount root, tried: "); |
246 | for (p = fs_names; *p; p += strlen(p)+1) | |
247 | printk(" %s", p); | |
248 | printk("\n"); | |
9361401e DH |
249 | #ifdef CONFIG_BLOCK |
250 | __bdevname(ROOT_DEV, b); | |
251 | #endif | |
252 | panic("VFS: Unable to mount root fs on %s", b); | |
1da177e4 LT |
253 | out: |
254 | putname(fs_names); | |
255 | } | |
256 | ||
257 | #ifdef CONFIG_ROOT_NFS | |
258 | static int __init mount_nfs_root(void) | |
259 | { | |
260 | void *data = nfs_root_data(); | |
261 | ||
bdaf8529 | 262 | create_dev("/dev/root", ROOT_DEV); |
1da177e4 LT |
263 | if (data && |
264 | do_mount_root("/dev/root", "nfs", root_mountflags, data) == 0) | |
265 | return 1; | |
266 | return 0; | |
267 | } | |
268 | #endif | |
269 | ||
270 | #if defined(CONFIG_BLK_DEV_RAM) || defined(CONFIG_BLK_DEV_FD) | |
271 | void __init change_floppy(char *fmt, ...) | |
272 | { | |
273 | struct termios termios; | |
274 | char buf[80]; | |
275 | char c; | |
276 | int fd; | |
277 | va_list args; | |
278 | va_start(args, fmt); | |
279 | vsprintf(buf, fmt, args); | |
280 | va_end(args); | |
281 | fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0); | |
282 | if (fd >= 0) { | |
283 | sys_ioctl(fd, FDEJECT, 0); | |
284 | sys_close(fd); | |
285 | } | |
286 | printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf); | |
287 | fd = sys_open("/dev/console", O_RDWR, 0); | |
288 | if (fd >= 0) { | |
289 | sys_ioctl(fd, TCGETS, (long)&termios); | |
290 | termios.c_lflag &= ~ICANON; | |
291 | sys_ioctl(fd, TCSETSF, (long)&termios); | |
292 | sys_read(fd, &c, 1); | |
293 | termios.c_lflag |= ICANON; | |
294 | sys_ioctl(fd, TCSETSF, (long)&termios); | |
295 | sys_close(fd); | |
296 | } | |
297 | } | |
298 | #endif | |
299 | ||
300 | void __init mount_root(void) | |
301 | { | |
302 | #ifdef CONFIG_ROOT_NFS | |
303 | if (MAJOR(ROOT_DEV) == UNNAMED_MAJOR) { | |
304 | if (mount_nfs_root()) | |
305 | return; | |
306 | ||
307 | printk(KERN_ERR "VFS: Unable to mount root fs via NFS, trying floppy.\n"); | |
308 | ROOT_DEV = Root_FD0; | |
309 | } | |
310 | #endif | |
311 | #ifdef CONFIG_BLK_DEV_FD | |
312 | if (MAJOR(ROOT_DEV) == FLOPPY_MAJOR) { | |
313 | /* rd_doload is 2 for a dual initrd/ramload setup */ | |
314 | if (rd_doload==2) { | |
315 | if (rd_load_disk(1)) { | |
316 | ROOT_DEV = Root_RAM1; | |
317 | root_device_name = NULL; | |
318 | } | |
319 | } else | |
320 | change_floppy("root floppy"); | |
321 | } | |
322 | #endif | |
9361401e | 323 | #ifdef CONFIG_BLOCK |
bdaf8529 | 324 | create_dev("/dev/root", ROOT_DEV); |
1da177e4 | 325 | mount_block_root("/dev/root", root_mountflags); |
9361401e | 326 | #endif |
1da177e4 LT |
327 | } |
328 | ||
329 | /* | |
330 | * Prepare the namespace - decide what/where to mount, load ramdisks, etc. | |
331 | */ | |
332 | void __init prepare_namespace(void) | |
333 | { | |
334 | int is_floppy; | |
335 | ||
1da177e4 LT |
336 | if (root_delay) { |
337 | printk(KERN_INFO "Waiting %dsec before mounting root device...\n", | |
338 | root_delay); | |
339 | ssleep(root_delay); | |
340 | } | |
341 | ||
d779249e GKH |
342 | /* wait for the known devices to complete their probing */ |
343 | while (driver_probe_done() != 0) | |
344 | msleep(100); | |
345 | ||
1da177e4 LT |
346 | md_run_setup(); |
347 | ||
348 | if (saved_root_name[0]) { | |
349 | root_device_name = saved_root_name; | |
e9482b43 JE |
350 | if (!strncmp(root_device_name, "mtd", 3)) { |
351 | mount_block_root(root_device_name, root_mountflags); | |
352 | goto out; | |
353 | } | |
1da177e4 LT |
354 | ROOT_DEV = name_to_dev_t(root_device_name); |
355 | if (strncmp(root_device_name, "/dev/", 5) == 0) | |
356 | root_device_name += 5; | |
357 | } | |
358 | ||
1da177e4 LT |
359 | if (initrd_load()) |
360 | goto out; | |
361 | ||
cc1ed754 PO |
362 | /* wait for any asynchronous scanning to complete */ |
363 | if ((ROOT_DEV == 0) && root_wait) { | |
364 | printk(KERN_INFO "Waiting for root device %s...\n", | |
365 | saved_root_name); | |
366 | while (driver_probe_done() != 0 || | |
367 | (ROOT_DEV = name_to_dev_t(saved_root_name)) == 0) | |
368 | msleep(100); | |
369 | } | |
370 | ||
371 | is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR; | |
372 | ||
1da177e4 LT |
373 | if (is_floppy && rd_doload && rd_load_disk(0)) |
374 | ROOT_DEV = Root_RAM0; | |
375 | ||
376 | mount_root(); | |
377 | out: | |
1da177e4 LT |
378 | sys_mount(".", "/", NULL, MS_MOVE, NULL); |
379 | sys_chroot("."); | |
1da177e4 LT |
380 | } |
381 |