<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:12pt"><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt;">Hi all,</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 12pt;"><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 16px; color: rgb(0, 0, 0); background-color: transparent; font-style: normal;">I am creating a module that has a lot of configuration parameters (of _Bool type). These parameters are set to 0 or 1 using sysfs attributes registered in an attribute group of one&nbsp;<span style="background-color: transparent;">kobject.</span><span style="background-color: transparent;">&nbsp;Each attribute show just printfs the var and attrbute store just scanfs the corresponding variable of the same name.</span></div><div style="font-family: 'times new roman', 'new york',
 times, serif; font-size: 16px; color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><span style="background-color: transparent;"><br></span></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 16px; color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><span style="background-color: transparent;">I have just one show and one store function that is shared among all attributes, in an effort to minimise repetition.</span></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 16px; color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 16px; color: rgb(0, 0, 0); background-color: transparent; font-style: normal;">My problem is that I don't know how to make this single 'show' function simple enough, so that it does not have to parse the name of
 each file read in order to find out which variable to work with.</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 16px; color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 16px; color: rgb(0, 0, 0); background-color: transparent; font-style: normal;">To make this more clear, here is my code right now for the show function of the attribute group:</div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 16px; color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><br></div><div style="background-color: transparent;"><span style="font-family: 'times new roman', 'new york', times, serif;">_Bool system_status = 1;</span></div><div style="background-color: transparent;"><span style="font-family: 'times new roman', 'new york', times, serif;">_Bool&nbsp;confoptionA=
 1;</span></div><div style="background-color: transparent;"><span style="font-family: 'times new roman', 'new york', times, serif;">_Bool&nbsp;confoptionB&nbsp;= 0;</span></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: 'times new roman', 'new york', times, serif; font-style: normal;">...</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: 'times new roman', 'new york', times, serif; font-style: normal;"><span style="font-size: 16px;">_Bool&nbsp;confoptionZ</span><span style="font-size: 16px;">&nbsp;= 0;</span><br></div><div style="font-family: 'times new roman', 'new york', times, serif; font-size: 16px; color: rgb(0, 0, 0); background-color: transparent; font-style: normal;"><br></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif">static ssize_t option_show(struct kobject *kobj, struct kobj_attribute *attr,
 char *buf)</font></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif">{</font></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif"><span class="Apple-tab-span" style="white-space:pre">        </span>size_t count = 0;</font></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif">&nbsp; &nbsp; &nbsp; &nbsp; if (strcmp(attr-&gt;attr.name, "system_status") == 0){</font></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif"><span class="Apple-tab-span" style="white-space:pre">                </span>count = sprintf(buf, "%d\n", system_status);</font></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif"><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div style="background-color: transparent;"><font face="times new
 roman, new york, times, serif">&nbsp; &nbsp; &nbsp; &nbsp; else if (strcmp(attr-&gt;attr.name, "confoptionA") == 0){</font></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif"><span class="Apple-tab-span" style="white-space:pre">                </span>count = sprintf(buf, "%lu\n",&nbsp;confoptionA);</font></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif"><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif">&nbsp; &nbsp; &nbsp; &nbsp; else if (strcmp(attr-&gt;attr.name, "confoptionB") == 0){</font></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif"><span class="Apple-tab-span" style="white-space:pre">                </span>count = sprintf(buf, "%d\n",&nbsp;confoptionB);</font></div><div style="background-color:
 transparent;"><font face="times new roman, new york, times, serif"><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif">&nbsp; &nbsp; &nbsp; &nbsp; else if (strcmp(attr-&gt;attr.name, "confoptionC") == 0){</font></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif"><span class="Apple-tab-span" style="white-space: pre;">                </span>count = sprintf(buf, "%d\n",&nbsp;confoptionC);</font></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif"><span class="Apple-tab-span" style="white-space: pre;">        </span>}</font></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: 'Times New Roman'; font-style: normal;"><span class="Apple-tab-span" style="white-space:pre">        </span>.....</div><div style="background-color:
 transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: 'Times New Roman'; font-style: normal;"><br></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif">&nbsp; &nbsp; &nbsp; &nbsp; return count;</font></div><div style="background-color: transparent;"><font face="times new roman, new york, times, serif">}</font></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: 'times new roman', 'new york', times, serif; font-style: normal;"><font face="times new roman, new york, times, serif"><br></font></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: 'times new roman', 'new york', times, serif; font-style: normal;">This repeats for all my 40something options.&nbsp;</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: 'times new roman', 'new york', times, serif;
 font-style: normal;"><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: 'times new roman', 'new york', times, serif; font-style: normal;">Surely this is not ideal and there has to be a better way to do it!</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: 'times new roman', 'new york', times, serif; font-style: normal;"><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: 'times new roman', 'new york', times, serif; font-style: normal;">Any ideas?</div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: 'times new roman', 'new york', times, serif; font-style: normal;"><br></div><div style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: 'times new roman', 'new york', times, serif; font-style: normal;">Thanks,</div><div
 style="background-color: transparent; color: rgb(0, 0, 0); font-size: 16px; font-family: 'times new roman', 'new york', times, serif; font-style: normal;">GeorgeW</div></div></body></html>