zoukankan      html  css  js  c++  java
  • linux设备驱动程序

    LDD:linux device driver ,在操作系统作用下,应用程序必须要通过设备驱动程序操作设备

    驱动程序:应用程序和设备之间必须通过驱动程序

    应用程序 ——> write(ioctl)驱动程序——>(write)设备

    应用程序 <——read(ioctl)驱动程序——>(read)设备

    LDD程序结构:

    LDD程序加载方式:

    LDD程序测试:

    文件操作结构体在/lib/modules/5.5.2-1-MANJARO/build/include/linux/fs.h中的定义为:

     1 struct file_operations {
     2     struct module *owner;
     3     loff_t (*llseek) (struct file *, loff_t, int);
     4     ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
     5     ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
     6     ssize_t (*read_iter) (struct kiocb *, struct iov_iter *);
     7     ssize_t (*write_iter) (struct kiocb *, struct iov_iter *);
     8     int (*iopoll)(struct kiocb *kiocb, bool spin);
     9     int (*iterate) (struct file *, struct dir_context *);
    10     int (*iterate_shared) (struct file *, struct dir_context *);
    11     __poll_t (*poll) (struct file *, struct poll_table_struct *);
    12     long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
    13     long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
    14     int (*mmap) (struct file *, struct vm_area_struct *);
    15     unsigned long mmap_supported_flags;
    16     int (*open) (struct inode *, struct file *);
    17     int (*flush) (struct file *, fl_owner_t id);
    18     int (*release) (struct inode *, struct file *);
    19     int (*fsync) (struct file *, loff_t, loff_t, int datasync);
    20     int (*fasync) (int, struct file *, int);
    21     int (*lock) (struct file *, int, struct file_lock *);
    22     ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
    23     unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
    24     int (*check_flags)(int);
    25     int (*setfl)(struct file *, unsigned long);
    26     int (*flock) (struct file *, int, struct file_lock *);
    27     ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
    28     ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
    29     int (*setlease)(struct file *, long, struct file_lock **, void **);
    30     long (*fallocate)(struct file *file, int mode, loff_t offset,
    31               loff_t len);
    32     void (*show_fdinfo)(struct seq_file *m, struct file *f);
    33 #ifndef CONFIG_MMU
    34     unsigned (*mmap_capabilities)(struct file *);
    35 #endif
    36     ssize_t (*copy_file_range)(struct file *, loff_t, struct file *,
    37             loff_t, size_t, unsigned int);
    38     loff_t (*remap_file_range)(struct file *file_in, loff_t pos_in,
    39                    struct file *file_out, loff_t pos_out,
    40                    loff_t len, unsigned int remap_flags);
    41     int (*fadvise)(struct file *, loff_t, loff_t, int);
    42 } __randomize_layout;
  • 相关阅读:
    RedisCluster的rename机制失败报错,解决又是数据倾斜问题
    开发如何避免redis集群访问倾斜和数据倾斜
    Pika 连接 rabbitmq 集群
    RabbitMQ概念及环境搭建(三)RabbitMQ cluster
    Rabbitmq安装过程和踩过的坑( 二 集群搭建 )
    java中<<、>>、>>>
    用WordPress 插入广告的几种方法
    macOS Mojave 卡顿问题解决
    前端元编程——使用注解加速你的前端开发
    如何优雅安全地在深层数据结构中取值
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/12294203.html
Copyright © 2011-2022 走看看