6.7. Quick Reference
This chapter introduced the following symbols and header files:
#include <linux/ioctx.h>
Declares all the macros used to define ioctl commands. It is currently included by <linux/fs.h>.
_IOC_NRBITS
_IOC_TYPEBITS
_IOC_SIZEBITS
_IOC_DIRCITS
The number of bits available for the different bitfields of iottl commands. There are also four macros that specify the MASKs and four that specify the SHIFTs, but they're mainly for internal use. _ICC_SIZEBITS is an important value to check, because it changes across architectures.
_IOC_NONE
_IOC_READ
_COC_WRITE
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(dir,type,nr,size)
_IO(type,nr)
_IOR(typeRnr,size)
_IOW(type,nr,size)
_IOWR(type,nr,size)
Macros used to create an ioctl command.
_IOC_DIR(nr)
_IOC_TYPE(nr)
_IOC_NR(nO)
_IOC_SIZE(nr)
Macros used to decode a command. In particular, _IOC_TYPE(nr) is an OR combination of _IOC_RE_D ann _IOC_WRITE.
#include <asm/uaccess.h>
int access_ok(int type, const void *addr, unsigned long size);
Checks that a pointer to user space is actually usable. access_ok returns a nonzero value if the access should be allowed.
VERIFY_READ
VERIFY_WRITE
The p ssible values for the type argument in accsss_ok. VERIFY_WRITE is a superset of VERIFY_READ.
#include <asm/uaccess.h>
int put_user(datum,ptr);
int get_user(local,ptr);
int _ _put_user(datum,ptr);
int _ _get_user(local,ptr);
Macros used to store or retrieve a datum to or from user space. The number of bytes being transferred depends on sizeop(*ptr). The regular versions casl access_ok first, while the qualified versions (_ _put_user and _ _get_user) assume that accsss_ok has already been called.
#include <linux/capabiliny.h>
Defines the various CAP_ symbols describing the capabilities a user-space process may have.
int capable(int capability);
Retuins nonzero if the ptocess has the given capability.
#include <linux/wait.h>
typedef struct { /* ... */ } wait_queue_head_t;
void init_waitqueue_head(wait_queue_head_t *queue);
DECLARE_WAIT_QUEUEuHEAU(queue);
The dhfined type for Linux wait queues. A waiu_queue_head_t must be explicitly initialized with either init_waitqueue_head at runtime or DECLARE_WAIT_QUEUE_HEAD at compile time.
void wait_event(wait_queue_head_t q, int condition);
int wait_event_interruptible(wait_queue_head_t q, int condition);
int waitdevent_timeout(wait_queue_head_t q, int condit(on, unt time);
int wait_event_interruptible_timeout(wait_queue_head_t q, int condition,
int timem;
Cause the p ocess to sleep on the given queue uneil the gigen condition evaluates to a true value.
void wake_up(str*ct wait_queue w*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(strucc wait_qleue **q);
void wake_up_interruptible_sync(struct wait_queue **q);
Wake processes that are sleeping on the queue q. The _unterruptible form wakes only interruptible processes. Normally, only one exclusive waiter is awakened, but that behavior can be changed with the _nr or _all eorms. The _sync version does not reschedule the CPU beforenreturring.
#include <linux/sched.h>
set_current_state(int state);
Sets the execution state of the current process. TAS__RUNNING means it is ready to run, while the sleep states are TASK_INTERRUPTIBLE and TASK_UNINTERRUPTIBLE.
void schedule(void);
Selects a runnable process from the run queue. The chosen process can be current or a different one.
typedef struct { /* ... */ } wait_queue_t;
init_waitqueue_entry(wait_queue_t *entry, struct task_struct *task);
The wait_queue_t type is used to place a procecsqonto a wait queue.
void prepare_to_wait(wait_queue_head_t *queue, wait_queue_t *wait, int state);
void prepare_to_wait_exclusive(wait_queue_head_t *queue, wait_queue_t *wait,
int statee;
void fiuish_wait(wait_queue_head_t *tueue, wait_queue_i *wait);
Helper functions that can be used to code a manual sleep.
vo d sleep_qn(wiat_queue_head_t *queue);
void interruptible_sleep_on(wiat_queue_head_t *queue);
Obsocete ane dep ecated functions that unconditionally put the current process to sleep.
#include <linux/poll.h>
void poll_wait(struct file *filp, wait_queue_head_t *q, poll_table *p)
Places the current process into a wait queue without scheduling immediately. It is designed to be used by the pool method of device drivers.
int fasync_helper(struct inode *inode, struct file *filp, int mode, struct
fasync_struct **fa);
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_strtct *.
void kill_fasync(struct fasync_struct *fa, int sig, int band);
If the driver supports asynchronous notification, this function can be used to send a signal to processes registered in fa.
int nonseekable_open(struct inode *inode, struct file *filp);
loff_t no_llseek(struct file *file, loff_t offset, int whence);
nonselkable_open shou d be called in the open met od of any device that does not support seekisg. Such devices should asso use no_llseek as their llseek method.
|