Skip to content

Commit a7c4c52

Browse files
[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.
1 parent 1a47f3f commit a7c4c52

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

libc/config/linux/riscv/entrypoints.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@ set(TARGET_LIBC_ENTRYPOINTS
266266
libc.src.sys.stat.mkdirat
267267
libc.src.sys.stat.stat
268268

269+
# sys/statvfs.h
270+
libc.src.sys.statvfs.fstatvfs
271+
libc.src.sys.statvfs.statvfs
272+
269273
# sys/utsname.h entrypoints
270274
libc.src.sys.utsname.uname
271275

libc/config/linux/riscv/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ set(TARGET_PUBLIC_HEADERS
4444
libc.include.sys_select
4545
libc.include.sys_socket
4646
libc.include.sys_stat
47+
libc.include.sys_statvfs
4748
libc.include.sys_syscall
4849
libc.include.sys_time
4950
libc.include.sys_types

libc/test/src/sys/statvfs/linux/fstatvfs_test.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,16 @@
99
#include <linux/magic.h>
1010
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
1111

12+
#ifdef SYS_statfs64
13+
using statFs = struct statfs64;
14+
#else
15+
using statFs = struct statfs;
16+
#endif
17+
1218
namespace LIBC_NAMESPACE_DECL {
13-
static int fstatfs(int fd, struct statfs *buf) {
19+
static int fstatfs(int fd, statFs *buf) {
1420
using namespace statfs_utils;
15-
if (cpp::optional<LinuxStatFs> result = linux_fstatfs(fd)) {
21+
if (cpp::optional<statFs> result = linux_fstatfs(fd)) {
1622
*buf = *result;
1723
return 0;
1824
}
@@ -29,7 +35,7 @@ struct PathFD {
2935
};
3036

3137
TEST(LlvmLibcSysStatvfsTest, FstatfsBasic) {
32-
struct statfs buf;
38+
statFs buf;
3339
ASSERT_THAT(LIBC_NAMESPACE::fstatfs(PathFD("/"), &buf), Succeeds());
3440
ASSERT_THAT(LIBC_NAMESPACE::fstatfs(PathFD("/proc"), &buf), Succeeds());
3541
ASSERT_EQ(buf.f_type, static_cast<decltype(buf.f_type)>(PROC_SUPER_MAGIC));

libc/test/src/sys/statvfs/linux/statvfs_test.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
#include <linux/magic.h>
77
using namespace LIBC_NAMESPACE::testing::ErrnoSetterMatcher;
88

9+
#ifdef SYS_statfs64
10+
using statFs = struct statfs64;
11+
#else
12+
using statFs = struct statfs;
13+
#endif
14+
915
namespace LIBC_NAMESPACE_DECL {
10-
static int statfs(const char *path, struct statfs *buf) {
16+
static int statfs(const char *path, statFs *buf) {
1117
using namespace statfs_utils;
1218
if (cpp::optional<LinuxStatFs> result = linux_statfs(path)) {
1319
*buf = *result;
@@ -18,7 +24,7 @@ static int statfs(const char *path, struct statfs *buf) {
1824
} // namespace LIBC_NAMESPACE_DECL
1925

2026
TEST(LlvmLibcSysStatfsTest, StatfsBasic) {
21-
struct statfs buf;
27+
statFs buf;
2228
ASSERT_THAT(LIBC_NAMESPACE::statfs("/", &buf), Succeeds());
2329
ASSERT_THAT(LIBC_NAMESPACE::statfs("/proc", &buf), Succeeds());
2430
ASSERT_EQ(buf.f_type, static_cast<decltype(buf.f_type)>(PROC_SUPER_MAGIC));

0 commit comments

Comments
 (0)