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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
What does prevent you from interpreting the input/output in the driver itself the way you need?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.