Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 如何从linux内核中的目录获取文件列表?_C_Linux_Linux Kernel_Kernel_Virtual Directory - Fatal编程技术网

C 如何从linux内核中的目录获取文件列表?

C 如何从linux内核中的目录获取文件列表?,c,linux,linux-kernel,kernel,virtual-directory,C,Linux,Linux Kernel,Kernel,Virtual Directory,我刚才看到在任何rootfs之前都有一个ROOT/目录(无论是从initrd还是形成磁盘) 我已经知道它确实包含/root和/dev,并且安装了devtmpfs(如果选择了CONFIG\u devtmpfs\u MOUNT) 但我无法找到是否还有其他目录以及它们是什么 因此,关键是在第403行之前的init/do_mounts.c处插入代码,以便将列表打印到屏幕上。 问题是我不知道如何使用struct direent为旧的readdir()(int readdir(unsigned int fd

我刚才看到在任何rootfs之前都有一个ROOT
/
目录(无论是从initrd还是形成磁盘)
我已经知道它确实包含
/root
/dev
,并且安装了devtmpfs(如果选择了
CONFIG\u devtmpfs\u MOUNT

但我无法找到是否还有其他目录以及它们是什么

因此,关键是在第403行之前的
init/do_mounts.c
处插入代码,以便将列表打印到屏幕上。

问题是我不知道如何使用struct direent为旧的
readdir()
int readdir(unsigned int fd,struct dirent*dirp,unsigned int count);

您可以使用filp_open()从内核空间打开文件。
您想使用函数iterate_dir()。

您必须定义一个struct dir_上下文(include/linux/fs.h)并提供某种filldir函数(可能类似于向列表中添加条目)。

记住,这并不是在生产环境中做什么:问题是在访问任何用户空间可执行文件之前,进行肮脏的修改并从虚拟机获取根目录结构。