Linux内核编程(持续整理)

  1. 如何给模块传一个数组性参数

    #include <linux/moduleparam.h>
    static int arr_var[10];
    static int num=0;
    module_param_array(arr_var, int, &num, 0644);//最后一个数字是访问权限
    
  2. /proc编程

    1. 创建entry: struct proc_dir_entry * entry = proc_create("name", 0444, NULL, &file_ops);

      其中parent为NULL即直接创建在/proc目录下, file_ops是文件操作

    2. file_operations

    file_operations的的结构体定义如下,

         struct file_operations {  
            struct module *owner;  
            loff_t (*llseek) (struct file *, loff_t, int);  
            ssize_t (*read) (struct file *, char *, size_t, loff_t *);  
            ssize_t (*write) (struct file *, const char *, size_t, loff_t *);  
            int (*readdir) (struct file *, void *, filldir_t);  
            unsigned int (*poll) (struct file *, struct poll_table_struct *);  
            int (*ioctl) (struct inode *, struct file *, unsigned int, unsigned long);  
            int (*mmap) (struct file *, struct vm_area_struct *);  
            int (*open) (struct inode *, struct file *);  
            int (*flush) (struct file *);  
            int (*release) (struct inode *, struct file *);  
            int (*fsync) (struct file *, struct dentry *, int datasync);  
            int (*fasync) (int, struct file *, int);  
            int (*lock) (struct file *, int, struct file_lock *);  
            ssize_t (*readv) (struct file *, const struct iovec *, unsigned long,  
              loff_t *);  
           ssize_t (*writev) (struct file *, const struct iovec *, unsigned long,  
               loff_t *);  
        };
    

    当我们需要定义自己的文件操作的时候,

    static const struct file_operations proc_read_only_fops = {
        .open = my_open,
        .read = my_read
    };
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值