Linux FS

数据结构

image.png

inode_operations

这些函数第一个参数都是struct vfsmount *mnt

static const struct inode_operations nfs4_file_inode_operations = {
    .permission = nfs_permission,
    .getattr    = nfs_getattr,
    .setattr    = nfs_setattr,
    .getxattr   = generic_getxattr,
    .setxattr   = generic_setxattr,
    .listxattr  = generic_listxattr,
    .removexattr    = generic_removexattr,
};

file_operations

第一个参数为struct file *filp

const struct file_operations nfs_file_operations = {
    .llseek     = nfs_file_llseek,
    .read       = do_sync_read,
    .write      = do_sync_write,
    .aio_read   = nfs_file_read,
    .aio_write  = nfs_file_write,
    .mmap       = nfs_file_mmap,
    .open       = nfs_file_open,
    .flush      = nfs_file_flush,
    .release    = nfs_file_release,
    .fsync      = nfs_file_fsync,
    .lock       = nfs_lock,
    .flock      = nfs_flock,
    .splice_read    = nfs_file_splice_read,
    .splice_write   = nfs_file_splice_write,
    .check_flags    = nfs_check_flags,
    .setlease   = nfs_setlease,
};

read的调用栈

sys_read
  vfs_read
    __vfs_read
      file->f_op->read //如果read非空则走这里
      filp->f_op->read_iter //如果read空则走这里,对于NFS来说这是nfs_file_read

readdir调用栈

//由C函数readdir()调用
sys_getdents 
  iterate_dir
    file->f_op->iterate //对于NFS来说这是nfs_readdir

file vs inode

  • file: 内核中用struct file表示。表示open的文件,例如两个进程对同一个打开,内存中会有两个file。
  • inode:内核中用struct inode表示。每个文件在文件系统中只有一个inode。
    因此inode和file是1对多的关系。

file => inode

static inline struct inode *file_inode(const struct file *f)
{
    return f->f_inode;
}

dentry

  • d_lookup() : 通过hashtable从dcache中查找
  • d_hash() : hash函数

proc filesystem

create_seq_entry()

你可能感兴趣的:(Linux FS)