As we mentioned at the beginning of this section, the device_create_file() API is the one we'll use to create our sysfs file:
int device_create_file(struct device *dev, const struct device_attribute *attr);
In the previous section, you learned how we obtain a device structure (the first parameter for our API). Now, let's figure out how to initialize and use the second parameter; that is, the device_attribute structure. The structure itself is defined as follows:
// include/linux/device.h
struct device_attribute {
struct attribute attr;
ssize_t (*show)(struct device *dev, struct device_attribute *attr,
char *buf);
ssize_t (*store)(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count);
};
The first member, attr, essentially consists of the name of the sysfs file and its mode (permission bitmask). The other two...