Windows 驱动程序替代 Linux 设备驱动程序 sysfs 接口

发布于 2025-01-19 16:57:35 字数 1711 浏览 0 评论 0原文

让我描述一下 sysfs 的作用:它是一个伪文件系统,其中文件、目录由核心内核或内核驱动程序生成。这些文件具有读/写访问权限,是一种通过用户空间控制某些内核级参数的机制(与 ioctl 和文件操作分开)。

  1. 来自 Kernel.org 的 Sysfs
  2. 来自 Wikipedia 的 Sysfs

以下是用户空间如何与sysfs。

    $ cat /sys/modules/mydriver/foo_count
    1 
    $ echo "2" > /sys/modules/mydriver/foo_count  $ cat /sys/modules/mydriver/foo_count
    2

cat 命令将通过 show_foo_count() 内核例程触发读取,而 echo 将通过 store_foo_count( ) 例程

下面是内核驱动程序/模块如何拦截用户空间活动。

static ssize_t show_foo_count(struct kobject *kobj,struct kobj_attribute *attr,
                                  char *buf)
{
    /* This will perform a read operation and contents of buf will be updated*/
    ...
}
static ssize_t store_foo_count(struct kobject *kobj, struct kobj_attribute *attr,
                               const char *buf,size_t len)
{
    /* Contents are read from buf and stored within the driver's context/state */
    ...

}

这里有一个很好的例子

如何在 Windows 驱动程序上实现相同的 sysfs 使用?

我看到以下 Windows 概念,但我无法将它们映射为 syfs 的等效项:

A. 设备对象

B. 文件对象

Let me describe what sysfs does : its a pseudo file system where files, directories are generated by the core kernel or kernel drivers. And these files have read/write access and are a mechanism to control certain kernel level parameters by user space (seperate from ioctls and file operations).

  1. Sysfs from Kernel.org
  2. Sysfs from Wikipedia

The following is an example of how userspace interacts with sysfs.

    $ cat /sys/modules/mydriver/foo_count
    1 
    $ echo "2" > /sys/modules/mydriver/foo_count  $ cat /sys/modules/mydriver/foo_count
    2

The cat command will trigger a read via the show_foo_count() kernel routine, while the echo will trigger a write via the store_foo_count() routine

The following is how the kernel driver/module might intercept the user space activity.

static ssize_t show_foo_count(struct kobject *kobj,struct kobj_attribute *attr,
                                  char *buf)
{
    /* This will perform a read operation and contents of buf will be updated*/
    ...
}
static ssize_t store_foo_count(struct kobject *kobj, struct kobj_attribute *attr,
                               const char *buf,size_t len)
{
    /* Contents are read from buf and stored within the driver's context/state */
    ...

}

A good example is here

How can one achieve the same sysfs usage on windows drivers ?

I see the following windows concepts, but I am unable to map them to be the equivalent of syfs :

A. Device Objects

B. File Object

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文