代码之家  ›  专栏  ›  技术社区  ›  Some Name

如何使用statx syscall?

  •  0
  • Some Name  · 技术社区  · 7 年前

    Ubuntu 18.04

    我想用 statx Linux内核中引入的SysCall 4.11 . 有一个手动输入:

    #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);
    

    所以我试着自己写一个例子:

    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);
    

    但它根本无法编译。错误是 sizeof(statx) 是未知的。实际上,在 sys/stat.h 但在 linux/stat.h 不包括在 sys/STAT.H . 但包括之后 Linux/STAT.H 问题是没有定义

    int statx(int dirfd, const char *pathname, int flags,
                 unsigned int mask, struct statx *statxbuf);
    

    我以为从那以后

    $ uname -r
    4.15.0-39-generic
    

    4.15.0-39-比4.11更新的通用,我可以使用它。

    发生了什么?

    1 回复  |  直到 7 年前
        1
  •  1
  •   KamilCuk    7 年前

    目前,因为glibc不提供 statx 调用,您必须使用内核定义。所以要么复制 斯塔克斯 从内核中定义结构,或者从Linux内核提供的API中使用它。这个 struct statx 当前在中定义 linux/stat.h .

    Linux提供了一个示例调用 斯塔克斯 可获得的 here .