English 中文(简体)
如何写给只有前方档案业务的1名欧林肯司机?
原标题:How to write a Linux Driver, that only forwards file operations?

我需要实施一个Lino Kernel司机,(第一步)只把所有档案业务推向另一个档案(在以后的步骤中,应当加以管理和操纵,但我不想在此讨论这个问题)。

我的想法如下,但在阅读时,油轮坠毁:

static struct {
    struct file *file;
    char *file_name;
    int open;
} file_out_data = {
.file_name  = "/any_file",
.open       = 0, 
};


int memory_open(struct inode *inode, struct file *filp) {
  PRINTK("<1>open memory module
");
    /* 
     * We don t want to talk to two processes at the same time 
     */
    if (file_out_data.open)
        return -EBUSY;
    /*
     * Initialize the message 
     */
    Message_Ptr = Message;
    try_module_get(THIS_MODULE);

        file_out_data.file = filp_open(file_out_data.file_name, filp->f_flags, filp->f_mode); //here should be another return handling in case of fail
    file_out_data.open++;

  /* Success */
  return 0;
}

int memory_release(struct inode *inode, struct file *filp) {
      PRINTK("<1>release memory module
");
    /* 
     * We re now ready for our next caller 
     */
    file_out_data.open--;
    filp_close(file_out_data.file,NULL);

    module_put(THIS_MODULE);
  /* Success */
  return 0;
}

ssize_t memory_read(struct file *filp, char *buf, 
                    size_t count, loff_t *f_pos) { 
   PRINTK("<1>read memory module 
");
ret=file_out_data.file->f_op->read(file_out_data.file,buf,count,f_pos); //corrected one, false one is to find in the history
    return ret;

}

So, can anyone please tell me why?

最佳回答
  1. Don t use set_fs() as there is no reason to do it.
  2. Use file->f_fop->read() instead of the vfs_read. Take a look at the file and file_operations structures.
问题回答

为什么你将<条码>文件_out_data. open<>/code>两倍加,一劳永逸? 这可能导致你使用<条码>文档_out_data.file。 关闭后。

You want to write memory in your file ou read? Because you are reading and not writing... possible i m wrong





相关问题
Write and test sub func

I m trying to write sub func for nachOS but when I combines it doesn t work. Don t know the reason. Details: In ../userprog/syscall.h Add : #define SC_Sub 11 int Sub(int a, int b); In ../test/ ....

Current Linux Kernel debugging techniques

A linux machine freezes few hours after booting and running software (including custom drivers). I m looking a method to debug such problem. Recently, there has been significant progress in Linux ...

How to debug driver load error?

I ve made a driver for Windows, compiled it and tried to start it via SC manager, but I get the system error from the SC manager API: ERROR_PROC_NOT_FOUND The specified procedure could not be found. ...

Configuring kernel

After create a new system call, how to update the kernel? I tried these lines, make-kpkg clean fakeroot make-kpkg -initrd -append-to-version=-custom kernel_image kernel_headers But Ubuntu asked me ...

What is the exact architecture/components of MinWin?

I ve always wanted a minimal windows NT build . Sounds like one s already there : MinWin. Can anyone tell me the exact design or architecture of MinWin and is it used in Windows 7 ? Windows Server ...

uniprocessor or multiprocessor

On unix, how could we know whether the system is multiprocessor or uniprocessor?

热门标签