简体   繁体   English

Linux驱动程序和Sysfs

[英]Linux Drivers and Sysfs

So I have been reading into Linux APIs (syscalls and libc) as well as device ioctls., calling ioctls via create(dev_name) and ioctl(device_file_handle) and the sysfs file system. 因此,我一直在阅读Linux API(syscalls和libc)以及设备ioctl。通过create(dev_name)ioctl(device_file_handle)以及sysfs文件系统调用ioctls。 So here are my questions: 所以这是我的问题:

  1. Is sysfs 'supposed' to be a read only where various Kernel parameters are exposed to be read ? sysfs是否“假定”为只读,其中公开了要读取的各种内核参数? Or are they 'supposed' to be writable too ? 还是他们“应该”也可写?

  2. Are all drivers in future required to expose interfaces in sysfs ? 将来是否需要所有驱动程序才能公开sysfs接口?

  3. If the answer to the above is true, then would we be really requiring IOCTL calls at all anymore? 如果上述答案是正确的,那么我们真的会再需要IOCTL呼叫了吗? because all that we would need to do to make a driver do something is to change values in some of the files in sysfs, eg, To call a ioctl called DO_SOMETHING on driver D1, we would be doing : 因为要做驱动程序要做的所有事情就是更改sysfs中某些文件的值,例如,要在驱动程序D1上调用一个名为DO_SOMETHING的ioctl,我们将这样做:

     echo 1> /sysfs/D1/IOCTLS/DO_SOMETHING ( or something like that ... :) ) 
  4. Are there any plans of exposing the kernel API (that is syscalls and libc ) as sysfs files, eg, 是否有任何计划将内核API(即syscalls和libc)公开为sysfs文件,例如,

     echo 1> /sysfs/libc/get_system_time cat /sysfs/libc/results/system_time 

    Would it be a good idea to do this ? 这样做是个好主意吗?

  5. Is there any sysfs like system in Windows ? Windows中是否有类似sysfs的系统? Or any ongoing projects maybe? 还是正在进行的任何项目?

  6. How about exposing core system calls , libc and any new libraries over http ? 如何通过http公开核心系统调用,libc和任何新库? ( Just wanted a frank discussion on this idea) (只想对此主题进行坦率的讨论)

  1. a) No. b) It depends. a)否b)视情况而定。
  2. I didn't hear about such requirement. 我没有听说过这样的要求。
  3. You have to provide a protocol to exchange between caller and kernel. 您必须提供一个在调用方和内核之间交换的协议。 You may check how it's done in Plan9. 您可以检查在Plan9中是如何完成的。 We will require IOCTL, read more about this on SO answer 我们将需要IOCTL,有关更多信息,请参见SO Answer
  4. Have you given a thought about security? 您是否考虑过安全性? It will be a big hole in the OS I presume. 我认为这将是操作系统中的一个大漏洞。
  5. Out of my knowledge. 据我所知。
  6. Won't discuss. 不会讨论。

Please find my inline reply of your questions: 请找到您的问题的我的在线答复:

1) We can perform both the read and write operation through sysfs; 1)我们可以通过sysfs进行读写操作; again it depends upon your requirements. 再次取决于您的要求。

2) I don't think so; 2)我不这么认为; both sysfs and ioctl have there own advantages so you can not compare both in the same ways. sysfs和ioctl都有各自的优势,因此您不能以相同的方式进行比较。

3) Its not true. 3)这是不正确的。

4)Sysfs APIs (show and store APIs)are already exposed to user space. 4)Sysfs API(显示和存储API)已经暴露给用户空间。 you can call these APIs from user space. 您可以从用户空间调用这些API。

5) It may be; 5)可能是; but I am not sure. 但我不确定。

1 - > No sysfs can be implemented for write also . 1->无法为写也不能实现sysfs。 User can use it something like this . 用户可以这样使用它。 echo " Hello" > /sys/devices/***/sysfs_entry 回声“你好”> / sys / devices / *** / sysfs_entry

2 -> No I think most of the platform related drivers open sysfs interfaces 2->不,我认为大多数与平台相关的驱动程序都打开sysfs接口

3 -> Answer to above question in No . 3->对第一个问题的回答。 We still need ioctls . 我们仍然需要ioctl。

4 -> I believe only the useful API's with some feature involved are exposed as sysfs entries. 4->我相信只有涉及某些功能的有用API才会作为sysfs条目公开。 For example the device behind the driver has 100 registers. 例如,驱动程序后面的设备有100个寄存器。 Each registers are not exposed as sysfs entries. 每个寄存器都不作为sysfs条目公开。 But if there are 3-4 features involving these registers those features are exposed as sysfs entries. 但是,如果涉及这些寄存器的3-4个功能将这些功能作为sysfs条目公开。 These entries should not cause any errors / panic on wrong data . 这些条目不应引起任何错误/对错误数据的恐慌。 That responsibility is there on the developer. 该责任在开发人员身上。

5 -> No idea. 5->不知道。

6 -> No idea. 6->不知道。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM