c - 如何使用 statx 系统调用?
问题描述
Ubuntu 18.04
我正在尝试使用statx
Linux Kernel 中引入的系统调用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-generic 比 4.11 更新我可以使用它。
怎么了?
解决方案
目前,由于 glibc 没有为statx
调用提供包装器,因此您必须使用内核定义。所以要么从你的内核复制statx
结构定义,要么只从 linux 内核提供的 API 中使用它。当前struct statx
在 中定义linux/stat.h
。
linux在此处statx
提供了一个可用的示例调用。
在 glibc 2.28 中添加了 @update 库支持
推荐阅读
- python-3.x - 从 pyqt5 的新窗口返回一个值
- html - 子菜单项的名称包含在下拉菜单中
- react-native - 是否有任何 proteus(运行时布局引擎)版本的 react-native?
- java - 在 Java 中使用 BigDecimal 理解数学运算
- entity-framework - 无法使用 Ef Core 删除数据库迁移
- javascript - 如何使用反应参考设置背景图像?
- python - 具有动态键名Python的递归dict flattener
- python - 在python中接收HTTP响应中的正文内容
- flutter - Flutter 国际化:如何访问 json 中的嵌套数据
- python - 如何通过分隔符拆分列,同时尊重要分隔的项目的相对位置