说明:本文基于Linux2.6内核分析;其他内核版本仅供参考。
前边通过源码情景分析,看过了总线、设备、驱动及其发现机制,Linux2.6内核udev设备节点创建相关;对于文件系统,一直望而生畏,但内核学习、这部分又不可能绕的过去。目前对VFS中使用的hash表还未做研究,它在dentry和vfsmount下查找节点起关键作用;后边在做分析。下边将根文件系统挂载过程做简单分析:
一、rootfs的诞生
引子:
Linux一切皆文件的提出:在Linux中,普通文件、目录、字符设备、块设备、套接字等都以文件被对待;他们具体的类型及其操作不同,但需要向上层提供统一的操作接口。
虚拟文件系统VFS就是内核中的一个软件层,向上给用户空间程序提供文件系统操作接口;向下允许不同的文件系统共存。所以,所有实际文件系统都必须实现VFS的结构封装。
矛盾的提出:
系统中任何文件系统的挂载必须满足两个条件:挂载点和文件系统。
直接挂载nfs或flash文件系统有如下两个问题必须解决:
1.谁来提供挂载点?我们可以想象自己创建一个超级块(包含目录项和i节点),这时挂载点不是就有了吗;很可惜,linux引入VFS(一切皆文件,所有类型文件系统必须提供一个VFS的软件层、以向上层提供统一接口)后该问题不能这么解决,因为挂载点必须关联到文件系统、也就是说挂载点必须属于某个文件系统。
2.怎样访问到nfs或flash上的文件系统?我们可以说直接访问设备驱动读取其上边的文件系统(设备上的文件系统是挂载在自己的根目录),不就可以了吗;别忘了还是Linux的VFS,设备访问也不例外。因为访问设备还是需要通过文件系统来访问它的挂载点,不能直接访问(要满足Linux的VFS架构,一切皆文件)。
所以,一句话:rootfs之所以存在,是因为需要在VFS机制下给系统提供最原始的挂载点。
如此矛盾,需要我们引入一种特殊文件系统:
1.它是系统自己创建并加载的第一个文件系统;该文件系统的挂载点就是它自己的根目录项。
2.该文件系统不能存在于nfs或flash上,因为如此将会陷入之前的矛盾。
rootfs的诞生:
上述问题需要我们创建具有如下三个特点的特殊文件系统:
1.它是系统自己创建并加载的第一个文件系统;
2.该文件系统的挂载点就是它自己的根目录项对象;
3.该文件系统仅仅存在于内存中。
由以上分析可以看出,rootfs是Linux的VFS(一切皆文件,所有类型文件系统必须提供一个VFS的软件层、以向上层提供统一接口)存在的基石;二者关系密切。如果没有VFS机制,rootfs也就没有存在的必要;同样,如果没有rootfs、VFS机制也就不能实现。
这就是两者之间的真正关系,之前看网上什么说法都有:有的只说关系密切,没有指明具体关系;有的干脆误人子弟,说VFS就是rootfs。
其实,VFS是一种机制、是Linux下每一种文件系统(包括刚才说的rootfs,还有常见的ext3、yaffs等)都必须按照这个机制去实现的一种规范;而rootfs仅仅是符合VFS规范的而且又具有如上3个特点的一个文件系统。
VFS是Linux文件系统实现必须遵循的一种机制,rootfs是一种具体实现的文件系统、Linux下所有文件系统的实现都必须符合VFS的机制(符合VFS的接口);这就是二者的真正关系。
以下分析基于模拟器Linux2.6.29内核:
二、相关
Linux内核中current指针作为全局变量,使用非常广泛;例如:进程上下文中获取当前进程ID、任务调度,以及open等文件系统调用中路径搜索等;首先介绍下current结构体:
各个平台、各个内核版本中current的实现可能不同;但原理是一样的。该指针一般定义在具体平台的current.h头文件中,类型为struct task_struct:
-
#define current (get_current())
-
static inline struct task_struct *get_current(void)
include/linux/sched.h
-
struct task_struct {
-
......
-
struct thread_info *thread_info;
-
struct list_head tasks;
-
pid_t pid;
-
pid_t tgid;
-
uid_t uid,euid,suid,fsuid;
-
gid_t gid,egid,sgid,fsgid;
-
struct fs_struct *fs;
-
struct files_struct *files;
-
......
-
}
1.文件系统注册
kernel/include/include/fs.h
-
struct file_system_type {
-
const char *name;
-
int fs_flags;
-
int (*get_sb) (struct file_system_type *, int, const char *, void *, struct vfsmount *);
-
-
void (*kill_sb) (struct super_block *);
-
-
struct module *owner;
-
struct file_system_type * next;
-
-
struct list_head fs_supers;
-
-
struct lock_class_key s_lock_key;
-
struct lock_class_key s_umount_key;
-
-
struct lock_class_key i_lock_key;
-
struct lock_class_key i_mutex_key;
-
struct lock_class_key i_mutex_dir_key;
-
struct lock_class_key i_alloc_sem_key;
-
};
2.文件系统挂载vfsmount(struct vfsmount):
本质上,mount操作的过程就是新建一个vfsmount结构,然后将此结构和挂载点(目录项对象)关联。关联之后,目录查找时就能沿着vfsmount挂载点一级级向下查找文件了。
对于每一个mount的文件系统,都由一个vfsmount实例来表示。
kernel/include/linux/mount.h
-
struct vfsmount {
-
struct list_head mnt_hash;
-
struct vfsmount *mnt_parent;
-
struct dentry *mnt_mountpoint;
-
struct dentry *mnt_root;
-
struct super_block *mnt_sb;
-
struct list_head mnt_mounts;
-
struct list_head mnt_child;
-
int mnt_flags;
-
-
const char *mnt_devname;
-
struct list_head mnt_list;
-
struct list_head mnt_expire;
-
struct list_head mnt_share;
-
struct list_head mnt_slave_list;
-
struct list_head mnt_slave;
-
struct vfsmount *mnt_master;
-
struct mnt_namespace *mnt_ns;
-
int mnt_id;
-
int mnt_group_id;
-
-
-
-
-
-
atomic_t mnt_count;
-
int mnt_expiry_mark;
-
int mnt_pinned;
-
int mnt_ghosts;
-
-
-
-
-
atomic_t __mnt_writers;
-
};
3.超级块(struct super_bloc):
kernel/include/linux/fs.h
-
struct super_block {
-
struct list_head s_list;
-
dev_t s_dev;
-
unsigned long s_blocksize;
-
unsigned char s_blocksize_bits;
-
unsigned char s_dirt;
-
unsigned long long s_maxbytes;
-
struct file_system_type *s_type;
-
-
const struct super_operations *s_op;
-
struct dquot_operations *dq_op;
-
struct quotactl_ops *s_qcop;
-
const struct export_operations *s_export_op;
-
unsigned long s_flags;
-
unsigned long s_magic;
-
struct dentry *s_root;
-
struct rw_semaphore s_umount;
-
struct mutex s_lock;
-
int s_count;
-
int s_need_sync_fs;
-
atomic_t s_active;
-
#ifdef CONFIG_SECURITY
-
void *s_security;
-
#endif
-
struct xattr_handler **s_xattr;
-
-
struct list_head s_inodes;
-
struct list_head s_dirty;
-
struct list_head s_io;
-
struct list_head s_more_io;
-
struct hlist_head s_anon;
-
struct list_head s_files;
-
-
struct list_head s_dentry_lru;
-
int s_nr_dentry_unused;
-
-
struct block_device *s_bdev;
-
struct mtd_info *s_mtd;
-
struct list_head s_instances;
-
struct quota_info s_dquot;
-
-
int s_frozen;
-
wait_queue_head_t s_wait_unfrozen;
-
-
char s_id[32];
-
-
void *s_fs_info;
-
fmode_t s_mode;
-
-
-
-
-
-
struct mutex s_vfs_rename_mutex;
-
-
-
u32 s_time_gran;
-
-
-
-
-
-
char *s_subtype;
-
-
-
-
-
-
char *s_options;
-
-
-
-
-
struct list_head s_async_list;
-
};
4.目录索引节点(struct inode):
kernel/include/linux/fs.h
-
struct inode {
-
struct hlist_node i_hash;
-
struct list_head i_list;
-
struct list_head i_sb_list;
-
struct list_head i_dentry;
-
unsigned long i_ino;
-
atomic_t i_count;
-
unsigned int i_nlink;
-
uid_t i_uid;
-
gid_t i_gid;
-
dev_t i_rdev;
-
u64 i_version;
-
loff_t i_size;
-
#ifdef __NEED_I_SIZE_ORDERED
-
seqcount_t i_size_seqcount;
-
#endif
-
struct timespec i_atime;
-
struct timespec i_mtime;
-
struct timespec i_ctime;
-
unsigned int i_blkbits;
-
blkcnt_t i_blocks;
-
unsigned short i_bytes;
-
umode_t i_mode;
-
spinlock_t i_lock;
-
struct mutex i_mutex;
-
struct rw_semaphore i_alloc_sem;
-
const struct inode_operations *i_op;
-
const struct file_operations *i_fop;
-
struct super_block *i_sb;
-
struct file_lock *i_flock;
-
struct address_space *i_mapping;
-
struct address_space i_data;
-
#ifdef CONFIG_QUOTA
-
struct dquot *i_dquot[MAXQUOTAS];
-
#endif
-
struct list_head i_devices;
-
union {
-
struct pipe_inode_info *i_pipe;
-
struct block_device *i_bdev;
-
struct cdev *i_cdev;
-
};
-
int i_cindex;
-
-
__u32 i_generation;
-
-
#ifdef CONFIG_DNOTIFY
-
unsigned long i_dnotify_mask;
-
struct dnotify_struct *i_dnotify;
-
#endif
-
-
#ifdef CONFIG_INOTIFY
-
struct list_head inotify_watches;
-
struct mutex inotify_mutex;
-
#endif
-
-
unsigned long i_state;
-
unsigned long dirtied_when;
-
-
unsigned int i_flags;
-
-
atomic_t i_writecount;
-
#ifdef CONFIG_SECURITY
-
void *i_security;
-
#endif
-
void *i_private;
-
};
5.目录项对象(struct dentry):
kernel/include/linux/dcache.h
-
struct dentry {
-
atomic_t d_count;
-
unsigned int d_flags;
-
spinlock_t d_lock;
-
int d_mounted;
-
struct inode *d_inode;
-
-
-
-
-
-
-
struct hlist_node d_hash;
-
struct dentry *d_parent;
-
struct qstr d_name;
-
-
struct list_head d_lru;
-
-
-
-
union {
-
struct list_head d_child;
-
struct rcu_head d_rcu;
-
} d_u;
-
struct list_head d_subdirs;
-
struct list_head d_alias;
-
unsigned long d_time;
-
struct dentry_operations *d_op;
-
struct super_block *d_sb;
-
void *d_fsdata;
-
-
unsigned char d_iname[DNAME_INLINE_LEN_MIN];
-
};
其他:
include/linux/fs.h
-
struct file {
-
-
-
-
-
union {
-
struct list_head fu_list;
-
struct rcu_head fu_rcuhead;
-
} f_u;
-
struct path f_path;
-
#define f_dentry f_path.dentry
-
#define f_vfsmnt f_path.mnt
-
const struct file_operations *f_op;
-
atomic_long_t f_count;
-
unsigned int f_flags;
-
fmode_t f_mode;
-
loff_t f_pos;
-
struct fown_struct f_owner;
-
const struct cred *f_cred;
-
struct file_ra_state f_ra;
-
-
u64 f_version;
-
#ifdef CONFIG_SECURITY
-
void *f_security;
-
#endif
-
-
void *private_data;
-
-
#ifdef CONFIG_EPOLL
-
-
struct list_head f_ep_links;
-
spinlock_t f_ep_lock;
-
#endif /* #ifdef CONFIG_EPOLL */
-
struct address_space *f_mapping;
-
#ifdef CONFIG_DEBUG_WRITECOUNT
-
unsigned long f_mnt_write_state;
-
#endif
-
};
include/linux/fs_struct.h
-
struct fs_struct {
-
atomic_t count;
-
rwlock_t lock;
-
int umask;
-
struct path root, pwd;
-
};
include/linux/namei.h
-
struct nameidata {
-
struct path path;
-
struct qstr last;
-
unsigned int flags;
-
int last_type;
-
unsigned depth;
-
char *saved_names[MAX_NESTED_LINKS + 1];
-
-
-
union {
-
struct open_intent open;
-
} intent;
-
};
include/linux/path.h
-
struct path {
-
struct vfsmount *mnt;
-
struct dentry *dentry;
-
};
include/linux/dcache.h
-
struct qstr {
-
unsigned int hash;
-
unsigned int len;
-
const unsigned char *name;
-
};
三、注册/创建、安装/挂载rootfs,并调用set_fs_root设置系统current的根文件系统为rootfs
过程:
第一步:建立rootfs文件系统;
第二步:调用其get_sb函数(对于rootfs这种内存/伪文件系统是get_sb_nodev,实际文件系统比如ext2等是get_sb_bdev)、建立超级块(包含目录项和i节点);
第三步:挂载该文件系统(该文件系统的挂载点指向该文件系统超级块的根目录项);
第四步:将系统current的根文件系统和根目录设置为rootfs和其根目录。
kernel/init/main.c
-
asmlinkage void __init start_kernel(void)
-
{
-
setup_arch(&command_line);
-
parse_args("Booting kernel", static_command_line, __start___param,
-
__stop___param - __start___param,
-
&unknown_bootoption);
-
vfs_caches_init(num_physpages);
-
}
kernel/fs/dcache.c
-
void __init vfs_caches_init(unsigned long mempages)
-
{
-
mnt_init();
-
bdev_cache_init();
-
chrdev_init();
-
}
kernel/fs/namespace.c
-
void __init mnt_init(void)
-
{
-
init_rootfs();
-
init_mount_tree();
-
}
下边分两步:
1.向内核注册rootfs虚拟文件系统init_rootfs
kernel/fs/ramfs/inode.c
-
int __init init_rootfs(void)
-
{
-
err = register_filesystem(&rootfs_fs_type);
-
}
-
static struct file_system_type rootfs_fs_type = {
-
.name = "rootfs",
-
.get_sb = rootfs_get_sb,
-
.kill_sb = kill_litter_super,
-
};
2.建立rootfs的根目录,并将rootfs挂载到自己的根目录;设置系统current根目录和根文件系统
kernel/fs/namespace.c
-
static void __init init_mount_tree(void)
-
{
-
struct vfsmount *mnt;
-
struct mnt_namespace *ns;
-
struct path root;
-
-
-
-
-
-
-
-
mnt = do_kern_mount("rootfs", 0, "rootfs", NULL);
-
list_add(&mnt->mnt_list, &ns->list);
-
ns->root = mnt;
-
mnt->mnt_ns = ns;
-
-
init_task.nsproxy->mnt_ns = ns;
-
get_mnt_ns(ns);
-
-
root.mnt = ns->root;
-
root.dentry = ns->root->mnt_root;
-
-
-
set_fs_pwd(current->fs, &root);
-
-
set_fs_root(current->fs, &root);
-
}
以下着重分析do_kern_mount函数,它实现了rootfs在自己根目录上的挂载:
kernel/fs/super.c
-
struct vfsmount *
-
do_kern_mount(const char *fstype, int flags, const char *name, void *data)
-
{
-
mnt = vfs_kern_mount(type, flags, name, data);
-
return mnt;
-
}
kernel/fs/super.c
-
struct vfsmount *
-
vfs_kern_mount(struct file_system_type *type, int flags, const char *name, void *data)
-
{
-
mnt = alloc_vfsmnt(name);
-
error = type->get_sb(type, flags, name, data, mnt);
-
mnt->mnt_mountpoint = mnt->mnt_root;
-
mnt->mnt_parent = mnt;
-
return mnt;
-
}
kernel/fs/ramfs/inode.c
-
static int rootfs_get_sb(struct file_system_type *fs_type,
-
int flags, const char *dev_name, void *data, struct vfsmount *mnt)
-
{
-
return get_sb_nodev(fs_type, flags|MS_NOUSER, data, ramfs_fill_super,
-
mnt);
-
}
kernel/fs/super.c
-
int get_sb_nodev(struct file_system_type *fs_type,
-
int flags, void *data,
-
int (*fill_super)(struct super_block *, void *, int),
-
struct vfsmount *mnt)
-
{
-
struct super_block *s = sget(fs_type, NULL, set_anon_super, NULL);
-
-
error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
return simple_set_mnt(mnt, s);
-
}
kernel/fs/namespace.c
-
int simple_set_mnt(struct vfsmount *mnt, struct super_block *sb)
-
{
-
printk("TK-------_>>>>>>>namespace.c>>>>simple_set_mnt\n");
-
mnt->mnt_sb = sb;
-
mnt->mnt_root = dget(sb->s_root);
-
return 0;
-
}
至此,rootfs文件系统建立、并且挂载于自己超级块(包括目录项dentry和i节点inod)对应的目录项,设置了系统current根目录和根文件系统、pwd的目录和文件系统。
========================================
释放Initramfs到rootfs;如果Initramfs中有init,这种情况比较特殊、rootfs就是最后系统使用的根文件系统。
而且此时,不需要在单独烧录根文件系统的img;此时,根文件系统就是内核uImage的一部分。当然,缺陷就是该文件系统运行时的介质是ramdisk即内存盘、它不再与磁盘对应;因此,此时修改根目录下的文件将不被得到保存。它的内核配置项为:CONFIG_INITRAMFS_SOURCE。实际项目中会经常碰到。
make menuconfig->General setup->Initial RAM filesystem and RAM disk(initramfs/initrd) support
底下的Initramfs source file(s)填写根文件系统的路径,如:../out/target/product/tclm6/root;不填的话,将导致initrd或磁盘文件系统的挂载(因为下边将会看到,内核将找不到“/init”)。
对应内核源码:
kernel/init/main.c
-
static int __init kernel_init(void * unused){
-
......
-
do_basic_setup();
-
-
-
-
-
-
-
-
-
-
-
......
-
if (!ramdisk_execute_command) ramdisk_execute_command = "/init";
-
if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
-
ramdisk_execute_command = NULL;
-
-
-
-
prepare_namespace();
-
}
-
init_post();
-
......
-
}
看看init_post实现:
-
static noinline int init_post(void)
-
{
-
if (ramdisk_execute_command) {
-
run_init_process(ramdisk_execute_command);
-
printk(KERN_WARNING "Failed to execute %s\n", ramdisk_execute_command);
-
}
-
-
if (execute_command) {
-
run_init_process(execute_command);
-
printk(KERN_WARNING "Failed to execute %s. Attempting "
-
"defaults...\n", execute_command);
-
}
-
-
run_init_process("/sbin/init");
-
run_init_process("/etc/init");
-
run_init_process("/bin/init");
-
run_init_process("/bin/sh");
-
}
四、挂载实际文件系统至rootfs,并调用set_fs_root设置为系统current的根文件系统
下边从uboot启动内核参数的角度来简单说明:
以下三种情况都是将文件系统挂载到rootfs的/root目录,并将系统current的根目录切换为/root、系统current的根文件系统切换为磁盘文件系统。
kernel/init/do_mounts.c
-
void __init prepare_namespace(void)
-
{
-
if (initrd_load())
-
goto out;
-
if (saved_root_name[0]) {
-
root_device_name = saved_root_name;
-
if (!strncmp(root_device_name, "mtd", 3) ||
-
!strncmp(root_device_name, "ubi", 3)) {
-
mount_block_root(root_device_name, root_mountflags);
-
goto out;
-
}
-
ROOT_DEV = name_to_dev_t(root_device_name);
-
if (strncmp(root_device_name, "/dev/", 5) == 0)
-
root_device_name += 5;
-
}
-
mount_root();
-
out:
-
-
sys_chroot(".");
-
}
下边分两步解释mount_root()和sys_chroot(".")调用:
1.将nfs或磁盘文件系统挂载至rootfs的/root目录(以磁盘为例)
-
void __init mount_root(void)
-
{
-
if (mount_nfs_root())
-
return;
-
-
-
create_dev("/dev/root", ROOT_DEV);
-
-
mount_block_root("/dev/root", root_mountflags);
-
}
-
void __init mount_block_root(char *name, int flags)
-
{
-
int err = do_mount_root(name, p, flags, root_mount_data);
-
}
-
static int __init do_mount_root(char *name, char *fs, int flags, void *data)
-
{
-
int err = sys_mount(name, "/root", fs, flags, data);
-
sys_chdir("/root");
-
ROOT_DEV = current->fs->pwd.mnt->mnt_sb->s_dev;
-
return 0;
-
}
2.将当前目录/root设置为系统current根目录,磁盘文件系统设置为系统current根文件系统
分析sys_chroot("."):见Linux内核编程之C语言预处理功能与宏
fs/open.c
-
SYSCALL_DEFINE1(chroot, const char __user *, filename)
-
{
-
struct path path;
-
error = user_path_dir(filename, &path);
-
-
set_fs_root(current->fs, &path);
-
}
注意,如下情况:rootfs特殊文件系统没有被卸载,他只是隐藏在基于磁盘的根文件系统下了。
initrd作为根文件系统
setenv bootargs root=/dev/ram0 initrd=0x2800000,24M rootfstype=ext2 mem=64M console=ttyAMA0
参数说明:
root:用来指定rootfs的位置。
rootfstype:用来指定文件系统的类型。
nfs作为根文件系统
setenv bootargs root=/dev/nfs nfsroot=192.168.1.7:/opt/yz/nfs,rw ip=192.168.1.160 mem=64M console=ttyAMA0
参数说明:
nfsroot:文件系统在哪台主机的哪个目录下。
ip:指定系统启动之后网卡的ip地址。
flash作为根文件系统
setenv bootargs root=/dev/mtdblock0 mem=16M mtdparts=armflash.1:4M@0x400000(jffs2) macaddr=9854 rootfstype=jffs2 console=ttyAMA0
参数说明:
mtdparts:根文件系统在flash中的位置。
总结:rootfs永远不会被卸载,它只是被隐藏了。在用户空间下,更多地情况是只能见到rootfs这棵大树的一叶,而且还是被安装过文件系统了的。
五、其他说明
至于在mirco2440下mount出的结果:
-
rootfs on / type rootfs (rw)
-
/dev/root on / type yaffs (rw,relatime)
-
none on /proc type proc (rw,relatime)
-
none on /sys type sysfs (rw,relatime)
-
none on /proc/bus/usb type usbfs (rw,relatime)
-
none on /dev type ramfs (rw,relatime)
-
none on /dev/pts type devpts (rw,relatime,mode=622)
-
tmpfs on /dev/shm type tmpfs (rw,relatime)
-
none on /tmp type ramfs (rw,relatime)
-
none on /var type ramfs (rw,relatime)
从log中体会一下这个过程:
-
s3c2410-rtc s3c2410-rtc: setting system clock to 2006-04-16 22:15:34 UTC (1145225734)
-
TK------->>>>>init/main.c>>>>>>kernel_init>>before>prepare_namespace
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_sb->s_type->name is rootfs
-
##################################################################################################################
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_sb->s_type->name is rootfs
-
##################################################################################################################
-
TK------->>>>>init/do_mounts.c>>>>>>prepare_namespace>>before>mount_root
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_sb->s_type->name is rootfs
-
##################################################################################################################
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_sb->s_type->name is rootfs
-
##################################################################################################################
-
yaffs: dev is 32505859 name is "mtdblock3"
-
yaffs: passed flags ""
-
yaffs: Attempting MTD mount on 31.3, "mtdblock3"
-
yaffs_read_super: isCheckpointed 0
-
VFS: Mounted root (yaffs filesystem) on device 31:3.
-
TK------->>>>>init/do_mounts.c>>>>>>prepare_namespace>>before>sys_mount
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_sb->s_type->name is rootfs
-
##################################################################################################################
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_name.name is root
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_sb->s_type->name is yaffs
-
##################################################################################################################
-
TK------->>>>>init/do_mounts.c>>>>>>prepare_namespace>>before>sys_chroot
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_sb->s_type->name is rootfs
-
##################################################################################################################
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_name.name is root
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_sb->s_type->name is yaffs
-
##################################################################################################################
-
TK------->>>>>fs/open.c>>>>>>SYSCALL_DEFINE1(chroot>>before>set_fs_root
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_sb->s_type->name is rootfs
-
##################################################################################################################
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_name.name is root
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_sb->s_type->name is yaffs
-
##################################################################################################################
-
TK------->>>>>init/do_mounts.c>>>>>>SYSCALL_DEFINE1(chroot>>after>set_fs_root
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_name.name is root
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_sb->s_type->name is yaffs
-
##################################################################################################################
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_name.name is root
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_sb->s_type->name is yaffs
-
##################################################################################################################
-
TK------->>>>>init/do_mounts.c>>>>>>prepare_namespace>>after>sys_chroot
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_name.name is root
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_sb->s_type->name is yaffs
-
##################################################################################################################
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_name.name is root
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_sb->s_type->name is yaffs
-
##################################################################################################################
-
TK------->>>>>init/main.c>>>>>>kernel_init>>after>prepare_namespace
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_name.name is root
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_sb->s_type->name is yaffs
-
##################################################################################################################
-
##################################################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_name.name is root
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_sb->s_type->name is yaffs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_sb->s_type->name is yaffs
-
##################################################################################################################
-
Freeing init memory: 156K
-
[16/Apr/2006:14:15:35 +0000] boa: server version Boa/0.94.13
-
[16/Apr/2006:14:15:35 +0000] boa: server built Mar 26 2009 at 15:28:42.
-
[16/Apr/2006:14:15:35 +0000] boa: starting server pid=681, port 80
-
-
Try to bring eth0 interface up......eth0: link down
-
Done
-
-
Please press Enter to activate this console.
-
[root@FriendlyARM /]# mount
-
rootfs on / type rootfs (rw)
-
/dev/root on / type yaffs (rw,relatime)
-
none on /proc type proc (rw,relatime)
-
none on /sys type sysfs (rw,relatime)
-
none on /proc/bus/usb type usbfs (rw,relatime)
-
none on /dev type ramfs (rw,relatime)
-
none on /dev/pts type devpts (rw,relatime,mode=622)
-
tmpfs on /dev/shm type tmpfs (rw,relatime)
-
none on /tmp type ramfs (rw,relatime)
-
none on /var type ramfs (rw,relatime)
-
[root@FriendlyARM /]#
ubuntu下mount出的结果:
-
/dev/sda5 on / type ext3 (rw,errors=remount-ro,commit=0)
-
proc on /proc type proc (rw,noexec,nosuid,nodev)
-
sysfs on /sys type sysfs (rw,noexec,nosuid,nodev)
-
fusectl on /sys/fs/fuse/connections type fusectl (rw)
-
none on /sys/kernel/debug type debugfs (rw)
-
none on /sys/kernel/security type securityfs (rw)
-
udev on /dev type devtmpfs (rw,mode=0755)
-
devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=0620)
-
tmpfs on /run type tmpfs (rw,noexec,nosuid,size=10%,mode=0755)
-
none on /run/lock type tmpfs (rw,noexec,nosuid,nodev,size=5242880)
-
none on /run/shm type tmpfs (rw,nosuid,nodev)
-
/dev/sda7 on /home type ext3 (rw,commit=0)
-
binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev)
-
rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
-
nfsd on /proc/fs/nfsd type nfsd (rw)
-
gvfs-fuse-daemon on /home/tankai/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,user=tankai)
一个还显示rootfs,一个干脆不显示。这个无关紧要。可能micro2440中执行mount命令还会将系统current根目录的父节点也显示出来;而ubuntu下不会再去关心系统current根目录的父节点。但所有的文件搜索,内核都是从系统current根目录开始向下查找的,因此、可以说我们不能在访问rootfs中除了作为系统current根文件系统之外的其他任何节点。
六、用例,说明系统current的文件系统布局,不管在那个目录、其根都不会改变:
hello.c
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
#include
-
-
-
-
-
#include
-
#include
-
MODULE_LICENSE("Dual BSD/GPL");
-
-
static int hello_init(void)
-
{
-
printk(KERN_ALERT "Hello, world\n");
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_name.name is %s\n",current->fs->root.dentry->d_name.name);
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_sb->s_type->name is %s\n",current->fs->root.dentry->d_sb->s_type->name);
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_name.name is %s\n",current->fs->root.mnt->mnt_mountpoint->d_name.name);
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_sb->s_type->name is %s\n",current->fs->root.mnt->mnt_mountpoint->d_sb->s_type->name);
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_name.name is %s\n",current->fs->root.mnt->mnt_root->d_name.name);
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_sb->s_type->name is %s\n",current->fs->root.mnt->mnt_root->d_sb->s_type->name);
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_sb->s_type->name is %s\n",current->fs->root.mnt->mnt_sb->s_type->name);
-
printk("########################################################################################\n");
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_name.name is %s\n",current->fs->pwd.dentry->d_name.name);
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_sb->s_type->name is %s\n",current->fs->pwd.dentry->d_sb->s_type->name);
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_name.name is %s\n",current->fs->pwd.mnt->mnt_mountpoint->d_name.name);
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_sb->s_type->name is %s\n",current->fs->pwd.mnt->mnt_mountpoint->d_sb->s_type->name);
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_name.name is %s\n",current->fs->pwd.mnt->mnt_root->d_name.name);
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_sb->s_type->name is %s\n",current->fs->pwd.mnt->mnt_root->d_sb->s_type->name);
-
printk("TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_sb->s_type->name is %s\n",current->fs->pwd.mnt->mnt_sb->s_type->name);
-
return 0;
-
}
-
-
static void hello_exit(void)
-
{
-
printk(KERN_ALERT"Goodbye, cruel world\n");
-
}
-
-
module_init(hello_init);
-
module_exit(hello_exit);
Makefile
-
ifneq ($(KERNELRELEASE),)
-
obj-m:=hello.o
-
else
-
KERNELDIR:=/home/android2.3/android2.3_kernel/
-
PWD:=$(shell pwd)
-
default:
-
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
-
clean:
-
rm -rf *.o *.mod.c *.mod.o *.ko
-
endif
make生成hello.ko
先看下文件系统布局:
mount
-
rootfs / rootfs ro 0 0
-
tmpfs /dev tmpfs rw,mode=755 0 0
-
devpts /dev/pts devpts rw,mode=600 0 0
-
proc /proc proc rw 0 0
-
sysfs /sys sysfs rw 0 0
-
none /acct cgroup rw,cpuacct 0 0
-
tmpfs /mnt/asec tmpfs rw,mode=755,gid=1000 0 0
-
tmpfs /mnt/obb tmpfs rw,mode=755,gid=1000 0 0
-
none /dev/cpuctl cgroup rw,cpu 0 0
-
/dev/block/mtdblock0 /system yaffs2 rw 0 0
-
/dev/block/mtdblock1 /data yaffs2 rw,nosuid,nodev 0 0
-
/dev/block/mtdblock2 /cache yaffs2 rw,nosuid,nodev 0 0
-
/dev/block/vold/179:0 /mnt/sdcard vfat rw,dirsync,nosuid,nodev,noexec,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
-
/dev/block/vold/179:0 /mnt/secure/asec vfat rw,dirsync,nosuid,nodev,noexec,uid=1000,gid=1015,fmask=0702,dmask=0702,allow_utime=0020,codepage=cp437,iocharset=iso8859-1,shortname=mixed,utf8,errors=remount-ro 0 0
-
tmpfs /mnt/sdcard/.android_secure tmpfs ro,size=0k,mode=000 0 0
1.放入/data/下运行insmod hello.ko rmmod hello.ko
-
Hello, world
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_sb->s_type->name is rootfs
-
########################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_sb->s_type->name is yaffs2
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_name.name is data
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_sb->s_type->name is yaffs2
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_sb->s_type->name is yaffs2
-
Goodbye, cruel world
2.放在/sdcard/tank/下运行insmod hello.ko rmmod hello.ko
-
Hello, world
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.dentry->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_root->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->root.mnt->mnt_sb->s_type->name is rootfs
-
########################################################################################
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_name.name is tank
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.dentry->d_sb->s_type->name is vfat
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_name.name is sdcard
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_mountpoint->d_sb->s_type->name is rootfs
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_name.name is /
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_root->d_sb->s_type->name is vfat
-
TK---->>>>init/main.c>>>kernel_init>>>>current->fs->pwd.mnt->mnt_sb->s_type->name is vfat
-
Goodbye, cruel world
由此证明;current->fs->root就是系统承认的根文件系统。