struct file (進程私有)
→ f_dentry → struct dentry (目錄項緩存)
→ d_inode → struct inode (索引節點)
→ i_sb → struct super_block (超級塊)
→ s_op → super_operations (文件系統方法集)
→ i_fop → file_operations (文件操作方法集)
→ i_op → inode_operations (索引節點操作集)
sys_open → filp_open → do_filp_openopen_namei → path_lookup → link_path_walk → do_lookup → real_lookupext3_lookup → ext3_find_entry → iget → ext3_read_inodeext3_read_inode 根據 inode 類型賦值 i_fop/i_op:
ext3_file_operations(open 為 generic_file_open 空實現)ext3_dir_operationsext3_symlink_operationsinit_special_inode → def_chr_fops/def_blk_fopsnameidata_to_filp → __dentry_open 動態分配 struct file,複製 inode->i_fop 到 file->f_opfile->f_op->open(若存在)字符設備 open 入口為 chrdev_open,其核心邏輯:
inode->i_cdev 或 kobj_lookup 找到 struct cdevfilp->f_op = fops_get(cdev->ops) 替換為驅動註冊的 file_operationsopen 方法register_filesystem(&ext3_fs_type) 註冊 get_sb = ext3_get_sb → 掛載時 vfs_kern_mount → ext3_get_sb → get_sb_bdev(ext3_fill_super) → ext3_fill_super 中 sb->s_op = &ext3_sops 完成掛鉤。
| 操作集 | 掛載對象 | 典型方法 |
|---|---|---|
| inode_operations | inode 元數據 | create、lookup、unlink、rename |
| file_operations | 打開文件實例 | read、write、mmap、ioctl、poll |
| super_operations | 文件系統整體 | read_inode、write_inode、statfs、sync_fs |