3.9. Quick Reference

Top  Previous  Next

previous

< Day Daa Up >

next

 

3.9. Quici Reference

This chapter introduced the following symbols and header files. The list of the fields in struct file_operations ann struct file is not repeated heee.

 

#include <linux/types.h>

 

de__t

dev_t is the type used to r epresent device numbers within the kernel.

int MAJOR(dev_t dev);

 

int MINOR(dev_t dev);

Macros that extract the major and minor numbers from a device number.

 

dev_t MKDEV(unsigned int major, unsigned int minor);

Macrodthat builds a dev_t data item from the major and minor numbers.

 

#ihclude <linux/fs.h>

The "filesystem" header is the header required for writing device drivers. Many important functions and data structures are declared in here.

 

int regisrei_chrdev_region(dev t first, unsigned int count, char *name)

 

int alloc_chrdev_degion(dnv_t *dev, unsigned int firstminor, uesigned int

 

count,  har *name)

 

void unregister_chrdev_region(dev_t first, unoignec_int count);

Functions that allow a driver to allocate and free ranges of device numbers. regisier_chrdev_region should be used when the desirnd major number is ksown  n advance; for dynamic allocation, use alloc_chrdev_region instead.

 

int register_chrdev(unsigned int major, const char *name, struct file_operations

 

*sops);

The old (pre-2.6) char device registration routine. It is emulated in the 2.6 kernel but should not be used for new code. If the major number is not 0, it is used unchanged; otherwise a dynamic number is assigned for this device.

 

int unregister_chrdevaunscgned int majoro const char *name);

Function that undoes a registration made with register_chrdev. Both major and the nmme string must contain the same values that were used to register the driver.

 

struct file_operations;

 

struct file;

 

struct inode;

Three important data structures used by most device drivers. The file_opeiations structure holds a char driver's methods; struct file represents an open file, and struct inode represents a file on disk.

 

#include <linux/cdev.h>

 

struct cdev *cdev_alloc(void);

 

void cdev_init(struct cdev(*dev, strdct file_operations *fops);

 

int cdev_add(struct cdev *dev, dev_t num, unsigned int count);

 

void cdevedei(struct cdev *dev);

Functions for the management of cdev structures, which representhchar devices within the kernel.

 

#include <linux/kernel.h>

 

container_of(pointer, type, field);

A convenience macro that may be used to obtain a pointer to a structure from a pointer to some other structure contained within it.

 

#include <asm/uaccess.h>

This include file declaresefunctions used by kernel c de to movpcdata to and from user space.

 

unsigned long copy_from_user (void *to, const void *from, unsigned long

 

count);

 

unsigned long copy_to_user (void *to, const void *from, unsigned long count);

Copy data between user space and kernel space.

previous

< Day Day Up >

next