md: rewrite md_setup_drive to avoid ioctls
[linux-block.git] / init / do_mounts.c
CommitLineData
457c8996 1// SPDX-License-Identifier: GPL-2.0-only
1da177e4
LT
2#include <linux/module.h>
3#include <linux/sched.h>
4#include <linux/ctype.h>
5#include <linux/fd.h>
6#include <linux/tty.h>
7#include <linux/suspend.h>
8#include <linux/root_dev.h>
9#include <linux/security.h>
10#include <linux/delay.h>
dd2a345f 11#include <linux/genhd.h>
d53d9f16 12#include <linux/mount.h>
d779249e 13#include <linux/device.h>
46595390 14#include <linux/init.h>
011e3fcd 15#include <linux/fs.h>
82c8253a 16#include <linux/initrd.h>
22a9d645 17#include <linux/async.h>
5ad4e53b 18#include <linux/fs_struct.h>
5a0e3ad6 19#include <linux/slab.h>
57f150a5 20#include <linux/ramfs.h>
16203a7a 21#include <linux/shmem_fs.h>
1da177e4
LT
22
23#include <linux/nfs_fs.h>
24#include <linux/nfs_fs_sb.h>
25#include <linux/nfs_mount.h>
4f5b246b 26#include <linux/raid/detect.h>
e262e32d 27#include <uapi/linux/mount.h>
1da177e4
LT
28
29#include "do_mounts.h"
30
1da177e4
LT
31int __initdata rd_doload; /* 1 = load RAM disk, 0 = don't load */
32
9b04c997 33int root_mountflags = MS_RDONLY | MS_SILENT;
f56f6d30 34static char * __initdata root_device_name;
1da177e4 35static char __initdata saved_root_name[64];
79975f13 36static int root_wait;
1da177e4 37
1da177e4
LT
38dev_t ROOT_DEV;
39
1da177e4
LT
40static int __init load_ramdisk(char *str)
41{
42 rd_doload = simple_strtol(str,NULL,0) & 3;
43 return 1;
44}
45__setup("load_ramdisk=", load_ramdisk);
46
47static int __init readonly(char *str)
48{
49 if (*str)
50 return 0;
51 root_mountflags |= MS_RDONLY;
52 return 1;
53}
54
55static int __init readwrite(char *str)
56{
57 if (*str)
58 return 0;
59 root_mountflags &= ~MS_RDONLY;
60 return 1;
61}
62
63__setup("ro", readonly);
64__setup("rw", readwrite);
65
6d0aed7a 66#ifdef CONFIG_BLOCK
1ad7e899
SW
67struct uuidcmp {
68 const char *uuid;
69 int len;
70};
71
b5af921e
WD
72/**
73 * match_dev_by_uuid - callback for finding a partition using its uuid
74 * @dev: device passed in by the caller
1ad7e899 75 * @data: opaque pointer to the desired struct uuidcmp to match
b5af921e
WD
76 *
77 * Returns 1 if the device matches, and 0 otherwise.
78 */
9f3b795a 79static int match_dev_by_uuid(struct device *dev, const void *data)
b5af921e 80{
9f3b795a 81 const struct uuidcmp *cmp = data;
b5af921e
WD
82 struct hd_struct *part = dev_to_part(dev);
83
84 if (!part->info)
85 goto no_match;
86
1ad7e899
SW
87 if (strncasecmp(cmp->uuid, part->info->uuid, cmp->len))
88 goto no_match;
b5af921e
WD
89
90 return 1;
91no_match:
92 return 0;
93}
94
95
96/**
97 * devt_from_partuuid - looks up the dev_t of a partition by its UUID
a68b3108 98 * @uuid_str: char array containing ascii UUID
b5af921e
WD
99 *
100 * The function will return the first partition which contains a matching
101 * UUID value in its partition_meta_info struct. This does not search
102 * by filesystem UUIDs.
103 *
a68b3108 104 * If @uuid_str is followed by a "/PARTNROFF=%d", then the number will be
79975f13
WD
105 * extracted and used as an offset from the partition identified by the UUID.
106 *
b5af921e
WD
107 * Returns the matching dev_t on success or 0 on failure.
108 */
1ad7e899 109static dev_t devt_from_partuuid(const char *uuid_str)
b5af921e
WD
110{
111 dev_t res = 0;
1ad7e899 112 struct uuidcmp cmp;
b5af921e 113 struct device *dev = NULL;
79975f13
WD
114 struct gendisk *disk;
115 struct hd_struct *part;
116 int offset = 0;
283f8fc0
SW
117 bool clear_root_wait = false;
118 char *slash;
79975f13 119
1ad7e899 120 cmp.uuid = uuid_str;
1ad7e899 121
283f8fc0 122 slash = strchr(uuid_str, '/');
79975f13 123 /* Check for optional partition number offset attributes. */
283f8fc0 124 if (slash) {
79975f13
WD
125 char c = 0;
126 /* Explicitly fail on poor PARTUUID syntax. */
283f8fc0
SW
127 if (sscanf(slash + 1,
128 "PARTNROFF=%d%c", &offset, &c) != 1) {
129 clear_root_wait = true;
79975f13
WD
130 goto done;
131 }
283f8fc0
SW
132 cmp.len = slash - uuid_str;
133 } else {
134 cmp.len = strlen(uuid_str);
135 }
136
137 if (!cmp.len) {
138 clear_root_wait = true;
139 goto done;
79975f13 140 }
b5af921e 141
1ad7e899
SW
142 dev = class_find_device(&block_class, NULL, &cmp,
143 &match_dev_by_uuid);
b5af921e
WD
144 if (!dev)
145 goto done;
146
147 res = dev->devt;
b5af921e 148
79975f13
WD
149 /* Attempt to find the partition by offset. */
150 if (!offset)
151 goto no_offset;
152
153 res = 0;
154 disk = part_to_disk(dev_to_part(dev));
155 part = disk_get_part(disk, dev_to_part(dev)->partno + offset);
156 if (part) {
157 res = part_devt(part);
158 put_device(part_to_dev(part));
159 }
160
161no_offset:
162 put_device(dev);
b5af921e 163done:
283f8fc0
SW
164 if (clear_root_wait) {
165 pr_err("VFS: PARTUUID= is invalid.\n"
166 "Expected PARTUUID=<valid-uuid-id>[/PARTNROFF=%%d]\n");
167 if (root_wait)
168 pr_err("Disabling rootwait; root= is invalid.\n");
169 root_wait = 0;
170 }
b5af921e
WD
171 return res;
172}
f027c34d
NV
173
174/**
175 * match_dev_by_label - callback for finding a partition using its label
176 * @dev: device passed in by the caller
177 * @data: opaque pointer to the label to match
178 *
179 * Returns 1 if the device matches, and 0 otherwise.
180 */
181static int match_dev_by_label(struct device *dev, const void *data)
182{
183 const char *label = data;
184 struct hd_struct *part = dev_to_part(dev);
185
186 if (part->info && !strcmp(label, part->info->volname))
187 return 1;
188
189 return 0;
190}
6d0aed7a 191#endif
b5af921e 192
1da177e4
LT
193/*
194 * Convert a name into device number. We accept the following variants:
195 *
0bf37ae4
PM
196 * 1) <hex_major><hex_minor> device number in hexadecimal represents itself
197 * no leading 0x, for example b302.
1da177e4
LT
198 * 2) /dev/nfs represents Root_NFS (0xff)
199 * 3) /dev/<disk_name> represents the device number of disk
200 * 4) /dev/<disk_name><decimal> represents the device number
201 * of partition - device number of disk plus the partition number
202 * 5) /dev/<disk_name>p<decimal> - same as the above, that form is
203 * used when disk name of partitioned disk ends on a digit.
b5af921e
WD
204 * 6) PARTUUID=00112233-4455-6677-8899-AABBCCDDEEFF representing the
205 * unique id of a partition if the partition table provides it.
d33b98fc
SW
206 * The UUID may be either an EFI/GPT UUID, or refer to an MSDOS
207 * partition using the format SSSSSSSS-PP, where SSSSSSSS is a zero-
208 * filled hex representation of the 32-bit "NT disk signature", and PP
209 * is a zero-filled hex representation of the 1-based partition number.
79975f13
WD
210 * 7) PARTUUID=<UUID>/PARTNROFF=<int> to select a partition in relation to
211 * a partition with a known unique id.
6c251611
SC
212 * 8) <major>:<minor> major and minor number of the device separated by
213 * a colon.
f027c34d
NV
214 * 9) PARTLABEL=<name> with name being the GPT partition label.
215 * MSDOS partitions do not support labels!
8902dd52 216 * 10) /dev/cifs represents Root_CIFS (0xfe)
1da177e4 217 *
edfaa7c3
KS
218 * If name doesn't have fall into the categories above, we return (0,0).
219 * block_class is used to check if something is a disk name. If the disk
220 * name contains slashes, the device name has them replaced with
221 * bangs.
1da177e4
LT
222 */
223
e6e20a7a 224dev_t name_to_dev_t(const char *name)
1da177e4
LT
225{
226 char s[32];
227 char *p;
228 dev_t res = 0;
30f2f0eb 229 int part;
1da177e4 230
6d0aed7a 231#ifdef CONFIG_BLOCK
b5af921e
WD
232 if (strncmp(name, "PARTUUID=", 9) == 0) {
233 name += 9;
b5af921e
WD
234 res = devt_from_partuuid(name);
235 if (!res)
236 goto fail;
237 goto done;
f027c34d
NV
238 } else if (strncmp(name, "PARTLABEL=", 10) == 0) {
239 struct device *dev;
240
241 dev = class_find_device(&block_class, NULL, name + 10,
242 &match_dev_by_label);
243 if (!dev)
244 goto fail;
245
246 res = dev->devt;
247 put_device(dev);
248 goto done;
b5af921e 249 }
6d0aed7a 250#endif
b5af921e 251
1da177e4 252 if (strncmp(name, "/dev/", 5) != 0) {
cb31ef48 253 unsigned maj, min, offset;
283e7ad0 254 char dummy;
1da177e4 255
cb31ef48
CY
256 if ((sscanf(name, "%u:%u%c", &maj, &min, &dummy) == 2) ||
257 (sscanf(name, "%u:%u:%u:%c", &maj, &min, &offset, &dummy) == 3)) {
1da177e4
LT
258 res = MKDEV(maj, min);
259 if (maj != MAJOR(res) || min != MINOR(res))
260 goto fail;
261 } else {
262 res = new_decode_dev(simple_strtoul(name, &p, 16));
263 if (*p)
264 goto fail;
265 }
266 goto done;
267 }
edfaa7c3 268
1da177e4
LT
269 name += 5;
270 res = Root_NFS;
271 if (strcmp(name, "nfs") == 0)
272 goto done;
8902dd52
PAS
273 res = Root_CIFS;
274 if (strcmp(name, "cifs") == 0)
275 goto done;
1da177e4
LT
276 res = Root_RAM0;
277 if (strcmp(name, "ram") == 0)
278 goto done;
279
280 if (strlen(name) > 31)
281 goto fail;
282 strcpy(s, name);
283 for (p = s; *p; p++)
284 if (*p == '/')
285 *p = '!';
30f2f0eb
KS
286 res = blk_lookup_devt(s, 0);
287 if (res)
288 goto done;
289
290 /*
25985edc 291 * try non-existent, but valid partition, which may only exist
30f2f0eb
KS
292 * after revalidating the disk, like partitioned md devices
293 */
294 while (p > s && isdigit(p[-1]))
295 p--;
296 if (p == s || !*p || *p == '0')
297 goto fail;
298
299 /* try disk name without <part number> */
300 part = simple_strtoul(p, NULL, 10);
301 *p = '\0';
302 res = blk_lookup_devt(s, part);
303 if (res)
304 goto done;
305
306 /* try disk name without p<part number> */
307 if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p')
308 goto fail;
309 p[-1] = '\0';
310 res = blk_lookup_devt(s, part);
1da177e4
LT
311 if (res)
312 goto done;
313
edfaa7c3
KS
314fail:
315 return 0;
1da177e4 316done:
1da177e4 317 return res;
1da177e4 318}
e6e20a7a 319EXPORT_SYMBOL_GPL(name_to_dev_t);
1da177e4
LT
320
321static int __init root_dev_setup(char *line)
322{
323 strlcpy(saved_root_name, line, sizeof(saved_root_name));
324 return 1;
325}
326
327__setup("root=", root_dev_setup);
328
cc1ed754
PO
329static int __init rootwait_setup(char *str)
330{
331 if (*str)
332 return 0;
333 root_wait = 1;
334 return 1;
335}
336
337__setup("rootwait", rootwait_setup);
338
1da177e4
LT
339static char * __initdata root_mount_data;
340static int __init root_data_setup(char *str)
341{
342 root_mount_data = str;
343 return 1;
344}
345
346static char * __initdata root_fs_names;
347static int __init fs_names_setup(char *str)
348{
349 root_fs_names = str;
350 return 1;
351}
352
353static unsigned int __initdata root_delay;
354static int __init root_delay_setup(char *str)
355{
356 root_delay = simple_strtoul(str, NULL, 0);
357 return 1;
358}
359
360__setup("rootflags=", root_data_setup);
361__setup("rootfstype=", fs_names_setup);
362__setup("rootdelay=", root_delay_setup);
363
364static void __init get_fs_names(char *page)
365{
366 char *s = page;
367
368 if (root_fs_names) {
369 strcpy(page, root_fs_names);
370 while (*s++) {
371 if (s[-1] == ',')
372 s[-1] = '\0';
373 }
374 } else {
375 int len = get_filesystem_list(page);
376 char *p, *next;
377
378 page[len] = '\0';
379 for (p = page-1; p; p = next) {
380 next = strchr(++p, '\n');
381 if (*p++ != '\t')
382 continue;
383 while ((*s++ = *p++) != '\n')
384 ;
385 s[-1] = '\0';
386 }
387 }
388 *s = '\0';
389}
390
cccaa5e3
DB
391static int __init do_mount_root(const char *name, const char *fs,
392 const int flags, const void *data)
1da177e4 393{
d8c9584e 394 struct super_block *s;
7de7de7c
LT
395 struct page *p = NULL;
396 char *data_page = NULL;
cccaa5e3
DB
397 int ret;
398
7de7de7c
LT
399 if (data) {
400 /* do_mount() requires a full page as fifth argument */
401 p = alloc_page(GFP_KERNEL);
402 if (!p)
403 return -ENOMEM;
404 data_page = page_address(p);
405 /* zero-pad. do_mount() will make sure it's terminated */
406 strncpy(data_page, data, PAGE_SIZE);
407 }
cccaa5e3
DB
408
409 ret = do_mount(name, "/root", fs, flags, data_page);
410 if (ret)
411 goto out;
1da177e4 412
447016e9 413 ksys_chdir("/root");
d8c9584e
AV
414 s = current->fs->pwd.dentry->d_sb;
415 ROOT_DEV = s->s_dev;
80cdc6da
MSB
416 printk(KERN_INFO
417 "VFS: Mounted root (%s filesystem)%s on device %u:%u.\n",
d8c9584e 418 s->s_type->name,
bc98a42c 419 sb_rdonly(s) ? " readonly" : "",
d8c9584e 420 MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
cccaa5e3
DB
421
422out:
7de7de7c
LT
423 if (p)
424 put_page(p);
cccaa5e3 425 return ret;
1da177e4
LT
426}
427
428void __init mount_block_root(char *name, int flags)
429{
75f296d9 430 struct page *page = alloc_page(GFP_KERNEL);
a608ca21 431 char *fs_names = page_address(page);
1da177e4
LT
432 char *p;
433 char b[BDEVNAME_SIZE];
434
ea3edd4d
CH
435 scnprintf(b, BDEVNAME_SIZE, "unknown-block(%u,%u)",
436 MAJOR(ROOT_DEV), MINOR(ROOT_DEV));
1da177e4
LT
437 get_fs_names(fs_names);
438retry:
439 for (p = fs_names; *p; p += strlen(p)+1) {
440 int err = do_mount_root(name, p, flags, root_mount_data);
441 switch (err) {
442 case 0:
443 goto out;
444 case -EACCES:
1da177e4
LT
445 case -EINVAL:
446 continue;
447 }
448 /*
449 * Allow the user to distinguish between failed sys_open
450 * and bad superblock on root device.
dd2a345f 451 * and give them a list of the available devices
1da177e4 452 */
0e0cb892
BW
453 printk("VFS: Cannot open root device \"%s\" or %s: error %d\n",
454 root_device_name, b, err);
dd2a345f 455 printk("Please append a correct \"root=\" boot option; here are the available partitions:\n");
1da177e4 456
dd2a345f 457 printk_all_partitions();
55dc7db7
TH
458#ifdef CONFIG_DEBUG_BLOCK_EXT_DEVT
459 printk("DEBUG_BLOCK_EXT_DEVT is enabled, you need to specify "
460 "explicit textual name for \"root=\" boot option.\n");
461#endif
1da177e4
LT
462 panic("VFS: Unable to mount root fs on %s", b);
463 }
e462ec50
DH
464 if (!(flags & SB_RDONLY)) {
465 flags |= SB_RDONLY;
10975933
MS
466 goto retry;
467 }
be6e028b 468
dd2a345f
DG
469 printk("List of all partitions:\n");
470 printk_all_partitions();
be6e028b
AW
471 printk("No filesystem could mount root, tried: ");
472 for (p = fs_names; *p; p += strlen(p)+1)
473 printk(" %s", p);
474 printk("\n");
9361401e 475 panic("VFS: Unable to mount root fs on %s", b);
1da177e4 476out:
a608ca21 477 put_page(page);
1da177e4
LT
478}
479
480#ifdef CONFIG_ROOT_NFS
43717c7d
CL
481
482#define NFSROOT_TIMEOUT_MIN 5
483#define NFSROOT_TIMEOUT_MAX 30
484#define NFSROOT_RETRY_MAX 5
485
1da177e4
LT
486static int __init mount_nfs_root(void)
487{
56463e50 488 char *root_dev, *root_data;
43717c7d
CL
489 unsigned int timeout;
490 int try, err;
1da177e4 491
43717c7d
CL
492 err = nfs_root_data(&root_dev, &root_data);
493 if (err != 0)
56463e50 494 return 0;
43717c7d
CL
495
496 /*
497 * The server or network may not be ready, so try several
498 * times. Stop after a few tries in case the client wants
499 * to fall back to other boot methods.
500 */
501 timeout = NFSROOT_TIMEOUT_MIN;
502 for (try = 1; ; try++) {
503 err = do_mount_root(root_dev, "nfs",
504 root_mountflags, root_data);
505 if (err == 0)
506 return 1;
507 if (try > NFSROOT_RETRY_MAX)
508 break;
509
510 /* Wait, in case the server refused us immediately */
511 ssleep(timeout);
512 timeout <<= 1;
513 if (timeout > NFSROOT_TIMEOUT_MAX)
514 timeout = NFSROOT_TIMEOUT_MAX;
515 }
516 return 0;
1da177e4
LT
517}
518#endif
519
8902dd52
PAS
520#ifdef CONFIG_CIFS_ROOT
521
522extern int cifs_root_data(char **dev, char **opts);
523
524#define CIFSROOT_TIMEOUT_MIN 5
525#define CIFSROOT_TIMEOUT_MAX 30
526#define CIFSROOT_RETRY_MAX 5
527
528static int __init mount_cifs_root(void)
529{
530 char *root_dev, *root_data;
531 unsigned int timeout;
532 int try, err;
533
534 err = cifs_root_data(&root_dev, &root_data);
535 if (err != 0)
536 return 0;
537
538 timeout = CIFSROOT_TIMEOUT_MIN;
539 for (try = 1; ; try++) {
540 err = do_mount_root(root_dev, "cifs", root_mountflags,
541 root_data);
542 if (err == 0)
543 return 1;
544 if (try > CIFSROOT_RETRY_MAX)
545 break;
546
547 ssleep(timeout);
548 timeout <<= 1;
549 if (timeout > CIFSROOT_TIMEOUT_MAX)
550 timeout = CIFSROOT_TIMEOUT_MAX;
551 }
552 return 0;
553}
554#endif
555
1da177e4
LT
556#if defined(CONFIG_BLK_DEV_RAM) || defined(CONFIG_BLK_DEV_FD)
557void __init change_floppy(char *fmt, ...)
558{
559 struct termios termios;
560 char buf[80];
561 char c;
562 int fd;
563 va_list args;
564 va_start(args, fmt);
565 vsprintf(buf, fmt, args);
566 va_end(args);
bae217ea 567 fd = ksys_open("/dev/root", O_RDWR | O_NDELAY, 0);
1da177e4 568 if (fd >= 0) {
cbb60b92 569 ksys_ioctl(fd, FDEJECT, 0);
2ca2a09d 570 ksys_close(fd);
1da177e4
LT
571 }
572 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
bae217ea 573 fd = ksys_open("/dev/console", O_RDWR, 0);
1da177e4 574 if (fd >= 0) {
cbb60b92 575 ksys_ioctl(fd, TCGETS, (long)&termios);
1da177e4 576 termios.c_lflag &= ~ICANON;
cbb60b92 577 ksys_ioctl(fd, TCSETSF, (long)&termios);
3ce4a7bf 578 ksys_read(fd, &c, 1);
1da177e4 579 termios.c_lflag |= ICANON;
cbb60b92 580 ksys_ioctl(fd, TCSETSF, (long)&termios);
2ca2a09d 581 ksys_close(fd);
1da177e4
LT
582 }
583}
584#endif
585
586void __init mount_root(void)
587{
588#ifdef CONFIG_ROOT_NFS
377485f6 589 if (ROOT_DEV == Root_NFS) {
1da177e4
LT
590 if (mount_nfs_root())
591 return;
592
593 printk(KERN_ERR "VFS: Unable to mount root fs via NFS, trying floppy.\n");
594 ROOT_DEV = Root_FD0;
595 }
596#endif
8902dd52
PAS
597#ifdef CONFIG_CIFS_ROOT
598 if (ROOT_DEV == Root_CIFS) {
599 if (mount_cifs_root())
600 return;
601
602 printk(KERN_ERR "VFS: Unable to mount root fs via SMB, trying floppy.\n");
603 ROOT_DEV = Root_FD0;
604 }
605#endif
1da177e4
LT
606#ifdef CONFIG_BLK_DEV_FD
607 if (MAJOR(ROOT_DEV) == FLOPPY_MAJOR) {
608 /* rd_doload is 2 for a dual initrd/ramload setup */
609 if (rd_doload==2) {
610 if (rd_load_disk(1)) {
611 ROOT_DEV = Root_RAM1;
612 root_device_name = NULL;
613 }
614 } else
615 change_floppy("root floppy");
616 }
617#endif
9361401e 618#ifdef CONFIG_BLOCK
c69e3c3a
VPS
619 {
620 int err = create_dev("/dev/root", ROOT_DEV);
621
622 if (err < 0)
623 pr_emerg("Failed to create /dev/root: %d\n", err);
624 mount_block_root("/dev/root", root_mountflags);
625 }
9361401e 626#endif
1da177e4
LT
627}
628
629/*
630 * Prepare the namespace - decide what/where to mount, load ramdisks, etc.
631 */
632void __init prepare_namespace(void)
633{
634 int is_floppy;
635
1da177e4 636 if (root_delay) {
ca75b4d8 637 printk(KERN_INFO "Waiting %d sec before mounting root device...\n",
1da177e4
LT
638 root_delay);
639 ssleep(root_delay);
640 }
641
216773a7
AV
642 /*
643 * wait for the known devices to complete their probing
644 *
645 * Note: this is a potential source of long boot delays.
646 * For example, it is not atypical to wait 5 seconds here
647 * for the touchpad of a laptop to initialize.
648 */
649 wait_for_device_probe();
d779249e 650
1da177e4
LT
651 md_run_setup();
652
653 if (saved_root_name[0]) {
654 root_device_name = saved_root_name;
2d62f488
AH
655 if (!strncmp(root_device_name, "mtd", 3) ||
656 !strncmp(root_device_name, "ubi", 3)) {
e9482b43
JE
657 mount_block_root(root_device_name, root_mountflags);
658 goto out;
659 }
1da177e4
LT
660 ROOT_DEV = name_to_dev_t(root_device_name);
661 if (strncmp(root_device_name, "/dev/", 5) == 0)
662 root_device_name += 5;
663 }
664
1da177e4
LT
665 if (initrd_load())
666 goto out;
667
cc1ed754
PO
668 /* wait for any asynchronous scanning to complete */
669 if ((ROOT_DEV == 0) && root_wait) {
670 printk(KERN_INFO "Waiting for root device %s...\n",
671 saved_root_name);
672 while (driver_probe_done() != 0 ||
673 (ROOT_DEV = name_to_dev_t(saved_root_name)) == 0)
39a0e975 674 msleep(5);
216773a7 675 async_synchronize_full();
cc1ed754
PO
676 }
677
678 is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
679
1da177e4
LT
680 if (is_floppy && rd_doload && rd_load_disk(0))
681 ROOT_DEV = Root_RAM0;
682
683 mount_root();
684out:
5e787dbf 685 devtmpfs_mount();
cccaa5e3 686 do_mount(".", "/", NULL, MS_MOVE, NULL);
a16fe33a 687 ksys_chroot(".");
1da177e4 688}
57f150a5 689
6e19eded 690static bool is_tmpfs;
f3235626 691static int rootfs_init_fs_context(struct fs_context *fc)
57f150a5 692{
6e19eded 693 if (IS_ENABLED(CONFIG_TMPFS) && is_tmpfs)
f3235626 694 return shmem_init_fs_context(fc);
6e19eded 695
f3235626 696 return ramfs_init_fs_context(fc);
57f150a5
RL
697}
698
fd3e007f 699struct file_system_type rootfs_fs_type = {
57f150a5 700 .name = "rootfs",
f3235626 701 .init_fs_context = rootfs_init_fs_context,
57f150a5
RL
702 .kill_sb = kill_litter_super,
703};
704
037f11b4 705void __init init_rootfs(void)
57f150a5 706{
6e19eded 707 if (IS_ENABLED(CONFIG_TMPFS) && !saved_root_name[0] &&
037f11b4 708 (!root_fs_names || strstr(root_fs_names, "tmpfs")))
6e19eded 709 is_tmpfs = true;
57f150a5 710}