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. jquery的liveQuery插件

    一.livequery插件简介 jQuery的事件绑定功能使得jQuery代码与HTML代码能够完全分离,这样代码的层次关系更加清晰,维护起来也更加简单.然而对于动态加载到页面的HTML元素,每次都需 ...

  2. C++之在类内部访问对象的私有成员

    一.引言 今天看项目里的一段代码发现,竟然可以再类的成员函数中访问该类的对象的私有成员.感觉不可思议. 自己写的实例代码: #include <iostream> using namesp ...

  3. 中兴ZXV10 B860AV1.1 全TTL操作完美破解

    本文转自:http://www.znds.com/tv-496624-1-1.html 1)前期准备工作 1.1 拆开盒子,TTL接线,这个论坛里有好多其它帖子,就不再详细描述. 1.2 复制需要安装 ...

  4. mouseover mouseenter mouseout mouseleave

    mouseover与mouseenter 不论鼠标指针穿过被选元素或其子元素,都会触发 mouseover 事件. 只有在鼠标指针穿过被选元素时,才会触发 mouseenter 事件. mouseou ...

  5. [转]VC传递消息sendmessage

    SendMessage的基本结构如下: SendMessage( HWND hWnd,  //消息传递的目标窗口或线程的句柄. UINT Msg, //消息类别(这里可以是一些系统消息,也可以是自己定 ...

  6. sqlite3命令读出sqlite3格式的文件内容案例

    /*********************************************************************  * Author  : Samson  * Date   ...

  7. zabbix监控数据库

    Zabbix通过percona监控MySQL   因为Zabbix自带的MySQL监控没有提供可以直接使用的Key,所以一般不采用,业界的同学们都使用Percona Monitoring Plugin ...

  8. IDEA 中 右键新建时,没有新建class的解决方案

    今天在用IDEA新建包后,因为我新建的包名是userprivman-data这样的包,然后导致右键后没法新建类,并且在新建包名的时候就提示:不合法的包名,可能不会新建类 然后右键单击包名,发现没有新建 ...

  9. Go语言入门系列2 基本语法

    get download and install packages and dependencies install = compile and install packages and depend ...

  10. 原生Orcale数据库连接

    package tj.test.demo; import java.sql.Connection;import java.sql.DriverManager;import java.sql.Prepa ...