-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[libc] Fix statvfs test case when SYS_statfs64 is used #99827
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-libc Author: Mikhail R. Gadelha (mikhailramalho) ChangesWhen 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. Full diff: https://github.com/llvm/llvm-project/pull/99827.diff 4 Files Affected:
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..5a126fa3510b0 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 = struct statfs64;
+#else
+using statFs = struct 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..7e1e5854364e9 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 = struct statfs64;
+#else
+using statFs = struct 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));
|
a7c4c52
to
0ca1462
Compare
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.
0ca1462
to
b754b21
Compare
Summary: 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. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251215
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.