2

我正在编写 Linux 内核模块,我在其中创建一些 sysfs 文件来存储变量。

但我需要实现数组,例如:

struct ats {
   struct attribute attr;
   unsigned long value[5];
};

struct ats m_ats = {
   .attr.name="m_ats",
   .attr.mode = 0644,
   .value[0] = 0,
   .value[1] = 0,
   .value[2] = 0,
   .value[3] = 0,
   .value[4] = 0,
};

有没有办法做到这一点?show、store、module_init、module_exit 功能如何?

4

1 回答 1

3

您必须手动完成。您可以sscanf在传入的字符串上使用,解析输入并将每个值存储在数组槽中。像这样的东西:

sscanf(input_string, "%d %d %d", value[0], value[1], value[3])
于 2014-02-05T10:31:48.260 回答