#ifndef LLVM_LIBC_SRC_SYS_STAT_LINUX_KERNEL_STATX_H
#define LLVM_LIBC_SRC_SYS_STAT_LINUX_KERNEL_STATX_H
#include "src/__support/OSUtil/syscall.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include <stdint.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <linux/kdev_t.h>
namespace {
struct statx_timestamp {
int64_t tv_sec;
uint32_t tv_nsec;
int32_t __reserved;
};
struct statx_buf {
uint32_t stx_mask;
uint32_t stx_blksize;
uint64_t stx_attributes;
uint32_t stx_nlink;
uint32_t stx_uid;
uint32_t stx_gid;
uint16_t stx_mode;
uint16_t __spare0[1];
uint64_t stx_ino;
uint64_t stx_size;
uint64_t stx_blocks;
uint64_t stx_attributes_mask;
struct statx_timestamp stx_atime;
struct statx_timestamp stx_btime;
struct statx_timestamp stx_ctime;
struct statx_timestamp stx_mtime;
uint32_t stx_rdev_major;
uint32_t stx_rdev_minor;
uint32_t stx_dev_major;
uint32_t stx_dev_minor;
uint64_t stx_mnt_id;
uint64_t __spare2;
uint64_t __spare3[12];
};
constexpr unsigned int STATX_BASIC_STATS_MASK = 0x7FF;
}
namespace LIBC_NAMESPACE_DECL {
LIBC_INLINE int statx(int dirfd, const char *__restrict path, int flags,
struct stat *__restrict statbuf) {
::statx_buf xbuf;
int ret = LIBC_NAMESPACE::syscall_impl<int>(SYS_statx, dirfd, path, flags,
::STATX_BASIC_STATS_MASK, &xbuf);
if (ret < 0)
return -ret;
statbuf->st_dev = MKDEV(xbuf.stx_dev_major, xbuf.stx_dev_minor);
statbuf->st_ino = static_cast<decltype(statbuf->st_ino)>(xbuf.stx_ino);
statbuf->st_mode = xbuf.stx_mode;
statbuf->st_nlink = xbuf.stx_nlink;
statbuf->st_uid = xbuf.stx_uid;
statbuf->st_gid = xbuf.stx_gid;
statbuf->st_rdev = MKDEV(xbuf.stx_rdev_major, xbuf.stx_rdev_minor);
statbuf->st_size = xbuf.stx_size;
statbuf->st_atim.tv_sec = xbuf.stx_atime.tv_sec;
statbuf->st_atim.tv_nsec = xbuf.stx_atime.tv_nsec;
statbuf->st_mtim.tv_sec = xbuf.stx_mtime.tv_sec;
statbuf->st_mtim.tv_nsec = xbuf.stx_mtime.tv_nsec;
statbuf->st_ctim.tv_sec = xbuf.stx_ctime.tv_sec;
statbuf->st_ctim.tv_nsec = xbuf.stx_ctime.tv_nsec;
statbuf->st_blksize = xbuf.stx_blksize;
statbuf->st_blocks =
static_cast<decltype(statbuf->st_blocks)>(xbuf.stx_blocks);
return 0;
}
}
#endif