从struct file到struct super_block

时间:2012-03-07 22:14:39

标签: c linux linux-kernel

我刚刚在Linux设备驱动程序

之后实现了一个简单的驱动程序(scull device

在read函数中,我想获取文件系统的名称。所以我做了一些改变。

ssize_t scull_read(struct file *filp, char __user *buf, size_t count,
            loff_t *f_pos)
{
    struct scull_dev *dev = filp->private_data; 
    struct scull_qset *dptr;        /* the first listitem */
    int quantum = dev->quantum, qset = dev->qset;
    int itemsize = quantum * qset; /* how many bytes in the listitem */
    int item, s_pos, q_pos, rest;
    ssize_t retval = 0;

//start of change

    struct super_block *sp;
    const char *name;

    /** Get the super_block via struct inode, it works **/
    sp = flip->f_path.dentry->d_inode->i_sb;
    name = sp->s_type->name;

    /** Get the super_block via struct vfsmount, not works **/
    sp = flip->f_path.mnt->mnt_sb;

//end of change

    if (down_interruptible(&dev->sem))
            return -ERESTARTSYS;
    if (*f_pos >= dev->size)
            goto out;
    if (*f_pos + count > dev->size)
            count = dev->size - *f_pos;
    ....

要通过inode获取super_block,一切运行良好。

但是当我试图通过vfsmount结构获取super_block时,我在编译时遇到错误

 error: dereferencing pointer to incomplete type

似乎vfsmount结构中的super_block未初始化。

对我来说,无论我们选择哪种方法,都应该获得相同的super_block。但奇怪的是第二种方法不起作用。

如果我错误理解,请更正。

修改

以下是头文件的内容

#include <linux/module.h>
#include <linux/cdev.h>
#include <linux/moduleparam.h>
#include <linux/types.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/slab.h>
#include <linux/semaphore.h>
#include <linux/kernel.h>
#include <asm/uaccess.h>
#include "scull.h"

0 个答案:

没有答案
相关问题