private_data是Linux下连接VFS文件系统框架和不同文件/文件系统底层实现之间的一个核心数据结构,虽然它只是一个指针,但是一个指针可以解决所有问题。

因 为file是VFS框架的一个基本概念,它要支持文件操作结构,例如open/read/write/release之类的接口,甚至还有poll等,只 有有了这些结构,它们才能被纳入VFS这个大家庭。但是对于不同的设备文件来说,它们只是披着文件外衣的设备,所以他要有自己特有的结构来和设备交流,而 这private_data就是这个连接的纽带。这样说可能还是比较抽象,最后是多看一些代码感受可能会深一些。

实质就是把device设备的private_data指针指向了自己定义的结构体。增加可复用性。

下面是一些使用private_data的文件:

1、tty设备
static ssize_t tty_read(struct file * file, char __user * buf, size_t count, 
            loff_t *ppos)
{
    int i;
    struct tty_struct * tty;
    struct inode *inode;
    struct tty_ldisc *ld;
  tty = (struct tty_struct *)file->private_data;
2、tun/tap设备
static ssize_t tun_chr_aio_read(struct kiocb *iocb, const struct iovec *iv,
                unsigned long count, loff_t pos)
{
    struct file *file = iocb->ki_filp;
    struct tun_struct *tun = file->private_data;
3、套接口文件
static ssize_t do_sock_read(struct msghdr *msg, struct kiocb *iocb,
        struct file *file, const struct iovec *iov,
        unsigned long nr_segs)
{
struct socket *sock = file->private_data;
    size_t size = 0;
4、epoll文件
static int ep_eventpoll_close(struct inode *inode, struct file *file)
{
struct eventpoll *ep = file->private_data;
5、shm文件
long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
{
……
    file->private_data = sfd;

Reference

[1].http://blog.csdn.net/ywh147/article/details/8684486

file结构中的private_data的更多相关文章

  1. Linux_2.6字符设备驱动实例

    第一步:my74hc595.c #include <linux/module.h> //模块所需的大量符号和函数定义#include <linux/init.h> //指定初始 ...

  2. V4L2驱动的移植与应用(一)

    V4L2(video for linux) 可以支持多种设备,它可以有以下5种接口: 1.视频采集接口(video capture interface):这种应用的设备可以是高频头或者摄像头.V4L2 ...

  3. Linux_Struct file()结构体

    struct file结构体定义在/linux/include/linux/fs.h(Linux 2.6.11内核)中,其原型是:struct file {        /*         * f ...

  4. Samsung_tiny4412(驱动笔记04)----volatile,container_of,file_operations,file,inode

    /*********************************************************************************** * * volatile,co ...

  5. 设备文件三大结构:inode,file,file_operations

    驱动程序就是向下控制硬件,向上提供接口,这里的向上提供的接口最终对应到应用层有三种方式:设备文件,/proc,/sys,其中最常用的就是使用设备文件,而Linux设备中用的最多的就是字符设备,本文就以 ...

  6. Linux设备文件三大结构:inode,file,file_operations

    驱动程序就是向下控制硬件,向上提供接口,这里的向上提供的接口最终对应到应用层有三种方式:设备文件,/proc,/sys,其中最常用的就是使用设备文件,而Linux设备中用的最多的就是字符设备,本文就以 ...

  7. Linux Communication Mechanism Summarize

    目录 . Linux通信机制分类简介 . 控制机制 0x1: 竞态条件 0x2: 临界区 . Inter-Process Communication (IPC) mechanisms: 进程间通信机制 ...

  8. linux内核数据结构学习总结

    目录 . 进程相关数据结构 ) struct task_struct ) struct cred ) struct pid_link ) struct pid ) struct signal_stru ...

  9. TCP Socket Establish;UDP Send Package Process In Kernel Sourcecode Learning

    目录 . 引言 . TCP握手流程 . TCP connect() API原理 . TCP listen() API原理 . UDP交互过程 . UDP send() API原理 . UDP bind ...

随机推荐

  1. Nginx 0.8.x + PHP 5.2.13(FastCGI)搭建胜过Apache十倍的Web服务器(第6版)[原创]

    mkdir -p /data0/software cd /data0/software wget http://sysoev.ru/nginx/nginx-0.8.46.tar.gz wget htt ...

  2. 每日英语:Dishing the Dirt on Hand-Washing Guidelines

    Americans aren't washing their hands nearly as often and as thoroughly as they should, according to ...

  3. 03、矢量图形查询工具(Symbol Unicode)

    目前的软件开发中,很多地方都使用到了矢量图标,在 Metro app 的开发中,可以使用 Windows 系统图标(02.Universal app 中按钮图标使用 ),包括 Segoe UI Sym ...

  4. 2、visual studio 常用设置

    1.关闭 “引用” 提示 有时候感觉 “方法” 或者 “类” 上的引用有点乱: 去掉它的步骤: 1)在 “引用”文字上单击鼠标右键: 2)在弹出的“选项” 对话框中,取消 CodeLens: 2.打开 ...

  5. 关于C与python交互设想及文章汇总

    gui: gtk by c 后台: python Python实例浅谈之三Python与C/C++相互调用 Python 与 C/C++ 交互的几种方式 C语言 + GTK3+ Visual Stud ...

  6. Java Mail(一):telnet实现发送收取邮件

    http://blog.csdn.net/ghsau/article/details/8602076 ******************************* 最近要做一个解析邮件的东东,就顺便 ...

  7. Makefile 12——改善编译效率

    从Makefile的角度看,一个可以改善编译效率的地方与其中的隐式规则有关.为了了解make的隐式规则,我们把之前的simple项目的Makefile做一点更改,删除生成.o文件的规则(与隐式规则相对 ...

  8. 搭建自己的GitHub Pages

    本文记录博主使用Win 10操作系统和Jekyll 3.1.2搭建GitHub Pages的过程.希望能帮助到相同有需要的朋友. 基本需求 GitHub账号及一个命名为{GitHub昵称}.githu ...

  9. NPOI导入Excel日期格式的处理 - 附类型格式匹配表

    传统操作Excel方法在部署的时候遇到很多问题,如目标主机需要安装Excel.64位电脑不支持.需要安装相关驱动程序等.所以我们一般会使用开源的NPOI来替代传统的Excel操作方法,NPOI的优点是 ...

  10. java 包 和 物理目录 解惑

    今天做 JUnit 实验, 发现在物理实际不同的目录(src, testsrc)下可以使用相同的包名, 并且在这两个目录下, 都有个子目录 coolUnit (这个子目录是配合 package 使用的 ...