[英]How to store an array on sysfs in Linux kernel module?
I am writing Linux Kernel module, where I'm creating some sysfs files to store variables. 我正在写Linux Kernel模块,在其中创建一些sysfs文件来存储变量。
But I need to implement arrays, something like: 但是我需要实现数组,例如:
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,
};
Is there a way to do that? 有没有办法做到这一点? How would be the show, store, module_init, module_exit functions?
show,store,module_init,module_exit函数如何?
You have to do it manually . 您必须手动进行 。 You can use
sscanf
on the incoming string, parse the input and store each value in the array slot. 您可以对输入的字符串使用
sscanf
,解析输入并将每个值存储在数组插槽中。 Something like this: 像这样:
sscanf(input_string, "%d %d %d", value[0], value[1], value[3])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.