Ubuntu 18.04
I'm trying to use statx
syscall introduced in the Linux Kernel 4.11
. There is a manual entry:
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h> /* Definition of AT_* constants */
int statx(int dirfd, const char *pathname, int flags,
unsigned int mask, struct statx *statxbuf);
So I tried to write an example by myself:
const char *dir_path = NULL;
const char *file_path = NULL;
//read from command line arguments
int dir_fd = open(dir_path, O_DIRECTORY);
struct statx st; //<--------------------------- compile error
statx(dir_fd, file_path, 0, &statx);
But it simply does not compile. The error is the sizeof(statx)
is unknown. And actually it is not defined in sys/stat.h
, but in linux/stat.h
which is not included by sys/stat.h
. But after including linux/stat.h
the problem is there is no definition for
int statx(int dirfd, const char *pathname, int flags,
unsigned int mask, struct statx *statxbuf);
I expected that since
$ uname -r
4.15.0-39-generic
and 4.15.0-39-generic newer than 4.11 I can use it.
What's wrong?
statx()
system call; call it usingsyscall(2)
." – Janinastruct statx
definition defined inlinux/stat.h
? I thought headers fromlinux/xxx.h
were sort of kernel private so I'm not really sure. – Murmansklinux/xx.h
includes is a part of kernel API or ABI - it is the interface to access linux things from userspace things. For common features across systems programs can useglibc
ormusl
or other standard C library and POSIX (and other standards) implementations. Currentlyglibc
library does not implementstatx
call, so you have to use kernel api. – Ashmeadsyscall
s orioctl
s on device drivers. What do you mean by the interface to access linux things from userspace things? – Murmanskkernel/xxx.h
. Thenglibc
is build upon that API and provides it's own API.glibc
translatesprintf("...")
in number ofsyscall(__NR_write, ...)
thenkernel/xxx.h
tellsglibc
what the number behind__NR_write
is. You may not useglibc
and callsyscall
yourself. Asglibc
does not provide a wrapper forstatx
, you have to callsyscall
yourself. – Ashmead