title: How to create a simple sysfs class attribute in Linux kernel v3.2
body: <p>I'm learning how to use <strong>sysfs</strong> in my Linux modules, but I'm having the hardest time finding current documentation on these topics. The <a href="http://www.makelinux.net/ldd3/chp-14-sect-5" rel="noreferrer">Linux Device Drivers 3rd Edition</a> book I've been using seems to be rather dated in this area unfortunately (e.g. the <code>class_device</code> structure appears to be completely gone in current Linux versions).</p>
  
  <p>I'm simply trying to get an attribute to appear, under the respective <strong>sysfs</strong> class for my module, that will allow me to read the value of a module variable from kernel space.</p>
  
  <p>In my code, I have a class created that allows udev to create a device node at <em>/dev/foo</em> for my module:</p>
  
  <pre><code>dev_t foo_dev;
  alloc_chrdev_region(&amp;foo_dev, 0, 1, "bar");
  
  struct class *bar = class_create(THIS_MODULE, "bar");
  
  device_create(bar, NULL, foo_dev, NULL, "foo");
  
  struct cdev foo_dev_file;
  cdev_init(&amp;foo_dev_file, &amp;fops); /* fops defined earlier */
  cdev_add(&amp;foo_dev_file, foo_dev, 1);
  </code></pre>
  
  <p>When I insert the module I get a <strong>sysfs</strong> class directory created and populated with some default attributes at <em>/sys/class/bar/foo/</em>. How can I create attributes that show up under this new directory?</p>
  
  <p>I have the concepts down pretty well I believe -- create attribute structure, define <code>sysfs_ops</code> functions, etc -- my problem is that I don't know which particular kernel structure to use (<code>class_attribute</code>?), nor how to make these attributes appear under the right <strong>sysfs</strong> directory.</p>
  
  <p>Would anyone point me to a tutorial or article detailing the process for current Linux kernels?</p>