c - 如何使用 statx 系统调用?

标签 c linux stat

Ubuntu 18.04

我正在尝试使用 Linux 内核 4.11 中引入的 statx 系统调用。有一个手动输入:

#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.11 更新的 4.15.0-39-generic 我可以使用它。

怎么了?

最佳答案

目前,由于 glibc 不为 statx 调用提供包装器,您必须使用内核定义。因此,要么从内核复制 statx 结构定义,要么从 linux 内核提供的 API 中使用它。 struct statx 当前在 linux/stat.h 中定义。

linux 提供了一个调用 statx 的例子 here .

在 glibc 2.28 中添加了@update 库支持

关于c - 如何使用 statx 系统调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53810990/

相关文章:

C - 如何将文件从 cifs 挂载到本地硬盘

c - 尝试将两个尺寸为 1000*1000 的大矩阵相乘会导致段错误

c - Telnet 从服务器启用线路模式

linux - 是否可以在 Linux bash 中限制子进程的 pid?

C : call to stat() erases a string variable?

c - C 中使用 ncursesw 输出 "█"

c - 数组:C 中的左旋转

linux - 我正在尝试 grep 文件夹并为结果创建一个变量以供进一步需要

node.js - 纳秒分辨率的 mtime/ctime/atime 与 Node 的 fs.stat

c - 从 stat(2) 打印信息