use*_*508 2 mount linux-kernel gpio
在我的initramfs.cpio中,我只有这些目录:
root@localhost extract]# ls
dev init tmp sys
Run Code Online (Sandbox Code Playgroud)
dev有控制台,sys是空的.
init是一个二进制文件,对应于我在内核启动后访问GPIO时讨论过的程序.
现在在同一个GPIO程序中,我想编写代码来挂载/ sys.我知道它可以使用mount挂载:
mount -t sysfs none /sys
Run Code Online (Sandbox Code Playgroud)
如何编写将实现上述代码的C程序.请注意,我没有文件系统; initramfs.cpio有空文件夹:/ sys,/ tmp.如果需要,我可以放更多的空文件夹.但我不能把完整的文件系统.
我的主要目的是 使用此程序或其他方式访问GPIO ,但不使用完整的文件系统.我不需要运行任何其他东西,但只想要GPIO访问(和LED闪烁)
您使用mount(2)系统调用.从联机帮助页:
概要
Run Code Online (Sandbox Code Playgroud)#include <sys/mount.h> int mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags, const void *data);
所以,在你的C代码中,它看起来像:
#include <sys/mount.h>
/* ... */
void mount_sys() {
if (0 != mount("none", "/sys", "sysfs", 0, "")) {
/* handle error */
}
}
Run Code Online (Sandbox Code Playgroud)
(最后一个空字符串是您传递挂载选项的位置,但AFAIK sysfs不接受任何挂载选项.)
| 归档时间: |
|
| 查看次数: |
3520 次 |
| 最近记录: |