Skip to content

Commit 8b2e9c7

Browse files
committed
StatFS implementation
1 parent a9597cc commit 8b2e9c7

9 files changed

Lines changed: 2184 additions & 3 deletions

File tree

Sources/CSystem/include/CSystemLinux.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift System open source project
33
4-
Copyright (c) 2020 Apple Inc. and the Swift System project authors
4+
Copyright (c) 2020 - 2026 Apple Inc. and the Swift System project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66
77
See https://swift.org/LICENSE.txt for license information
@@ -20,5 +20,25 @@
2020
#include <sched.h>
2121
#include <unistd.h>
2222
#include "io_uring.h"
23+
24+
// The `ST_*` mount-flag constants in <sys/statvfs.h> require _GNU_SOURCE.
25+
// Rather than define _GNU_SOURCE module-wide, which clashes with SwiftGlibc,
26+
// expose them through these getters, defined in shims.c under _GNU_SOURCE.
27+
#include <stdint.h>
28+
uint64_t _system_get_ST_RDONLY(void);
29+
uint64_t _system_get_ST_NOSUID(void);
30+
uint64_t _system_get_ST_NODEV(void);
31+
uint64_t _system_get_ST_NOEXEC(void);
32+
uint64_t _system_get_ST_SYNCHRONOUS(void);
33+
uint64_t _system_get_ST_MANDLOCK(void);
34+
uint64_t _system_get_ST_NOATIME(void);
35+
uint64_t _system_get_ST_NODIRATIME(void);
36+
uint64_t _system_get_ST_RELATIME(void);
37+
uint64_t _system_get_ST_NOSYMFOLLOW(void);
38+
#if !defined(__ANDROID__)
39+
uint64_t _system_get_ST_WRITE(void);
40+
uint64_t _system_get_ST_APPEND(void);
41+
uint64_t _system_get_ST_IMMUTABLE(void);
42+
#endif
2343
#endif
2444

Sources/CSystem/shims.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,32 @@
1919
#endif
2020

2121
#ifdef __linux__
22+
23+
// The `ST_*` mount-flag constants in <sys/statvfs.h> require _GNU_SOURCE.
24+
// Define it here, in a dedicated translation unit, not in CSystemLinux.h,
25+
// since defining it there changes libc types like `fd_set` for every file
26+
// that imports CSystem and conflicts with SwiftGlibc.
2227
#define _GNU_SOURCE
28+
#include <sys/statvfs.h>
29+
#include <stdint.h>
30+
31+
uint64_t _system_get_ST_RDONLY(void) { return ST_RDONLY; }
32+
uint64_t _system_get_ST_NOSUID(void) { return ST_NOSUID; }
33+
uint64_t _system_get_ST_NODEV(void) { return ST_NODEV; }
34+
uint64_t _system_get_ST_NOEXEC(void) { return ST_NOEXEC; }
35+
uint64_t _system_get_ST_SYNCHRONOUS(void) { return ST_SYNCHRONOUS; }
36+
uint64_t _system_get_ST_MANDLOCK(void) { return ST_MANDLOCK; }
37+
uint64_t _system_get_ST_NOATIME(void) { return ST_NOATIME; }
38+
uint64_t _system_get_ST_NODIRATIME(void) { return ST_NODIRATIME; }
39+
uint64_t _system_get_ST_RELATIME(void) { return ST_RELATIME; }
40+
uint64_t _system_get_ST_NOSYMFOLLOW(void) { return ST_NOSYMFOLLOW; }
41+
42+
#if !defined(__ANDROID__)
43+
uint64_t _system_get_ST_WRITE(void) { return ST_WRITE; }
44+
uint64_t _system_get_ST_APPEND(void) { return ST_APPEND; }
45+
uint64_t _system_get_ST_IMMUTABLE(void) { return ST_IMMUTABLE; }
46+
#endif
47+
2348
#include <CSystemLinux.h>
2449
#endif
2550

Sources/System/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#[[
22
This source file is part of the Swift System open source project
33
4-
Copyright (c) 2020 Apple Inc. and the Swift System project authors
4+
Copyright (c) 2020 - 2026 Apple Inc. and the Swift System project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66
77
See https://swift.org/LICENSE.txt for license information
@@ -42,7 +42,9 @@ target_sources(SystemPackage PRIVATE
4242
FileSystem/FileMode.swift
4343
FileSystem/FileType.swift
4444
FileSystem/Identifiers.swift
45-
FileSystem/Stat.swift)
45+
FileSystem/MountFlags.swift
46+
FileSystem/Stat.swift
47+
FileSystem/StatFS.swift)
4648
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
4749
target_sources(SystemPackage PRIVATE
4850
IORing/IOCompletion.swift

Sources/System/FileSystem/MountFlags.swift

Lines changed: 522 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)