|
大家好,我在看下面这代码时有些不明白的地方,希望有人帮我解惑,谢谢!
首先代码(1)处,将initrd img的内容mount 到了/root目录下,此时的目录结构应该如下吧:
/
|-----/root(挂载的initrd img)
|--bin
|--inuxrc
|--dev
|--....
|-----/dev
|--console(5:1)
|--root.old(1:0)
|--...
(2)处,该是在要目录下新建了一个/old目录.
/
|-----/root(挂载的initrd img)
|--bin
|--inuxrc
|--dev
|--....
|-----/old
|-----/dev
|--console(5:1)
|--root.old(1:0)
|--...
(3)处执行do_linuxrc()函数,将/root目录置为根目录,此时的目录结构应该是initrd文件系统的目录结构吧?
/
|----bin
|----linuxrc
|----dev
|----....
(4)处呢?它表示什么意思?从后面来看,这里应该时将root目录下的initrd文件系统移动到/old目录下的呀,谁为我分析一下(4)处代码,谢谢!
static void __init handle_initrd(void)
{
int ram0 = kdev_t_to_nr(MKDEV(RAMDISK_MAJOR,0));
int error;
int i, pid;
create_dev("/dev/root.old", ram0, NULL);
(1) mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
(2) sys_mkdir("/old", 0700);
sys_chdir("/old");
(3) pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
if (pid > 0) {
while (pid != wait(&i)) {
current->policy |= SCHED_YIELD;
schedule();
}
}
(4) sys_mount("..", ".", NULL, MS_MOVE, NULL);
sys_umount("/old/dev", 0);
if (real_root_dev == ram0) {
sys_chdir("/old");
return;
}
ROOT_DEV = real_root_dev;
mount_root();
printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
if (!error)
printk("okay\n");
else {
.....
}
}
static int do_linuxrc(void * shell)
{
static char *argv[] = { "linuxrc", NULL, };
extern char * envp_init[];
sys_chdir("/root");
sys_mount(".", "/", NULL, MS_MOVE, NULL);
sys_chroot(".");
mount_devfs_fs ();
close(0);close(1);close(2);
setsid();
(void) open("/dev/console",O_RDWR,0);
(void) dup(0);
(void) dup(0);
return execve(shell, argv, envp_init);
} |
|