⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testdriver.c

📁 一个能在优龙s3c2410下测试的小模块
💻 C
字号:

#ifndef __KERNEL__

#define __KERNEL__

#endif

#ifndef MODULE

#define MODULE

#endif

 

#include <linux/config.h>

 

#include <linux/init.h>

#include <linux/module.h>

#include <linux/kernel.h>

 

#include <linux/fs.h>

 

MODULE_******("Dual BSD/GPL");

 

int testdriver_major=200;

 

/***************************************OPEN***************************************/

static int testdriver_open(struct inode *inode,struct file *file)

{

     printk("\nIt's in testdriver_open fuction!!!---in the testdriver.ko!!!\n");

     //MOD_INC_USE_COUNT;

     return 0;

}

 

 

/***************************************READ***************************************/

static int testdriver_read(struct inode *node,struct file *file,char *buf,int count)

{

     printk("\nIt's in testdriver_read fuction!!!---in the testdriver.ko!!!\n");

     return count;

}

 

/***************************************WRITE***************************************/

static int testdriver_write(struct inode *inode,struct file *file,const char *buf,int count)

{

     printk("\nIt's in testdriver_write fuction!!!---in the testdriver.ko!!!\n");

     return count;

}

 

 

/***************************************RELEASE***************************************/

static void testdriver_release(struct inode *inode,struct file *file)

{

     printk("\nIt's in testdriver_release fuction!!!---in the testdriver.ko!!!\n");

     //MOD_DEC_USE_COUNT;

}

 

 

 

struct file_operations testdriver_fops=

{

      .read=testdriver_read,

     .write=testdriver_write,

     .open=testdriver_open,

     .release=testdriver_release,

};

 

static int testdriver_init(void)

{

     printk("Hello ,it's a testdriver!!!---in the testdriver.ko!!!\n");

     int ret;

    ret=register_chrdev(testdriver_major,"testdriver",&testdriver_fops);//注册设备

    if(ret<0)

    {

          printk("init_module failed with %d---in the testdriver.ko!!!\n",ret);

           return ret;

    }

    else

    {

           printk("init_module testdriver success!!!---in the testdriver.ko!!!\n");

    }

    return ret; 

}

 

static void testdriver_exit(void)

{

     unregister_chrdev(testdriver_major,"testdriver");

    printk("Goodbye,testdriver!!!---in the testdriver.ko!!!\n");

}

 

module_init(testdriver_init);

module_exit(testdriver_exit);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -