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?

Abhijeet Kasurde
  • 3,937
  • 1
  • 24
  • 33
2rdv1
  • 25
  • 4
  • are you asking if there is a way to point to functions? `"How would be the show, store, module_init, module_exit functions?"` – Babbleshack Feb 04 '14 at 12:21
  • no, I'm asking how to implement these functions. What difference exist between normal variable store on sysfs and array one. – 2rdv1 Feb 04 '14 at 12:24

1 Answers1

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])
Federico
  • 3,782
  • 32
  • 46
  • Isn't there another way? for example, the loopN files on _/sys/block_ : _loop0_ , _loop1_ and so on, are all created by hand? – 2rdv1 Feb 05 '14 at 17:44
  • 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 – Federico Feb 05 '14 at 17:56