Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Sources/CSystem/include/CSystemLinux.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift System open source project

Copyright (c) 2020 Apple Inc. and the Swift System project authors
Copyright (c) 2020 - 2026 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
Expand All @@ -20,5 +20,25 @@
#include <sched.h>
#include <unistd.h>
#include "io_uring.h"

// The `ST_*` mount-flag constants in <sys/statvfs.h> require _GNU_SOURCE.
// Rather than define _GNU_SOURCE module-wide, which clashes with SwiftGlibc,
// expose them through these getters, defined in shims.c under _GNU_SOURCE.
#include <stdint.h>
uint64_t _system_get_ST_RDONLY(void);
uint64_t _system_get_ST_NOSUID(void);
uint64_t _system_get_ST_NODEV(void);
uint64_t _system_get_ST_NOEXEC(void);
uint64_t _system_get_ST_SYNCHRONOUS(void);
uint64_t _system_get_ST_MANDLOCK(void);
uint64_t _system_get_ST_NOATIME(void);
uint64_t _system_get_ST_NODIRATIME(void);
uint64_t _system_get_ST_RELATIME(void);
uint64_t _system_get_ST_NOSYMFOLLOW(void);
#if !defined(__ANDROID__)
uint64_t _system_get_ST_WRITE(void);
uint64_t _system_get_ST_APPEND(void);
uint64_t _system_get_ST_IMMUTABLE(void);
#endif
#endif

4 changes: 4 additions & 0 deletions Sources/CSystem/include/CSystemWASI.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <fcntl.h>
#include <limits.h> // For NAME_MAX

// wasi-libc ships <sys/statvfs.h>, but the Swift WASILibc module does not
// surface it. Re-export them through CSystem here.
#include <sys/statvfs.h>

// wasi-libc defines the following constants in a way that Clang Importer can't
// understand, so we need to expose them manually.
static inline int32_t _getConst_O_ACCMODE(void) { return O_ACCMODE; }
Expand Down
32 changes: 32 additions & 0 deletions Sources/CSystem/shims.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,39 @@
#endif

#ifdef __linux__

// The `ST_*` mount-flag constants in <sys/statvfs.h> require _GNU_SOURCE.
// Define it here, in a dedicated translation unit, not in CSystemLinux.h,
// since defining it there changes libc types like `fd_set` for every file
// that imports CSystem and conflicts with SwiftGlibc.
#define _GNU_SOURCE
#include <sys/statvfs.h>
#include <stdint.h>

uint64_t _system_get_ST_RDONLY(void) { return ST_RDONLY; }
uint64_t _system_get_ST_NOSUID(void) { return ST_NOSUID; }
uint64_t _system_get_ST_NODEV(void) { return ST_NODEV; }
uint64_t _system_get_ST_NOEXEC(void) { return ST_NOEXEC; }
uint64_t _system_get_ST_SYNCHRONOUS(void) { return ST_SYNCHRONOUS; }
uint64_t _system_get_ST_MANDLOCK(void) { return ST_MANDLOCK; }
uint64_t _system_get_ST_NOATIME(void) { return ST_NOATIME; }
uint64_t _system_get_ST_NODIRATIME(void) { return ST_NODIRATIME; }
uint64_t _system_get_ST_RELATIME(void) { return ST_RELATIME; }

// ST_NOSYMFOLLOW was added to glibc's <sys/statvfs.h> in Linux 5.10. For
// older versions, fall back to the fixed kernel UAPI bit (<linux/statfs.h>),
// which is the same value a newer glibc header defines.
#ifndef ST_NOSYMFOLLOW
#define ST_NOSYMFOLLOW 0x2000
#endif
uint64_t _system_get_ST_NOSYMFOLLOW(void) { return ST_NOSYMFOLLOW; }

#if !defined(__ANDROID__)
uint64_t _system_get_ST_WRITE(void) { return ST_WRITE; }
uint64_t _system_get_ST_APPEND(void) { return ST_APPEND; }
uint64_t _system_get_ST_IMMUTABLE(void) { return ST_IMMUTABLE; }
#endif

#include <CSystemLinux.h>
#endif

Expand Down
6 changes: 4 additions & 2 deletions Sources/System/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#[[
This source file is part of the Swift System open source project

Copyright (c) 2020 Apple Inc. and the Swift System project authors
Copyright (c) 2020 - 2026 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -42,7 +42,9 @@ target_sources(SystemPackage PRIVATE
FileSystem/FileMode.swift
FileSystem/FileType.swift
FileSystem/Identifiers.swift
FileSystem/Stat.swift)
FileSystem/MountFlags.swift
FileSystem/Stat.swift
FileSystem/StatFS.swift)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
target_sources(SystemPackage PRIVATE
IORing/IOCompletion.swift
Expand Down
522 changes: 522 additions & 0 deletions Sources/System/FileSystem/MountFlags.swift

Large diffs are not rendered by default.

Loading
Loading