gpt4 book ai didi

c - 用户空间到内核空间和 sysfs 以及如何使用 sysfs 更改 igmpv3 pkt 中的一个保留值

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:12:35 26 4
gpt4 key购买 nike

我之前已经发布了查询,我正在重复同样的问题我想修改 kernel2.6 中内置的 igmpv3 (Linux)。-- 以便它从文件中读取一个值并适本地决定内部的保留 (res 1) 值主机发送的igmpv3数据包。

我想对上述问题补充更多,说这是一个从用户空间更改内核空间变量的更一般的问题。

对此,一位 ctuffli 回复道:

From the perspective of a user land program, you should think of the driver as a "black box" with well defined interfaces instead of code with variables you want to change. Using this mental model, there are four ways (i.e. interfaces) to communicate control information to the driver that you should consider:

  • Command line options. You can pass parameters to a kernel module which are available to it during initialization.
  • IOCTLs. This is the traditional way of passing control information to a driver, but this mechanism is a little more cumbersome to use than sysfs.
  • proc the process information pseudo-file system. proc creates files in the /proc directory which user land programs can read and sometimes write. In the past, this interface was appropriated to also communicate with drivers. Although proc looks similarly to sysfs, newer drivers (Linux 2.6) should use sysfs instead as the intent of the proc is to report on the status of processes.
  • sysfs is a pseudo-file system used to export information about drivers and devices

Depending on when you need to communicate with the driver (i.e. initialization, run time), you should add either a new command line option or a new sysfs entry to change how the driver treats the value of reserved fields in the packet.

感谢 Ctuffli 的回答。我对 sysfs 没有任何了解。你能提供更多细节吗?我想将 igmpv3 pkt 的保留值之一更改为 0 或 1 或 2。这是我唯一需要更改的内容。您能否提供有关此特定问题的更多详细信息?

最佳答案

在这个SO answer中有sysfs(即/sys/...)接口(interface)的描述:

它具体描述了在驱动中添加什么,即:

static ssize_t mydrvr_version_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%s\n", DRIVER_RELEASE);
}

static DEVICE_ATTR(version, S_IRUGO, mydrvr_version_show, NULL);

在驱动程序设置期间:

device_create_file(dev, &dev_attr_version);

关于c - 用户空间到内核空间和 sysfs 以及如何使用 sysfs 更改 igmpv3 pkt 中的一个保留值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2607686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com