|
/*
* 这个文件是一个内核模块。
* 内核模块的编译,加载和卸载在前面已经介绍了。
* 这个模块的功能是,创建一个字符设备。
* 这个设备是一块4096字节的共享内存。
* 内核分配的主设备号会在加载模块时显示。
*/
/* 开始例行公事 */
#ifndef __KERNEL__
# define __KERNEL__
#endif
#ifndef MODULE
# define MODULE
#endif
#include #include #ifdef CONFIG_SMP
#define __SMP__
#endif
MODULE_LICENSE("GPL");
/* 结束例行公事 */
#include #include #include #include #include /*
* 关于内核功能库,可以去网上搜索详细资料,
*/
/* 文件被操作时的回调功能 */
static int asdf_open (struct inode *inode, struct file *filp);
static int asdf_release (struct inode *inode, struct file *filp);
static ssize_t asdf_read (struct file *filp, char *buf, size_t count,loff_t *f_pos);
static ssize_t asdf_write (struct file *filp, const char *buf, size_t count,loff_t *f_pos);
static loff_t asdf_lseek (struct file * file, loff_t offset, int orig);
/* 申请主设备号时用的结构, 在linux/fs.h里定义 */
struct file_operations asdf_fops = {
open: asdf_open,
release: asdf_release,
read: asdf_read,
write: asdf_write,
llseek: asdf_lseek,
};
static int asdf_major; /* 用来保存申请到的主设备号 */
static u8 asdf_body[4096]="asdf_body\n"; /* 设备 */
static int
init_module
(){
| Linux服务器傻瓜式安装完全接触 | 08-31 |
| Linux中新闻组服务器和客户端的使 | 08-14 |
| Linux下查找漏洞的几种必备工具 | 08-13 |
| Linux操作系统上摄像头的使用小技 | 08-11 |
| 网络工程师 Linux系统日志的分析 | 08-08 |
| Ubuntu 7.04操作系统下安装Man在 | 07-27 |
| 从USB移动硬盘上引导Portable Li | 07-27 |
| Ghost程序参数四则 系统备份与恢 | 07-27 |
| 系统安全:分级防御对Linux服务器 | 07-24 |
| Linux操作系统中厉害的“七种武器 | 07-21 |
| 体系架构是不是桌面Linux系统的弱 | 07-19 |
| Linux系统的各种后门和日志工具详 | 07-19 |