From b754b210b7b3419e14f31f3e79a60716d473e169 Mon Sep 17 00:00:00 2001 From: "Mikhail R. Gadelha" Date: Sun, 21 Jul 2024 19:13:53 -0300 Subject: [PATCH] [libc] Fix statvfs test case when SYS_statfs64 is used When SYS_statfs64 is used, struct statfs64 is used instead of struct statfs. This patch adds a define to select the appropriate struct, similar to how it's done internally. This patch also enables fstatvfs and statvfs on riscv, where these are failing to compile without this change. --- libc/config/linux/riscv/entrypoints.txt | 4 ++++ libc/config/linux/riscv/headers.txt | 1 + libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp | 12 +++++++++--- libc/test/src/sys/statvfs/linux/statvfs_test.cpp | 10 ++++++++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt index ea3f36604e45d..14cd006d80c2f 100644 --- a/libc/config/linux/riscv/entrypoints.txt +++ b/libc/config/linux/riscv/entrypoints.txt @@ -266,6 +266,10 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.sys.stat.mkdirat libc.src.sys.stat.stat + # sys/statvfs.h + libc.src.sys.statvfs.fstatvfs + libc.src.sys.statvfs.statvfs + # sys/utsname.h entrypoints libc.src.sys.utsname.uname diff --git a/libc/config/linux/riscv/headers.txt b/libc/config/linux/riscv/headers.txt index da203e9850603..4bb8d23ab961a 100644 --- a/libc/config/linux/riscv/headers.txt +++ b/libc/config/linux/riscv/headers.txt @@ -44,6 +44,7 @@ set(TARGET_PUBLIC_HEADERS libc.include.sys_select libc.include.sys_socket libc.include.sys_stat + libc.include.sys_statvfs libc.include.sys_syscall libc.include.sys_time libc.include.sys_types diff --git a/libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp b/libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp index 0895c33167151..8cb5f867453e4 100644 --- a/libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp +++ b/libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp @@ -9,10 +9,16 @@ #include using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; +#ifdef SYS_statfs64 +using StatFs = statfs64; +#else +using StatFs = statfs; +#endif + namespace LIBC_NAMESPACE_DECL { -static int fstatfs(int fd, struct statfs *buf) { +static int fstatfs(int fd, StatFs *buf) { using namespace statfs_utils; - if (cpp::optional result = linux_fstatfs(fd)) { + if (cpp::optional result = linux_fstatfs(fd)) { *buf = *result; return 0; } @@ -29,7 +35,7 @@ struct PathFD { }; TEST(LlvmLibcSysStatvfsTest, FstatfsBasic) { - struct statfs buf; + StatFs buf; ASSERT_THAT(LIBC_NAMESPACE::fstatfs(PathFD("/"), &buf), Succeeds()); ASSERT_THAT(LIBC_NAMESPACE::fstatfs(PathFD("/proc"), &buf), Succeeds()); ASSERT_EQ(buf.f_type, static_cast(PROC_SUPER_MAGIC)); diff --git a/libc/test/src/sys/statvfs/linux/statvfs_test.cpp b/libc/test/src/sys/statvfs/linux/statvfs_test.cpp index 6719c1ab26865..5329adb54d64d 100644 --- a/libc/test/src/sys/statvfs/linux/statvfs_test.cpp +++ b/libc/test/src/sys/statvfs/linux/statvfs_test.cpp @@ -6,8 +6,14 @@ #include using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher; +#ifdef SYS_statfs64 +using StatFs = statfs64; +#else +using StatFs = statfs; +#endif + namespace LIBC_NAMESPACE_DECL { -static int statfs(const char *path, struct statfs *buf) { +static int statfs(const char *path, StatFs *buf) { using namespace statfs_utils; if (cpp::optional result = linux_statfs(path)) { *buf = *result; @@ -18,7 +24,7 @@ static int statfs(const char *path, struct statfs *buf) { } // namespace LIBC_NAMESPACE_DECL TEST(LlvmLibcSysStatfsTest, StatfsBasic) { - struct statfs buf; + StatFs buf; ASSERT_THAT(LIBC_NAMESPACE::statfs("/", &buf), Succeeds()); ASSERT_THAT(LIBC_NAMESPACE::statfs("/proc", &buf), Succeeds()); ASSERT_EQ(buf.f_type, static_cast(PROC_SUPER_MAGIC));