热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

编写一个字符设备驱动程序,实现module_init和module_exit中的注册函数和卸载函数,并在注册函数和卸载函数中打印注册成功信息和卸载成功信息

编写一个字符设备驱动程序,实现module_init和module_exit中的注册函数和卸载函数,并在注册函数和卸载函数中打印注册成功信息和卸载成功信

编写一个字符设备驱动程序,实现module_init和module_exit中的注册函数和卸载函数,并在注册函数和卸载函数中打印注册成功信息和卸载成功信息,在/var/log/syslog日志文件中查看。#

#Makefile

obj-m := helo.o
KDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
        $(MAKE) -C $(KDIR) M=$(PWD) modules              
clean:
        rm -rf *.o *.ko *.mod.* *.symvers *.order

 

/*hello.c*/

#include
MODULE_LICENSE("Dual BSD/GPL");
#include
#include
#define nn 200
struct file_operations gk=
{
};

static int __init hello_init(void)
{
    int k;
    printk(KERN_ALERT "Hello,world!\n");
    k=register_chrdev(nn ,"drive",&gk);
    return 0;
}

static void __exit hello_exit(void)
{
    printk(KERN_ALERT "Goodbye,cruel world!\n");
    unregister_chrdev(nn,"drive");
}

module_init(hello_init);
module_exit(hello_exit);

 


推荐阅读
author-avatar
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有