0

I want to create a binary file in /sys/class/mydev/bitmap to indicate the absence of my device. But it seems that there is no Linux kernel API (like create_device_bin_file) to create a binary file in the class directory. How can I get that?

I have already created a character attribute file in the mydev class. The code is as follows

static int __init module_init(void)
{
    attr.show = pciex_devshow;
    attr.store = pciex_devstore;
    attr.attr.name = "state";
    attr.attr.mode = S_IRUSR | S_IWUSR;
    class_create_file(pciex_class, &attr); 
}

static ssize_t pciex_devshow(struct device *dev, struct device_attribute *attr, char *buf)
{
    struct dev_private *pdev;
    return snprintf(buf, PAGE_SIZE, "%c\r\n", dev_bitmap);
}

dev_bitmap is a hex format variable, how can I explore it to userspace?

Claudio
  • 10,614
  • 4
  • 31
  • 71
hooao
  • 103
  • 1
  • 9

1 Answers1

1

I believe what you're after are these functions:

  • class_create
  • class_destroy

etc. located in include/linux/device.h.

Here's (a bit outdated - function signatures changed a little since then) tutorial how to work with this interface.

drivers/s390/char/tape_class.c contains a good example of creating a device that communicates through this interface.

Also this answer looks like it's going to be helpful.

Community
  • 1
  • 1
rr-
  • 14,303
  • 6
  • 45
  • 67
  • I have created a char attribute file in */sys/class/mydev/status* by calling *class_create_file*. The file *status* can expore kernel object in character, but I want it in hex or bin format. In other words, I want to create a binary format in a existing class. Does it possible? – hooao Dec 27 '15 at 12:07
  • 1
    What does prevent you from interpreting the input/output in the driver itself the way you need? – rr- Dec 27 '15 at 12:14