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;
  • 相关阅读:
    FineReport---数据集
    FineReport----单元格元素(数据列、公式、斜线)
    FineReport---样式
    SQL-修改: 将日期修改为空NULL、修改为空的记录
    sql---字段类型转换,保留小数位数,取日期格式,sql获取当前时间,时间处理
    深入浅出Mqtt协议
    一文了解Redis
    RDBMS关系型数据库与HBase的对比
    Greedysky:C++ 建议用 nullptr 而不是 NULL
    Greedysky:C++11 新特性之强制类型转换static_cast
  • 原文地址:https://www.cnblogs.com/guochaoxxl/p/12294203.html
Copyright © 2011-2022 走看看