先看do_kernel_mount
1079 struct vfsmount * 1080 do_kern_mount(const char *fstype, int flags, const char *name, void*data) 1081 { 1082 struct file_system_type *type = get_fs_type(fstype); 1083 struct vfsmount *mnt; 1084 if (!type) 1085 return ERR_PTR(-ENODEV); 1086 mnt = vfs_kern_mount(type, flags, name, data); 1087 if (!IS_ERR(mnt) && (type->fs_flags & FS_HAS_SUBTYPE) && 1088 !mnt->mnt_sb->s_subtype) 1089 mnt = fs_set_subtype(mnt, fstype); 1090 put_filesystem(type); 1091 return mnt; 1092 } 1093 EXPORT_SYMBOL_GPL(do_kern_mount);
|
这里就用到了最开始说的注册的文件系统,通过get_fs_type来查找是否支持fstype类型的文件系统,例如ext4支持的话就把前面注册的结构返回到这里,以后使用的type都是ext4_fs_type,例如vfs_kern_mount里面传递进去的type,就是ext4_fs_type了,
进入到vfs_kern_mount里面看一下,里面肯定会调到get_sb,
899 struct vfsmount * 900 vfs_kern_mount(struct file_system_type *type, int flags, constchar *name, void *data) 901 { 902 struct vfsmount *mnt; 903 char *secdata = NULL; 904 int error; 905 906 if (!type) 907 return ERR_PTR(-ENODEV); 908 909 error = -ENOMEM; 910 mnt = alloc_vfsmnt(name); 911 if (!mnt) 912 goto out; 913 914 if (flags & MS_KERNMOUNT) 915 mnt->mnt_flags = MNT_INTERNAL; 916 917 if (data && !(type->fs_flags & FS_BINARY_MOUNTDATA)) { 918 secdata = alloc_secdata(); 919 if (!secdata) 920 goto out_mnt; 921 922 error = security_sb_copy_data(data, secdata); 923 if (error) 924 goto out_free_secdata; 925 } 926*************************在这呢,这里的get_sb就是fs/ext4/super.c里面的ext4_get_sb*********************************** 927 error = type->get_sb(type, flags, name, data, mnt); 928 if (error < 0) 929 goto out_free_secdata; 930 BUG_ON(!mnt->mnt_sb); 931 WARN_ON(!mnt->mnt_sb->s_bdi); 932 mnt->mnt_sb->s_flags |= MS_BORN; 933 934 error = security_sb_kern_mount(mnt->mnt_sb, flags, secdata); 935 if (error) 936 goto out_sb; 937 938 /* 939 * filesystems should never set s_maxbytes larger than MAX_LFS_FILESIZE 940 * but s_maxbytes was an unsigned long long for many releases. Throw 941 * this warning for a little while to try and catch filesystems that 942 * violate this rule. This warning should be either removed or 943 * converted to a BUG() in 2.6.34. 944 */ 945 WARN((mnt->mnt_sb->s_maxbytes < 0), "%s set sb->s_maxbytes to " 946 "negative value (%lld)\n", type->name,mnt->mnt_sb->s_maxbytes); 947 948 mnt->mnt_mountpoint = mnt->mnt_root; 949 mnt->mnt_parent = mnt; 950 up_write(&mnt->mnt_sb->s_umount); 951 free_secdata(secdata); 952 return mnt; 953 out_sb: 954 dput(mnt->mnt_root); 955 deactivate_locked_super(mnt->mnt_sb); 956 out_free_secdata: 957 free_secdata(secdata); 958 out_mnt: 959 free_vfsmnt(mnt); 960 out: 961 return ERR_PTR(error); 962 } 963 964 EXPORT_SYMBOL_GPL(vfs_kern_mount);
|
接下来就要进入到ext4系统里面看一下get_sb做了什么
4232 static int ext4_get_sb(struct file_system_type *fs_type, int flags, 4233 const char *dev_name, void *data, struct vfsmount *mnt) 4234 { 4235 return get_sb_bdev(fs_type, flags, dev_name, data, ext4_fill_super,mnt); 4236 }
|
这里面一共调用了两个接口get_sb_bdev和ext4_fill_super,一个文件系统的细节部分都在ext4_fill_super里面去做
get_sb_bdev里面会用到ext4_fill_super,因为要注册一下里面的细节,比如创建节点,文件,目录,链接,读文件,读目录,写文件,写目录,删除文件,很多很多。
后面涉及到了对块设备操作的很多工作,文件系统最关键的就是管理文件,并且是块设备上的,这个块设备就是在get_sb_bdev里面得到的
747 int get_sb_bdev(struct file_system_type *fs_type, 748 int flags, const char *dev_name, void *data, 749 int (*fill_super)(struct super_block *, void *, int), 750 struct vfsmount *mnt) 751 { 752 struct block_device *bdev; 753 struct super_block *s; 754 fmode_t mode = FMODE_READ; 755 int error = 0; 756 757 if (!(flags & MS_RDONLY)) 758 mode |= FMODE_WRITE; 759 760 bdev = open_bdev_exclusive(dev_name, mode, fs_type); 761 if (IS_ERR(bdev)) 762 return PTR_ERR(bdev); …… 799 800 s->s_flags = flags; 801 s->s_mode = mode; 802 strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id)); 803 sb_set_blocksize(s, block_size(bdev)); 804 error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); 805 if (error) { 806 deactivate_locked_super(s); 807 goto error; 808 } 809 810 s->s_flags |= MS_ACTIVE; 811 bdev->bd_super = s; 812 } 813 814 simple_set_mnt(mnt, s); 815 return 0; ……
|
通过这个open_bdev_exclusive拿到设备文件后进入到了error = fill_super(s, data, flags & MS_SILENT ? 1 : 0);
就这样,对磁盘文件操作就了解了
阅读(5718) | 评论(0) | 转发(0) |