Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
ffits
V2EX  ›  Linux

求教一个问题:内核空间和用户空间如何交换结构体变量的数据?

  •  
  •   ffits · Mar 16, 2014 · 3367 views
    This topic created in 4515 days ago, the information mentioned may be changed or developed.
    内核模块中定义了一个结构体变量,希望在用户空间编程修改其属性,通过sysfs 、procfs 和 ctl_table是不是一次只能修改一个属性?或者还有没有其他的方法? 感谢
    2 replies    1970-01-01 08:00:00 +08:00
    ffits
        1
    ffits  
    OP
       Mar 16, 2014
    已解决:

    在模块中注册一个字符设备,实现其write函数。write的原形是ssize_t write(struct file *filp, const void __user *buff, size_t len, loff_t *off), 其中buff可以强制转换为struct类型。在write函数中使用copy_from_user函数,就可以将buff变量赋给内核中的某个变量。
    heiher
        2
    heiher  
       Apr 24, 2014
    要注意一些位宽可能变化的类型,如 long 等,32-bit 4-byte, 64-bit 8-byte.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4894 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 05:40 · PVG 13:40 · LAX 22:40 · JFK 01:40
    ♥ Do have faith in what you're doing.