为什么我们需要文件->私人数据?
我目前正在学习linux设备驱动程序,一时无法理解基本的字符设备驱动程序代码。
struct scull_pipe {
...
};
static struct scull_pipe *scull_devices;
static int scull_open(struct inode *inode, struct file *filp)
{
struct scull_pipe *dev;
dev = container_of(inode->i_cdev, struct scull_pipe, cdev);
filp->private_data = dev;
...
}
static ssize_t scull_write(struct file *filp, const char __user *buf, size_t count,
loff_t *f_pos)
{
struct scull_pipe *dev = filp->private_data;
...
if (copy_from_user(dev->wp, buf, count)) {
...
}
}
我的问题是为什么我们需要使用 filp->private_data
中的 scull_devices
而不是直接引用 scull_devices
对象?
I'm currently learning linux device drivers and can't understand one moment from basic character device driver code.
struct scull_pipe {
...
};
static struct scull_pipe *scull_devices;
static int scull_open(struct inode *inode, struct file *filp)
{
struct scull_pipe *dev;
dev = container_of(inode->i_cdev, struct scull_pipe, cdev);
filp->private_data = dev;
...
}
static ssize_t scull_write(struct file *filp, const char __user *buf, size_t count,
loff_t *f_pos)
{
struct scull_pipe *dev = filp->private_data;
...
if (copy_from_user(dev->wp, buf, count)) {
...
}
}
My question is why do we need to use scull_devices
from filp->private_data
instead of directly referencing scull_devices
object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论