hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/init/do_mounts_initrd.c
....@@ -8,6 +8,7 @@
88 #include <linux/sched.h>
99 #include <linux/freezer.h>
1010 #include <linux/kmod.h>
11
+#include <uapi/linux/mount.h>
1112
1213 #include "do_mounts.h"
1314
....@@ -15,6 +16,9 @@
1516 int initrd_below_start_ok;
1617 unsigned int real_root_dev; /* do_proc_dointvec cannot handle kdev_t */
1718 static int __initdata mount_initrd = 1;
19
+
20
+phys_addr_t phys_initrd_start __initdata;
21
+unsigned long phys_initrd_size __initdata;
1822
1923 static int __init no_initrd(char *str)
2024 {
....@@ -24,17 +28,37 @@
2428
2529 __setup("noinitrd", no_initrd);
2630
27
-static int init_linuxrc(struct subprocess_info *info, struct cred *new)
31
+static int __init early_initrdmem(char *p)
32
+{
33
+ phys_addr_t start;
34
+ unsigned long size;
35
+ char *endp;
36
+
37
+ start = memparse(p, &endp);
38
+ if (*endp == ',') {
39
+ size = memparse(endp + 1, NULL);
40
+
41
+ phys_initrd_start = start;
42
+ phys_initrd_size = size;
43
+ }
44
+ return 0;
45
+}
46
+early_param("initrdmem", early_initrdmem);
47
+
48
+static int __init early_initrd(char *p)
49
+{
50
+ return early_initrdmem(p);
51
+}
52
+early_param("initrd", early_initrd);
53
+
54
+static int __init init_linuxrc(struct subprocess_info *info, struct cred *new)
2855 {
2956 ksys_unshare(CLONE_FS | CLONE_FILES);
30
- /* stdin/stdout/stderr for /linuxrc */
31
- ksys_open("/dev/console", O_RDWR, 0);
32
- ksys_dup(0);
33
- ksys_dup(0);
57
+ console_on_rootfs();
3458 /* move initrd over / and chdir/chroot in initrd root */
35
- ksys_chdir("/root");
36
- ksys_mount(".", "/", NULL, MS_MOVE, NULL);
37
- ksys_chroot(".");
59
+ init_chdir("/root");
60
+ init_mount(".", "/", NULL, MS_MOVE, NULL);
61
+ init_chroot(".");
3862 ksys_setsid();
3963 return 0;
4064 }
....@@ -46,15 +70,14 @@
4670 extern char *envp_init[];
4771 int error;
4872
73
+ pr_warn("using deprecated initrd support, will be removed in 2021.\n");
74
+
4975 real_root_dev = new_encode_dev(ROOT_DEV);
5076 create_dev("/dev/root.old", Root_RAM0);
5177 /* mount initrd on rootfs' /root */
5278 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
53
- ksys_mkdir("/old", 0700);
54
- ksys_chdir("/old");
55
-
56
- /* try loading default modules from initrd */
57
- load_default_modules();
79
+ init_mkdir("/old", 0700);
80
+ init_chdir("/old");
5881
5982 /*
6083 * In case that a resume from disk is carried out by linuxrc or one of
....@@ -71,39 +94,30 @@
7194 current->flags &= ~PF_FREEZER_SKIP;
7295
7396 /* move initrd to rootfs' /old */
74
- ksys_mount("..", ".", NULL, MS_MOVE, NULL);
97
+ init_mount("..", ".", NULL, MS_MOVE, NULL);
7598 /* switch root and cwd back to / of rootfs */
76
- ksys_chroot("..");
99
+ init_chroot("..");
77100
78101 if (new_decode_dev(real_root_dev) == Root_RAM0) {
79
- ksys_chdir("/old");
102
+ init_chdir("/old");
80103 return;
81104 }
82105
83
- ksys_chdir("/");
106
+ init_chdir("/");
84107 ROOT_DEV = new_decode_dev(real_root_dev);
85108 mount_root();
86109
87110 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
88
- error = ksys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
111
+ error = init_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
89112 if (!error)
90113 printk("okay\n");
91114 else {
92
- int fd = ksys_open("/dev/root.old", O_RDWR, 0);
93115 if (error == -ENOENT)
94116 printk("/initrd does not exist. Ignored.\n");
95117 else
96118 printk("failed\n");
97119 printk(KERN_NOTICE "Unmounting old root\n");
98
- ksys_umount("/old", MNT_DETACH);
99
- printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
100
- if (fd < 0) {
101
- error = fd;
102
- } else {
103
- error = ksys_ioctl(fd, BLKFLSBUF, 0);
104
- ksys_close(fd);
105
- }
106
- printk(!error ? "okay\n" : "failed\n");
120
+ init_umount("/old", MNT_DETACH);
107121 }
108122 }
109123
....@@ -118,11 +132,11 @@
118132 * mounted in the normal path.
119133 */
120134 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
121
- ksys_unlink("/initrd.image");
135
+ init_unlink("/initrd.image");
122136 handle_initrd();
123137 return true;
124138 }
125139 }
126
- ksys_unlink("/initrd.image");
140
+ init_unlink("/initrd.image");
127141 return false;
128142 }