0

I'm trying to open a directory during a custom system call in the Linux kernel (3.2.17) using 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);
    ...
    ...
}

However, the compiler can't find what it needs

mycall.c:9:5: error: unknown type name ‘DIR’
mycall.c:14:5: error: implicit declaration of function ‘opendir’ [-Werror=implicit-function-declaration]

If this was a user space application, then I would #include <dirent.h> and <sys/types.h>, but I don't have these available. The compiler doesn't seem to have any trouble finding the above headers, but it's obviously not getting what it need.

Is it possible to make this call from another syscall?
I see in another related question that someone suggested implementing or reusing what the desired syscall is doing under the hood, as opposed to calling it directly.

If it's possible, could someone let me know what I need to make the call (again, this is Linux 3.2.17).
Thanks.

Edit:
This seems to be the way to go: How do I open a directory at kernel level using the file descriptor for that directory?

Community
  • 1
  • 1
Rob
  • 788
  • 8
  • 9

1 Answers1

1

Yes, it is possible to make system call from another system call. But it has limitation. Also you cannot used opendir() in kernel.

Try to look for struct nameidata nd

use user_path_parent();

Check this link: http://lxr.free-electrons.com/source/fs/namei.c#L3352

David Guyon
  • 2,759
  • 1
  • 28
  • 40
suraj_fale
  • 978
  • 2
  • 21
  • 53