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

📄 test.c

📁 周立功ARM7试验箱
💻 C
字号:
#ifndef __KERNEL__    #define __KERNEL__#endif#ifndef MODULE    #define MODULE#endif

#include <linux/module.h>#include <linux/sched.h>#include <linux/kernel.h>       /* printk() */#include <linux/init.h>static loff_t test_llseek(struct file *filp, loff_t off, int whence);static ssize_t test_read(struct file *filp, char *buf, size_t count, loff_t *f_pos);static ssize_t test_write(struct file *filp, const char *buf, size_t count,                           loff_t *f_pos);static int test_open(struct inode *inode, struct file *filp);static int test_release(struct inode *inode, struct file *filp); static int test_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,		              unsigned long param);int  test_init(void);void test_cleanup(void);#define MAJOR_NR 125#define DEVICE_NAME "test"               /* name for messaging */module_init(test_init);module_exit(test_cleanup);/********************************************************************************************************/
static struct file_operations test_fops =        /* driver info  */{    owner:      THIS_MODULE,    llseek:     test_llseek,    read:       test_read,    write:      test_write,    ioctl:      test_ioctl,    open:       test_open,    release:    test_release,};        static loff_t test_llseek(struct file *filp, loff_t off, int whence){    return 0;}        static ssize_t test_read(struct file *filp, char *buf, size_t count,                           loff_t *f_pos){    return 0;}        static ssize_t test_write(struct file *filp, const char *buf, size_t count,                            loff_t *f_pos){    return 0;}                        static int  test_open(struct inode *inode, struct file *filp){    MOD_INC_USE_COUNT;    return 0;          /* success */}         static int  test_release(struct inode *inode, struct file *filp) {    MOD_DEC_USE_COUNT;    return(0); }         static int test_ioctl(struct inode *inode, struct file *filp,                     unsigned int cmd, unsigned long arg){    return 0;}        int  test_init(void){    int  result;    result = register_chrdev(MAJOR_NR,  DEVICE_NAME,  &test_fops);     if (result < 0)    {        printk(KERN_ERR DEVICE_NAME ": Unable to get major %d\n", MAJOR_NR );        return(result);     }     printk(KERN_ERR DEVICE_NAME ": init OK\n");    return(0); }        void test_cleanup(void){    unregister_chrdev(MAJOR_NR, DEVICE_NAME);}/***********************************************************************************************************                            End Of File********************************************************************************************************/

⌨️ 快捷键说明

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