Chinaunix首页 | 论坛 | 博客
  • 博客访问: 464678
  • 博文数量: 134
  • 博客积分: 3056
  • 博客等级: 中校
  • 技术积分: 1150
  • 用 户 组: 普通用户
  • 注册时间: 2010-05-14 15:53
文章分类
文章存档

2013年(1)

2010年(133)

我的朋友

分类: LINUX

2010-08-11 23:26:02

Declares all the macros used to define ioctl commands. It is currently included by .

#include <linux/ioctl.h>



The number of bits available for the different bitfields of ioctl commands. There are also four macros that specify the MASKs and four that specify the SHIFTs, but they’re mainly for internal use.  IOC_SIZEBITS is an important value to check, because it changes across architectures.

_IOC_NRBITS
_IOC_TYPEBITS
_IOC_SIZEBITS
_IOC_DIRBITS



The possible values for the “direction” bitfield. “Read” and “write” are different bits and can be ORed to specify read/write. The values are 0-based.

_IOC_NONE
_IOC_READ
_IOC_WRITE



Macros used to create an ioctl command.

_IOC(dir,type,nr,size)
_IO(type,nr)
_IOR(type,nr,size)
_IOW(type,nr,size)
_IOWR(type,nr,size)



Macros used to decode a command. In particular, _IOC_TYPE(nr) is an OR combination of _IOC_READ and _IOC_WRITE.

_IOC_DIR(nr)
_IOC_TYPE(nr)
_IOC_NR(nr)
_IOC_SIZE(nr)



Checks that a pointer to user space is actually usable. access_ok returns a nonzero value if the access should be allowed.

#include <asm/uaccess.h>
int access_ok(int type, const void *addr, unsigned long size);



The possible values for the type argument in access_ok. VERIFY_WRITE is a superset of VERIFY_READ.

VERIFY_READ
VERIFY_WRITE



Macros used to store or retrieve a datum to or from user space. The number of bytes being transferred depends on sizeof(*ptr). The regular versions call access_ok first, while the qualified versions (__put_user and __get_user) assume that access_ok has already been called.

#include <asm/uaccess.h>
int put_user(datum,ptr);
int get_user(local,ptr);
int __put_user(datum,ptr);
int __get_user(local,ptr);



Defines the various CAP_ symbols describing the capabilities a user-space process may have.

#include <linux/capability.h>



Returns nonzero if the process has the given capability.

int capable(int capability);



The defined type for Linux wait queues. A wait_queue_head_t must be explicitly nitialized with either init_waitqueue_head at runtime or DECLARE_WAIT_QUEUE_HEAD at compile time.

#include <linux/wait.h>
typedef struct { /* ... */ } wait_queue_head_t;
void init_waitqueue_head(wait_queue_head_t *queue);
DECLARE_WAIT_QUEUE_HEAD(queue);



Cause the process to sleep on the given queue until the given condition evaluates o a true value.

void wait_event(wait_queue_head_t q, int condition);
int wait_event_interruptible(wait_queue_head_t q, int condition);
int wait_event_timeout(wait_queue_head_t q, int condition, int time);
int wait_event_interruptible_timeout(wait_queue_head_t q, int condition,int time);



Wake processes that are sleeping on the queue q. The _interruptible form wakes only interruptible processes. Normally, only one exclusive waiter is awakened, but that behavior can be changed with the _nr or _all forms. The _sync version does not reschedule the CPU before returning.

void wake_up(struct wait_queue **q);
void wake_up_interruptible(struct wait_queue **q);
void wake_up_nr(struct wait_queue **q, int nr);
void wake_up_interruptible_nr(struct wait_queue **q, int nr);
void wake_up_all(struct wait_queue **q);
void wake_up_interruptible_all(struct wait_queue **q);
void wake_up_interruptible_sync(struct wait_queue **q);



Sets the execution state of the current process. TASK_RUNNING means it is ready to run, while the sleep states are TASK_INTERRUPTIBLE and TASK_UNINTERRUPTIBLE.

#include <linux/sched.h>
set_current_state(int state);



Selects a runnable process from the run queue. The chosen process can be current or a different one.

void schedule(void);



Obsolete and deprecated functions that unconditionally put the current process to sleep.

void sleep_on(wiat_queue_head_t *queue);
void interruptible_sleep_on(wiat_queue_head_t *queue);



Places the current process into a wait queue without scheduling immediately. It is designed to be used by the poll method of device drivers.

#include <linux/poll.h>
void poll_wait(struct file *filp, wait_queue_head_t *q, poll_table *p)



A “helper” for implementing the fasync device method. The mode argument is the same value that is passed to the method, while fa points to a device-specific fasync_struct *.

int fasync_helper(struct inode *inode, struct file *filp, int mode, struct fasync_struct **fa);



If the driver supports asynchronous notification, this function can be used to send a signal to processes registered in fa.

void kill_fasync(struct fasync_struct *fa, int sig, int band);



nonseekable_open should be called in the open method of any device that does not support seeking. Such devices should also use no_llseek as their llseek method.

int nonseekable_open(struct inode *inode, struct file *filp);
loff_t no_llseek(struct file *file, loff_t offset, int whence);


阅读(629) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~