#include <linux/proc_fs.h>
#include <linux/netlink.h>
#include <linux/module.h>
#define CREATE_TRACE_POINTS
#include "test_trace.h"
#undef CREATE_TRACE_POINTS
#define CDEVNAME "test"
static int major;
static struct class *dev_class;
static ssize_t test_write(struct file *file, const char __user *buf,
size_t count, loff_t *f_pos)
{
char test[128];
printk("test: cdev_write.\n");
if (copy_from_user(test, buf, count)) {
goto exit;
}
else
*f_pos += count;
trace_test_trace(current);
return count;
exit:
return -1;
}
static const struct file_operations test_fops = {
.owner = THIS_MODULE,
.write = test_write,
};
static int test_init(void)
{
printk("test init.\n");
major = register_chrdev(0, CDEVNAME, &test_fops);
if (major < 0) {
pr_err("test: register_chrdev.\n");
return major;
}
dev_class = class_create(THIS_MODULE, "testclass");
if (IS_ERR(dev_class)) {
unregister_chrdev(major, CDEVNAME);
pr_err("test: class_create.\n");
return PTR_ERR(dev_class);
}
device_create(dev_class, NULL, MKDEV(major, 0), NULL, CDEVNAME);
return 0;
}
static void test_exit(void)
{
printk("test exit.\n");
device_destroy(dev_class, MKDEV(major, 0));
class_destroy(dev_class);
unregister_chrdev(major, CDEVNAME);
}
module_init(test_init);
module_exit(test_exit);
MODULE_LICENSE("GPL");
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
pci.tar.gz (4个子文件)
pci
test.c 1KB
README 561B
Makefile 325B
test_trace.h 755B
共 4 条
- 1
坤昱
- 粉丝: 5687
- 资源: 32
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 2013-2022vc运行命令库
- probleme.exe
- 基于python完成对csv文件的读取并且通过flask框架显示
- 基于SpringBoot的“体质测试数据分析及可视化”的设计与实现.zip
- c语言-c语言编程基础之leetcode题解第21题合并两个有序链表.zip
- 快速开发API服务的框架
- c语言-c语言编程基础之leetcode题解第20题有效的括号.zip
- c语言-c语言编程基础之leetcode题解第19题删除链表的倒数第N个结点.zip
- c语言-c语言编程基础之leetcode题解第17题电话号码的字母组合.zip
- c语言-c语言编程基础之leetcode题解第16题最接近的三数之和.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0