Linux file System (ii)-Virtual file system __linux

Source: Internet
Author: User

The

Virtual file system layer provides most of the functions like vfs_xxx, and they end up calling the struct inode_operations and struct of the virtual file system that each specific file system is registered to File_ Some operation functions in operations and other structure bodies. Take the FAT file system as an example, he registered struct inode_operations and struct file_operations as follows:

fs/fat/namei_vfat.c
static const struct Inode_operations vfat_dir_inode_operations = {
        . Create         = Vfat_ Create,
        . Lookup         = vfat_lookup,
        . Unlink         = Vfat_unlink,
        . mkdir          = Vfat_mkdir,
        . rmdir          = Vfat_rmdir,
        . Rename         = Vfat_rename,
        . SetAttr        = fat_setattr,
        . getattr        = Fat_ GetAttr,
};

fs/fat/file.c
const struct File_operations fat_file_operations = {
        . Llseek         = Generic_file_llseek,
        . Read           = Do_sync_read,
        . Write          = Do_sync_write,
        . Aio_read       = Generic_file_aio_read,
        . Aio_write      = Generic_file_aio_write,
        . mmap           = Generic_file_mmap,
        . Release        = Fat_ File_release,
        . Unlocked_ioctl = Fat_generic_ioctl,
        . Fsync          = Fat_file_fsync,
        . Splice_read    = Generic_file_splice_read,
};
Open System Call
FS/OPEN.C
syscall_define3 (open, const char __user *, filename, ...)
    Do_sys_open
        do_filp_open//fs/namei.c
            path_openat
                do_last
                    lookup_open
                        Finish _open
                            do_dentry_open
                                f->f_op = Fops_get (INODE->I_FOP);

In the open, the structure in the inode is struct file_operations i_fop the stored function pointer to the structure in file struct file_operations f_op, later read, Functions called write and so on are the callback functions in the struct file_operations structure here. Write system call

fs/read_write.c
syscall_define3 (write, ...
    ) Vfs_write
        file->f_op->write (FAT file system is Do_sync_write)
        do_sync_write
            filp->f_op->aio_write (FAT file system is Generic_file_aio_write)
            Generic_file_aio_write//mm/filemap.c
                __generic_file_aio_write
                    generic_file_buffered_write
                        generic_ Perform_write
                            a_ops->write_begin
                            iov_iter_copy_from_user_atomic
                            a_ops->write_end

First, system call write calls the function in the virtual file system Vfs_write,vfs_write will eventually call the F_op->aio_write function in the struct file_operations function that the FAT file system registers. Generic_file_aio_write is a function implemented in a MM/FILEMAP.C file that writes data to the page cache and waits for the write-back thread to write page cache to disk. mkdir system Call

FS/NAMEI.C
syscall_define2 (mkdir, ...
    Sys_mkdirat
syscall_define3 (Mkdirat, ...
    Vfs_mkdir (struct inode *dir, struct dentry *dentry, ...)
        Dir->i_op->mkdir

mkdir system calls are not the same as write system calls, he calls functions in the struct inode_operations structure in the inode, and the write system calls the struct in file File_ Operations the function in the structure body.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.