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