[libc-commits] [libc] eaa07c0 - [libc] Fix statvfs test case when SYS_statfs64 is used (#99827)

via libc-commits libc-commits at lists.llvm.org
Sun Jul 21 17:21:09 PDT 2024


Author: Mikhail R. Gadelha
Date: 2024-07-21T21:21:05-03:00
New Revision: eaa07c00b10b2105fabed61a95d2a5e0971bc02e

URL: https://github.com/llvm/llvm-project/commit/eaa07c00b10b2105fabed61a95d2a5e0971bc02e
DIFF: https://github.com/llvm/llvm-project/commit/eaa07c00b10b2105fabed61a95d2a5e0971bc02e.diff

LOG: [libc] Fix statvfs test case when SYS_statfs64 is used (#99827)

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, which would not be compiled without this change.

Added: 
    

Modified: 
    libc/config/linux/riscv/entrypoints.txt
    libc/config/linux/riscv/headers.txt
    libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp
    libc/test/src/sys/statvfs/linux/statvfs_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/config/linux/riscv/entrypoints.txt b/libc/config/linux/riscv/entrypoints.txt
index 61a1ef351a4c6..6c557b7a69cb6 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 <linux/magic.h>
 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<LinuxStatFs> result = linux_fstatfs(fd)) {
+  if (cpp::optional<StatFs> 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<decltype(buf.f_type)>(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 <linux/magic.h>
 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<LinuxStatFs> 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<decltype(buf.f_type)>(PROC_SUPER_MAGIC));


        


More information about the libc-commits mailing list