kernel中的函数指针

经常会看到这类的结构体:

这个结构体中 有几个函数指针, 这种方式的好处,可以有多种具体的函数实现,但是,这样就统一了接口

struct address_space_operations {
    int (*writepage)(struct page *page, struct writeback_control *wbc);
    int (*readpage)(struct file *, struct page *);

    /* Write back some dirty pages from this mapping. */
    int (*writepages)(struct address_space *, struct writeback_control *);

    /* Set a page dirty.  Return true if this dirtied it */
    int (*set_page_dirty)(struct page *page);

    int (*readpages)(struct file *filp, struct address_space *mapping,
            struct list_head *pages, unsigned nr_pages);

    int (*write_begin)(struct file *, struct address_space *mapping,
                loff_t pos, unsigned len, unsigned flags,
                struct page **pagep, void **fsdata);
    int (*write_end)(struct file *, struct address_space *mapping,
                loff_t pos, unsigned len, unsigned copied,
                struct page *page, void *fsdata);

    /* Unfortunately this kludge is needed for FIBMAP. Don't use it */
    sector_t (*bmap)(struct address_space *, sector_t);
    void (*invalidatepage) (struct page *, unsigned int, unsigned int);
    int (*releasepage) (struct page *, gfp_t);
}
const struct address_space_operations v9fs_addr_operations = {
    .readpage = v9fs_vfs_readpage,
    .readpages = v9fs_vfs_readpages,
    .set_page_dirty = __set_page_dirty_nobuffers,
    .writepage = v9fs_vfs_writepage,
    .write_begin = v9fs_write_begin,
    .write_end = v9fs_write_end,
    .releasepage = v9fs_release_page,
    .invalidatepage = v9fs_invalidate_page,
    .launder_page = v9fs_launder_page,
    .direct_IO = v9fs_direct_IO,
};
static int v9fs_vfs_readpage(struct file *filp, struct page *page)
{
    return v9fs_fid_readpage(filp->private_data, page);
}
posted @ 2018-03-09 16:38  苏小北1024  阅读(465)  评论(0编辑  收藏  举报