gpt4 book ai didi

linux - 如何在/sys/class中创建bin属性文件?

转载 作者:太空宇宙 更新时间:2023-11-04 10:42:21 28 4
gpt4 key购买 nike

我想在 /sys/class/mydev/bitmap 中创建一个二进制文件来指示我的设备不存在。但似乎没有 Linux 内核 API(如 create_device_bin_file)在 class 目录中创建二进制文件。我怎样才能得到它?

我已经在mydev 类中创建了一个字符属性文件。代码如下

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 是一个十六进制格式的变量,我如何将它探索到用户空间?

最佳答案

我相信你追求的是这些功能:

  • class_create
  • class_destroy

等位于include/linux/device.h .

Here的(有点过时 - 从那时起函数签名发生了一些变化)教程如何使用此接口(interface)。

drivers/s390/char/tape_class.c包含创建通过此接口(interface)进行通信的设备的一个很好的示例。

还有 this answer看起来会有帮助。

关于linux - 如何在/sys/class中创建bin属性文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34478958/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com