Windows 驱动程序替代 Linux 设备驱动程序 sysfs 接口
让我描述一下 sysfs 的作用:它是一个伪文件系统,其中文件、目录由核心内核或内核驱动程序生成。这些文件具有读/写访问权限,是一种通过用户空间控制某些内核级参数的机制(与 ioctl 和文件操作分开)。
以下是用户空间如何与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).
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 */
...
}
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 :
B. File Object
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论