ioctl


//user space
int ioctl(int fd,unsigned long cmd,...);

//kernel space
int (*ioctl)(struct inode *inode,struct file* filp,unsigned int cmd,unsigned long arg)

Blocking I/O

#include <linux/wait.h>

wait_queue_head_t my_queue;

DECLARE_WAIT_QUEUE_HEAD(name);

init_waitqueue_head(&my_queue);
wait_event(queue,condition);

wait_event_interruptible(queue,condition);

wait_event_timeout(queue,condition,timeout);

wait_event_interruptible_timeout(queue,condition,timeout);

void wake_up(wait_queue_head_t *queue);

void wake_up_interruptible(wait_queue_head_t *queue);

Manual sleeps

DEFINE_WAIT(my_wait);

void prepare_to_wait(wait_queue_head_t *queue,wait_queue_t *wait,int state);

void schedule();//combine with condition check 

void finish_wait(wait_queue_head_t *queue,wait_queue_t *wait);

poll and select

unsigned int (*poll)(struct file *filp,struct poll_table *wait);

eg:

static unsigned int scull_p_poll(struct file *filp, poll_table *wait)
{
    struct scull_pipe *dev = filp->private_data;
    unsigned int mask = 0;
    /*
    * The buffer is circular; it is considered full
    * if "wp" is right behind "rp" and empty if the
    * two are equal.
    */
    down(&dev->sem);
    poll_wait(filp, &dev->inq, wait);
    poll_wait(filp, &dev->outq, wait);
    if (dev->rp != dev->wp)
        mask |= POLLIN | POLLRDNORM; /* readable */
    if (spacefree(dev))
        mask |= POLLOUT | POLLWRNORM; /* writable */
    up(&dev->sem);
    return mask;
}

Linux kernel Programming - Advanced Char Driver Operations的更多相关文章

  1. Linux kernel Programming - Allocating Memory

    kmalloc #include <linux/slab.h> void *kmalloc(size_t size,int flags); void kfree(void *addr); ...

  2. Linux kernel support docker storage driver aufs

    How to make docker use aufs in CentOS 7? - Server Faulthttps://serverfault.com/questions/650208/how- ...

  3. Linux kernel Programming - Concurrency and Race Conditions

    Concurrency and Its Management Race condition can often lead to system crashes, memory leak,corrupte ...

  4. Linux Kernel Programming - Time,Delays,and Deferred Work

    Measuring Time Lapses The counter and the utility functions to read it live in <linux/jiffies.h&g ...

  5. Linux kernel AACRAID Driver Compat IOCTL 本地安全绕过漏洞

    漏洞名称: Linux kernel AACRAID Driver Compat IOCTL 本地安全绕过漏洞 CNNVD编号: CNNVD-201311-390 发布时间: 2013-11-29 更 ...

  6. linux内核可以接受的参数 | Linux kernel启动参数 | 通过grub给内核传递参数

    在Linux中,给kernel传递参数以控制其行为总共有三种方法: 1.build kernel之时的各个configuration选项. 2.当kernel启动之时,可以参数在kernel被GRUB ...

  7. Intel 80x86 Linux Kernel Interrupt(中断)、Interrupt Priority、Interrupt nesting、Prohibit Things Whthin CPU In The Interrupt Off State

    目录 . 引言 . Linux 中断的概念 . 中断处理流程 . Linux 中断相关的源代码分析 . Linux 硬件中断 . Linux 软中断 . 中断优先级 . CPU在关中断状态下编程要注意 ...

  8. Linux Kernel中断子系统来龙去脉浅析【转】

    转自:http://blog.csdn.net/u011461299/article/details/9772215 版权声明:本文为博主原创文章,未经博主允许不得转载. 一般来说,在一个device ...

  9. Linux kernel的中断子系统之(七):GIC代码分析

    返回目录:<ARM-Linux中断系统>. 总结: 原文地址:<linux kernel的中断子系统之(七):GIC代码分析> 参考代码:http://elixir.free- ...

随机推荐

  1. 如何在UWP中统一处理不同设备间的页面回退逻辑

    已经有一段时间没有写博客来记录自己的学习点滴了.现在回想起来确实有些惭愧,期间经历了一些事情,到目前为止算是平息了,是时候该收收心来充实自己了. 在本篇缪文中,楼主打算给UWP开发的初学者讲述一个在开 ...

  2. javascript刷新父页面的各种方法汇总

    1.用iframe.弹出子页面刷新父页面iframe <script language=JavaScript> parent.location.reload(); </script& ...

  3. 【代码笔记】Web-HTML-列表

    一,效果图. 二,代码. <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  4. 程序员Web面试之前端框架等知识

    基于前面2篇博客: 程序员Web面试之jQuery 程序员Web面试之JSON 您已经可以顺利进入Web开发的大门. 但是要动手干,还需要了解一些已有的前端框架.UI套件,即要站在巨人肩膀上而不是从轮 ...

  5. 二层协议--LLDP协议总结

    二层协议--LLDP协议总结,待完善.

  6. JMeter 集合点设置之Synchronizing Timer的使用

    集合点设置之Synchronizing Timer的使用 by:授客 QQ:1033553122 1.布局设置 注: 1) 说明: 名称:自定义名称 Number of Simulated Users ...

  7. 安卓开发_浅谈DatePicker(日期选择器)

    DatePicker继承自FrameLayout类,日期选择控件的主要功能是向用户提供包含年.月.日的日期数据并允许用户对其修改.如果要捕获用户修改日期选择控件中的数据事件,需要为DatePicker ...

  8. 三. Redis 主从复制

    特点 1. Master可以拥有多个Slave 2. 多个Slave除可以连接一个Master外,还可以连接多个Salve(避免Master挂掉不能同步,当Master挂掉,其中一个Slave会立即变 ...

  9. openCV 色彩空间

    ---恢复内容开始--- 1.使用cv2.inrange()获取某个范围内的图像取值,指定某个通道的最小值和最大值 import numpy as np def color_space(image): ...

  10. 为什么内核访问用户数据之前,要做access_ok?【转】

    linuxer 案例 比如内核的如下commit引入了一个严重的安全漏洞(编号CVE-2017-5123): 危害 一个攻击案例可以参考: freebuf <Linux内核Waitid系统调用本 ...