我说的不是这个file_operations, 而是 static ssize_t foo_write(struct file *filp, const char __user *buffer, size_t count, loff_t *offp) 这个filp
> On 07 09, 2014, at 19:49, iZobs Lin <ivincent...@gmail.com> wrote: > > /*文件操作结构体*/ > static const struct file_operations globalmem_fops = > { > .owner = THIS_MODULE, > .llseek = globalmem_llseek, > .read = globalmem_read, > .write = globalmem_write, > .ioctl = globalmem_ioctl, > .open = globalmem_open, > .release = globalmem_release, > .poll = globalmem_poll, > .fasync = globalmem_fasync, > }; > 如上,那个fd指向的就是这么个结构体,这个结构体封装了与应用层交互的函数。 > > 在 14/7/9,K roderia<krode...@gmail.com> 写道: >> 是自己写的, 正在学. MISC的操作已经写了, 直接返回一个字符串什么的. 现在的问题是这个filp的含义不太明白, >> 它到底是一个fd指向一个文件还是一个指针指向一个内存空间, 然后如何对它进行操作. 我看ldd3的讲解, 似乎是一个内部动态分配的内存空间, >> 那么它内置的f_ops函数指针是用来干嘛的呢 >> >> >> 2014-07-09 19:07 GMT+08:00 iZobs Lin <ivincent...@gmail.com>: >> >>> 那个module是你自己写的吗?read/write需要自己在module里写。你搜一下char >>> driver,字符设备。有讲这个file_operations的东西。 >>> >>> 在 14/7/9,Kroderia<krode...@gmail.com> 写道: >>>> 找了老半天没找到能看的样例程序, 来求救 >>>> >>>> Linux module里面的file_operations的读写函数, 要对struct file *filp进行读写, 要调用那些函数? >>>> >>> 刚直接用filp->f_ops->read/write把虚拟机都搞崩了...看到有个版本是直接用simple_read_from_buffer对filp->private_data进行写入, >>>> 不过似乎要在init里面进行内存分配, 这个做法可以吗? >>>> >>>> -- >>>> 您收到此邮件是因为您订阅了 Google 网上论坛的“广州 GNU/Linux 用户组”论坛。 >>>> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到gzlug+unsubscr...@googlegroups.com。 >>>> 要向此网上论坛发帖,请发送电子邮件至 gzlug@googlegroups.com。 >>>> 通过以下网址访问此论坛:http://groups.google.com/group/gzlug。 >>>> 要查看更多选项,请访问 https://groups.google.com/d/optout。 >>>> >>> >>> >>> -- >>> *iZobs Lin* >>> *Appreciate Daily Life* >>> >>> -- >>> 您收到此邮件是因为您订阅了 Google 网上论坛的“广州 GNU/Linux 用户组”论坛。 >>> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到gzlug+unsubscr...@googlegroups.com。 >>> 要向此网上论坛发帖,请发送电子邮件至 gzlug@googlegroups.com。 >>> 通过以下网址访问此论坛:http://groups.google.com/group/gzlug。 >>> 要查看更多选项,请访问 https://groups.google.com/d/optout。 >>> >> >> -- >> 您收到此邮件是因为您订阅了 Google 网上论坛的“广州 GNU/Linux 用户组”论坛。 >> 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到gzlug+unsubscr...@googlegroups.com。 >> 要向此网上论坛发帖,请发送电子邮件至 gzlug@googlegroups.com。 >> 通过以下网址访问此论坛:http://groups.google.com/group/gzlug。 >> 要查看更多选项,请访问 https://groups.google.com/d/optout。 >> > > > -- > *iZobs Lin* > *Appreciate Daily Life* > > -- > 您收到此邮件是因为您订阅了 Google 网上论坛的“广州 GNU/Linux 用户组”论坛。 > 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到gzlug+unsubscr...@googlegroups.com。 > 要向此网上论坛发帖,请发送电子邮件至 gzlug@googlegroups.com。 > 通过以下网址访问此论坛:http://groups.google.com/group/gzlug。 > 要查看更多选项,请访问 https://groups.google.com/d/optout。 -- 您收到此邮件是因为您订阅了 Google 网上论坛的“广州 GNU/Linux 用户组”论坛。 要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到gzlug+unsubscr...@googlegroups.com。 要向此网上论坛发帖,请发送电子邮件至 gzlug@googlegroups.com。 通过以下网址访问此论坛:http://groups.google.com/group/gzlug。 要查看更多选项,请访问 https://groups.google.com/d/optout。