zoukankan      html  css  js  c++  java
  • procfs、debugfs

    procfs 是进程文件系统(file system) 的缩写,包含一个伪文件系统,用于通过内核访问进程信息
    这个文件系统通常被挂载到 /proc 目录。由于 /proc 不是一个真正的文件系统,它也就不占用存储空间,只是占用有限的内存

    伪文件系统
    用户和应用程序可以通过proc得到系统的信息,并可以改变内核的某些参数。proc文件系统是动态从系统内核读出所需信息并提交的

    优点
    在调试时修改某些内核变量,而printk无能为力;为了修改某个值重新编译内核或者驱动过于低效

    安装文件系统

    # mount -t debugfs none /mnt

    头文件

    linux/debugfs.h

    创建目录

    struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);

    创建文件

    struct dentry *debugfs_create_file(const char *name, mode_t mode, struct dentry *parent, void *data, 
    const struct file_operations *fops);

    name就是创建的名字;parent是父目录;mode是这个文件读写权限;data是传入的参数;fops为实现在该文件上进行文件操作的fiel_operations结构指针

    变量处理

    struct dentry *debugfs_create_u8(const char *name, mode_t mode, struct dentry *parent, u8 *value);
    struct dentry *debugfs_create_u16(const char *name, mode_t mode, struct dentry *parent, u16 *value);
    struct dentry *debugfs_create_u32(const char *name, mode_t mode, struct dentry *parent, u32 *value);
    struct dentry *debugfs_create_u64(const char *name, mode_t mode, struct dentry *parent, u64 *value);
    struct dentry *debugfs_create_bool(const char *name, mode_t mode, struct dentry *parent, u32 *value);
    struct dentry *debugfs_create_blob(const char *name, mode_t mode, struct dentry *parent, struct debugfs_blob_wrapper *blob);

    删除文件

    void debugfs_remove(struct dentry *dentry);
    void debugfs_remove_recursive(struct dentry *dentry);

    举例
    debugfs

    my_debugfs_root = debugfs_create_dir("mydebug", NULL); //根目录
    sub_dir = debugfs_create_dir("subdir", my_debugfs_root); //子目录
    debugfs_create_u8("a", 0644, my_debugfs_root, &a);
    
    char hello[32] = "Hello world!
    ";
    struct debugfs_blob_wrapper b;
    
    b.data = (void *)hello;
    b.size = strlen(hello) + 1;
    debugfs_create_blob("b", 0644, my_debugfs_root, &b);
    
    struct file_operations c_fops = {
        .owner = THIS_MODULE,
        .open = c_open,
        .read = c_read,
        .write = c_write,
    };
    
    debugfs_create_file("c", 0644, sub_dir, NULL, &c_fops);
  • 相关阅读:
    bzoj1951 [Sdoi2010]古代猪文
    bzoj2693 jzptab
    数学一本通第三章总结
    poj1019 Number Sequence
    SGU179 Brackets light
    字母组合2
    字母组合
    Java基础知识强化之集合框架笔记09:Collection集合迭代器使用的问题探讨
    Java基础知识强化之集合框架笔记08:Collection集合自定义对象并遍历案例(使用迭代器)
    Java基础知识强化之集合框架笔记07:Collection集合的遍历之迭代器遍历
  • 原文地址:https://www.cnblogs.com/zhangxuechao/p/11709820.html
Copyright © 2011-2022 走看看