【问题标题】:How to read the contents of a directory during a custom system call in Linux kernel 3.2.x如何在 Linux 内核 3.2.x 中的自定义系统调用期间读取目录的内容
【发布时间】:2012-10-26 00:16:37
【问题描述】:

我正在尝试在 Linux 内核 (3.2.17) 中使用 openDir 进行自定义系统调用期间打开一个目录:

#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 &lt;dirent.h&gt;&lt;sys/types.h&gt;,但我没有这些可用。编译器似乎没有任何问题可以找到上述头文件,但它显然没有得到它需要的东西。

是否可以从另一个系统调用进行此调用?
我在另一个相关问题中看到有人建议实现或重用所需的系统调用在后台执行的操作,而不是直接调用它。

如果可能的话,有人可以让我知道我需要什么来拨打电话(同样,这是 Linux 3.2.17)。
谢谢。

编辑:
这似乎是要走的路:How do I open a directory at kernel level using the file descriptor for that directory?

【问题讨论】:

    标签: linux kernel system-calls opendir


    【解决方案1】:

    是的,可以从另一个系统调用进行系统调用。但它有局限性。 你也不能在内核中使用opendir()

    尝试寻找struct nameidata nd

    使用user_path_parent();

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

    【讨论】:

      猜你喜欢
      • 2015-12-13
      • 2015-05-05
      • 2014-01-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-13
      • 2018-09-17
      • 2020-01-17
      相关资源
      最近更新 更多