Device Driver Functions Reference
#include
The "file system" header is the header required for writing device drivers.All the important functions are declared in here.
int register_chrdev(unsigned int major,const char *name,struct file_operations *fops);
Register a character device driver.If the major number is not 0, it is used unchanged;if the number is 0, then a dynamic number is assigned for this device.
int unregister_chrdev(unsigned int major,const char *name);
Unregisters the driver at unload time.Both major and the name string must contain the same values that were used to register the driver.
kdev_t inode->i_rdev;
The device "number" for the current device is accessible from the inode struct.
int MAJOR(kdev_t dev);
int MINOR(kdev_t dev);
These macros extract the major and minor numbers from a device item.
kdev_t MKDEV(int major,int minor);
This macro builds a kdev_t data item from the major and minor numbers.
SET_MUDULE_OWNER(struct file_operations *fops)
This macro sets the owner field in the given file_operations structure.
Defines functions and types for the ues of semaphores.
void sema_init(struct semaphore *sem,int val);
Initializes a semaphore to a known value.Mutual exclusion semaphores are usually initialized to a value of 1.
int down_interruptible(struct semaphore *sem);
void up(struct semaphore *sem);
Obtains a semaphore (sleeping,if necessary) and releases it, respectively.
segment.h defines functions related to cross-space copying in all kernels up to and including 2.0.The name was changed to uaccess.h in the 2.1 development series.
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.
void memcpy_fromfs(void *to,const void *from,unsigned long count);
void memcpy_tofs(void *to,const void *from,unsigned long count);
These functions were used to copy an array of bytes from user space to kernel space and vice versa in version 2.0 of the kernel.
#include
devfs_handle_t devfs_mk_dir(devfs_handle_t dir, const char *name,void *info);
devfs_handle_t devfs_register(devfs_handle_t dir, const char *name,unsigned int flags, unsigned int major, unsigned int minor, umode_t mode, void *ops, void *info);
void devfs_unregister(devfs_handle_t de);
These are the basic functions for registering devices with the device filesystem(devfs);
阅读(1181) | 评论(0) | 转发(0) |