我正在尝试使用 openDir 在 Linux 内核 (3.2.17) 中的自定义系统调用期间打开一个目录:
#include <linux/kernel.h>
#include <linux/unistd.h>
#include <linux/types.h> // also tried "asm/types.h"
#include <linux/dirent.h>
#include <linux/stat.h>
asmlinkage
int sys_mycall( const char* srcDir ) {
DIR* dir_p;
struct dirent *dirEntry;
struct stat inode;
dir_p = opendir(srcDir);
...
...
}
但是,编译器找不到它需要的东西
mycall.c:9:5: error: unknown type name ‘DIR’
mycall.c:14:5: error: implicit declaration of function ‘opendir’ [-Werror=implicit-function-declaration]
如果这是一个用户空间应用程序,那么我会#include <dirent.h>
和 <sys/types.h>
,但我没有这些可用的。编译器似乎没有任何问题可以找到上面的头文件,但它显然没有得到它需要的东西。
是否可以从另一个系统调用进行此调用?
我在另一个相关问题中看到有人建议实现或重用所需系统调用在幕后所做的事情,而不是直接调用它。
如果可能的话,有人可以告诉我打电话需要什么吗(同样,这是 Linux 3.2.17)。
谢谢。
编辑:
这似乎是要走的路:How do I open a directory at kernel level using the file descriptor for that directory?
最佳答案
是的,可以从另一个系统调用进行系统调用。但它有局限性。
此外,您不能在内核中使用 opendir()
。
尝试寻找struct nameidata nd
使用 user_path_parent();
关于linux - 如何在 Linux 内核 3.2.x 中的自定义系统调用期间读取目录的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13079169/