2

I am writing Linux Kernel module, where I'm creating some sysfs files to store variables.

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?

2
  • are you asking if there is a way to point to functions? "How would be the show, store, module_init, module_exit functions?" Commented Feb 4, 2014 at 12:21
  • no, I'm asking how to implement these functions. What difference exist between normal variable store on sysfs and array one. Commented Feb 4, 2014 at 12:24

1 Answer 1

3

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. Something like this:

sscanf(input_string, "%d %d %d", value[0], value[1], value[3])
Sign up to request clarification or add additional context in comments.

2 Comments

Isn't there another way? for example, the loopN files on /sys/block : loop0 , loop1 and so on, are all created by hand?
they are created automatically when a loop block device occur. But this is not what you are asking for. You asked for attributes, and in your example you are talking about blocks devices

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.