In this section, i would start the VFS travelling from rootfs. I'm showing out what happens to VFS when kernel starts.
The main scenario is shown below.
Fig 2-1
Let's get a further step to break it down.
1. In start_kernel context, vfs_caches_init() will call mnt_init(), and the following figure shows the hierarchy of mnt_init.
Fig 2-2
After register_filesystem(), the structure of file_systems is shown below:
Fig 2-3
And then inside do_kern_mount()
1) get_fs_type() to get a pointer points to the root file system type, which had already been shown above;
2) vfs_kern_mount is called. Firstly, it calls alloc_vfsmnt() to allocate a mount node and then initialize it;
3) Call type->get_sb which is actually get_sb_nodev(). It allocates a super block and initializes it, and then links s_instances to fs_supers list of root file system type node. Please be noted that when we called do_kern_mount("rootfs", 0, "rootfs", NULL) previously, the last input parameter is NULL, which means when we called mount_nodev(fs_type, flags, data, fill_super) inside get_sb_nodev(), the fill_super() function was NULL.
So after that, the structures inside RAM are like below:
Fig 2-4
2. In kernel_init context, let’s check Makefile firstly.
Let's analyze the source code by the following two figures.
Fig 2-5
Fig 2-6
Take jffs2 rootfs for example. If we use u-boot to boot-up the kernel, few available boot arguments are shown below:
- cramfs: setenv bootargs root=/dev/mtdblock2 init=/linuxrc console=ttySAC0,115200
- ramdisk: setenv bootargs initrd=0x31000000,0x200000 root=/dev/ram0 rw init=/linuxrc console=ttySAC0,115200
- jffs2: setenv bootargs root=/dev/mtdblock2 rootfstype=jffs2 rw console=ttySAC0,115200 init=/linuxrc
After above operations, the structure organization is updated as below:
Fig 2-7
(To be continue)
References:
[1] http://www.ibm.com/developerworks/cn/linux/l-vfs/