• 20145202、20145225、20145234 《信息安全系统设计基础》实验四 实时系统的移植


    实验步骤:

    1.配置环境

    2.阅读和理解代码

    #define DEVICE_NAME  "demo"
    static ssize_t demo_write(struct file *filp,const char * buffer, size_t count)
    { 
        char drv_buf[];
        copy_from_user(drv_buf , buffer, count);
        …
    }
    static ssize_t demo_read(struct file *filp,char *buffer,size_t count,loff_t *ppos)
    {
    char drv_buf[];
    copy_to_user(buffer, drv_buf,count);
    ….
    }
    static int demo_ioctl(struct inode *inode, struct file *file,unsigned int cmd, unsigned long arg)
    {
    }
    static int demo_open(struct inode *inode, struct file *file)
    {
    }
    static int demo_release(struct inode *inode, struct file *filp)
    {
        MOD_DEC_USE_COUNT;
        DPRINTK("device release
    ");
        return 0;
    }
    static struct file_operations demo_fops = {
        owner:  THIS_MODULE,
        write:demo_write, 
        read: demo_read, 
        ioctl: demo_ioctl,
        open: demo_open,
        release:demo_release,
    };
    #ifdef CONFIG_DEVFS_FS
    static devfs_handle_t devfs_demo_dir, devfs_demoraw;
    #endif
    static int __init demo_init(void)
    {
        int result;
        #ifdef CONFIG_DEVFS_FS
        devfs_demo_dir = devfs_mk_dir(NULL, "demo", NULL);
        devfs_demoraw = devfs_register(devfs_demo_dir, "0", DEVFS_FL_DEFAULT,
        demo_Major, demo_MINOR, S_IFCHR | S_IRUSR | S_IWUSR,&demo_fops, NULL);
        #else
        SET_MODULE_OWNER(&demo_fops);
        result = register_chrdev(demo_Major, "scullc", &demo_fops);
        if (result < 0) return result;
        if (demo_Major == 0) demo_Major = result; /* dynamic */
        #endif
        printk(DEVICE_NAME " initialized
    ");
        return 0;
    }
    static void __exit demo_exit(void)
    {
        unregister_chrdev(demo_major, "demo");
        kfree(demo_devices);
        printk(DEVICE_NAME " unloaded
    ");
    }
    module_init(demo_init);
    module_exit(demo_exit);

    3.make成功

    4.测试驱动程序
    输入命令./test_demo,插入驱动模块 demo.o

    实验结果:

  • 相关阅读:
    关于React的脚手架
    yarn和npm
    谈谈NPM和Webpack的关系
    php开发环境和框架phalcon的搭建
    Centos6.5--svn搭建
    System.Diagnostics.Process.Start(ProcessStartInfo)
    PHP错误:call to undefined function imagecreatetruecolor
    PostgreSQL删除表中重复数据行
    URL存在http host头攻击漏洞-修复方案
    for循环的执行顺序
  • 原文地址:https://www.cnblogs.com/nizaikanwoma/p/6131853.html
Copyright © 2020-2023  润新知