linux - 如何在 Linux 内核 3.2.x 中的自定义系统调用期间读取目录的内容

标签 linux kernel system-calls opendir

我正在尝试使用 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();

检查此链接:http://lxr.free-electrons.com/source/fs/namei.c#L3352

关于linux - 如何在 Linux 内核 3.2.x 中的自定义系统调用期间读取目录的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13079169/

相关文章:

ruby - 在 nginx 和 thin 下部署 Sinatra 应用程序的最快技巧(当然是 linux)

c++ - catch-all 处理程序中的 exception_ptr 在 Centos 7 和 Windows 上运行异常

linux - Netlink 和安全性如何相互作用?

linux - 有人可以向我指出 bitbake 或 openembedded 教程吗?

linux - Linux 程序集中的文件权限

c++ - 处理 EINTR(使用 goto?)

ruby - 可以通过 ruby​​ 脚本输出当前的 CPU 和内存使用情况吗?我正在尝试查找内存泄漏

c++ - gdb fork() 在 Linux 上执行

ruby - 何时在 Ruby 中使用 Kernel#gsub?

linux - 关于 CVE-2009-0029 : Linux Kernel insecure 64 bit system call argument passing 的困惑