本章介紹了下面符號和標頭檔. struct file_operations 和 struct file 中的成員的列表這裡不重複了.
-
#include <linux/types.h>
-
dev_t
-
dev_t 是用來在核心裡代表裝置號的類型.
-
int MAJOR(dev_t dev);
-
int MINOR(dev_t dev);
-
從裝置編號中抽取主次編號的宏.
-
dev_t MKDEV(unsigned int major, unsigned int minor);
-
從主次編號來建立 dev_t 資料項目的宏定義.
-
#include <linux/fs.h>
-
"檔案系統"標頭檔是編寫裝置驅動需要的標頭檔. 許多重要的函數和資料結構在此定義.
-
int register_chrdev_region(dev_t first, unsigned int count, char *name)
-
int alloc_chrdev_region(dev_t *dev, unsigned int firstminor, unsigned int count, char *name)
-
void unregister_chrdev_region(dev_t first, unsigned int count);
-
允許驅動分配和釋放裝置編號的範圍的函數. register_chrdev_region 應當用在事Crowdsourced Security Testing道需要的主編號時; 對於動態分配, 使用 alloc_chrdev_region 代替.
-
int register_chrdev(unsigned int major, const char *name, struct file_operations *fops);
-
老的( 2.6 之前) 字元裝置註冊函數. 它在 2.6 核心中被類比, 但是不應當給新代碼使用. 如果主編號不是 0, 可以不變地用它; 否則一個動態編號被分配給這個裝置.
-
int unregister_chrdev(unsigned int major, const char *name);
-
恢複一個由 register_chrdev 所作的註冊的函數. major 和 name 字串必須包含之前用來註冊裝置時同樣的值.
-
struct file_operations;
-
struct file;
-
struct inode;
-
大部分裝置驅動使用的 3 個重要資料結構. file_operations 結構持有一個字元驅動的方法; struct file 代表一個開啟的檔案, struct inode 代表磁碟上的一個檔案.
-
#include <linux/cdev.h>
-
struct cdev *cdev_alloc(void);
-
void cdev_init(struct cdev *dev, struct file_operations *fops);
-
int cdev_add(struct cdev *dev, dev_t num, unsigned int count);
-
void cdev_del(struct cdev *dev);
-
cdev 結構管理的函數, 它代表核心中的字元裝置.
-
#include <linux/kernel.h>
-
container_of(pointer, type, field);
-
一個傳統宏定義, 可用來擷取一個結構指標, 從它裡麵包含的某個其他結構的指標.
-
#include <asm/uaccess.h>
-
這個包含檔案聲明核心代碼使用的函數來移動資料到和從使用者空間.
-
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);
-
在使用者空間和核心空間拷貝資料.