I am currently writing a Linux Kernel Module (for the first time).
I am trying to use the stat function. I understand that regular imports are not going to work in Kernel code, so I imported their equivalent (that is what I thought...):
#include <linux/stat.h>
#include <linux/errno.h>
#include <linux/unistd.h>
I don't get any error about the imports directly, but I get the following messages:
- error: implicit declaration of function ‘stat’ [-Werror=implicit-function-declaration]
- error: ‘errno’ undeclared (first use in this function)
For the two lines respectively:
int ret = stat(pathname, statbuf);
and
errno = ENOENT;
Any help woule be welcome.
Thank you.
PS: I am working on Kali 4.9.0-kali4-amd64 but I am trying to write something generic, that could work on multiple versions of Linux.
return -ENOENT;if you want the system-call to fail witherrnoset toENOENT. - Some programmer dudestatis the user-space system-call, what you should use instead I don't know myself. Secondly, system-calls should return the negative error code on error, as explained in my previous comment. Try looking at a few example system-calls (if that's what you're writing) to see how they do it. System-calls and error handling is handled very differently inside the kernel than from user-space. - Some programmer dude