From 16cdb0d00869e158ec4bb976409a4f7081454d26 Mon Sep 17 00:00:00 2001 From: Owen Voorhees Date: Fri, 10 Jul 2026 15:03:50 -0700 Subject: [PATCH 01/10] Set -package-name in CMake build --- Sources/System/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/System/CMakeLists.txt b/Sources/System/CMakeLists.txt index 7816f1a..a904eb1 100644 --- a/Sources/System/CMakeLists.txt +++ b/Sources/System/CMakeLists.txt @@ -24,7 +24,8 @@ add_library(SystemPackage set_target_properties(SystemPackage PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) target_compile_options(SystemPackage PRIVATE - -enable-experimental-feature Lifetimes) + -enable-experimental-feature Lifetimes + "SHELL:-package-name swift-system") target_sources(SystemPackage PRIVATE FilePath/FilePath.swift FilePath/FilePathComponents.swift From 7edc09a749ec13a9e87ed0593fdd6f6374599c2b Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Fri, 10 Jul 2026 16:12:11 -0700 Subject: [PATCH 02/10] Remove an accidental throw annotation --- Sources/System/FileOperations.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/System/FileOperations.swift b/Sources/System/FileOperations.swift index df2a819..d920f93 100644 --- a/Sources/System/FileOperations.swift +++ b/Sources/System/FileOperations.swift @@ -222,7 +222,7 @@ extension FileDescriptor { internal func _read( into buffer: UnsafeMutableRawBufferPointer, retryOnInterrupt: Bool - ) throws -> Result { + ) -> Result { valueOrErrno(retryOnInterrupt: retryOnInterrupt) { system_read(self.rawValue, buffer.baseAddress, buffer.count) } From a6515006f57d3103cc4e0a76c941a42030c4a649 Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Fri, 10 Jul 2026 14:44:39 -0700 Subject: [PATCH 03/10] Adjust availability macro --- Package.swift | 8 ++------ Sources/System/FileSystem/FileFlags.swift | 4 ++-- Sources/System/FileSystem/FileMode.swift | 4 ++-- Sources/System/FileSystem/FileType.swift | 4 ++-- Sources/System/FileSystem/Identifiers.swift | 10 +++++----- Sources/System/FileSystem/Stat.swift | 12 ++++++------ Sources/System/Internals/CInterop.swift | 4 ++-- Sources/System/Internals/Exports.swift | 8 ++++---- Tests/SystemTests/FileModeTests.swift | 6 +++--- Tests/SystemTests/StatTests.swift | 12 ++++++------ 10 files changed, 34 insertions(+), 38 deletions(-) diff --git a/Package.swift b/Package.swift index 7f774e6..2c75bb0 100644 --- a/Package.swift +++ b/Package.swift @@ -59,13 +59,9 @@ let availability: [Available] = [ Available("1.3.2", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.0"), Available("1.4.0", "macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4, visionOS 1.0"), - Available("1.4.1", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"), - Available("1.4.2", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"), - Available("1.5.0", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"), - Available("1.6.0", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"), - Available("1.6.1", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"), + Available("1.7.0", "macOS 27.0, iOS 27.0, watchOS 27.0, tvOS 27.0, visionOS 27.0"), - Available("99", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"), + Available("199", "macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, visionOS 9999"), ] let swiftSettingsAvailability = availability.map(\.swiftSetting) diff --git a/Sources/System/FileSystem/FileFlags.swift b/Sources/System/FileSystem/FileFlags.swift index 5a905ed..15084b1 100644 --- a/Sources/System/FileSystem/FileFlags.swift +++ b/Sources/System/FileSystem/FileFlags.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift System open source project // -// Copyright (c) 2025 Apple Inc. and the Swift System project authors +// Copyright (c) 2025 - 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 @@ -45,7 +45,7 @@ /// /// - Note: Only available on Darwin, FreeBSD, and OpenBSD. @frozen -@available(System 99, *) +@available(System 1.7.0, *) public struct FileFlags: OptionSet, Sendable, Hashable, Codable { /// The raw C flags. diff --git a/Sources/System/FileSystem/FileMode.swift b/Sources/System/FileSystem/FileMode.swift index 91329f1..0bbeb56 100644 --- a/Sources/System/FileSystem/FileMode.swift +++ b/Sources/System/FileSystem/FileMode.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift System open source project // -// Copyright (c) 2025 Apple Inc. and the Swift System project authors +// Copyright (c) 2025 - 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 @@ -14,7 +14,7 @@ /// /// - Note: Only available on Unix-like platforms. @frozen -@available(System 99, *) +@available(System 1.7.0, *) public struct FileMode: RawRepresentable, Sendable, Hashable, Codable { /// The raw C mode. diff --git a/Sources/System/FileSystem/FileType.swift b/Sources/System/FileSystem/FileType.swift index 4213452..9a365a4 100644 --- a/Sources/System/FileSystem/FileType.swift +++ b/Sources/System/FileSystem/FileType.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift System open source project // -// Copyright (c) 2025 Apple Inc. and the Swift System project authors +// Copyright (c) 2025 - 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 @@ -34,7 +34,7 @@ /// /// - Note: Only available on Unix-like platforms. @frozen -@available(System 99, *) +@available(System 1.7.0, *) public struct FileType: RawRepresentable, Sendable, Hashable, Codable { /// The raw file-type bits from the C mode. diff --git a/Sources/System/FileSystem/Identifiers.swift b/Sources/System/FileSystem/Identifiers.swift index b8f9014..dda606e 100644 --- a/Sources/System/FileSystem/Identifiers.swift +++ b/Sources/System/FileSystem/Identifiers.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift System open source project // -// Copyright (c) 2025 Apple Inc. and the Swift System project authors +// Copyright (c) 2025 - 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 @@ -12,7 +12,7 @@ #if !os(Windows) /// A Swift wrapper of the C `uid_t` type. @frozen -@available(System 99, *) +@available(System 1.7.0, *) public struct UserID: RawRepresentable, Sendable, Hashable, Codable { /// The raw C `uid_t`. @@ -30,7 +30,7 @@ public struct UserID: RawRepresentable, Sendable, Hashable, Codable { /// A Swift wrapper of the C `gid_t` type. @frozen -@available(System 99, *) +@available(System 1.7.0, *) public struct GroupID: RawRepresentable, Sendable, Hashable, Codable { /// The raw C `gid_t`. @@ -48,7 +48,7 @@ public struct GroupID: RawRepresentable, Sendable, Hashable, Codable { /// A Swift wrapper of the C `dev_t` type. @frozen -@available(System 99, *) +@available(System 1.7.0, *) public struct DeviceID: RawRepresentable, Sendable, Hashable, Codable { /// The raw C `dev_t`. @@ -66,7 +66,7 @@ public struct DeviceID: RawRepresentable, Sendable, Hashable, Codable { /// A Swift wrapper of the C `ino_t` type. @frozen -@available(System 99, *) +@available(System 1.7.0, *) public struct Inode: RawRepresentable, Sendable, Hashable, Codable { /// The raw C `ino_t`. diff --git a/Sources/System/FileSystem/Stat.swift b/Sources/System/FileSystem/Stat.swift index e30e2b1..fd6fb5c 100644 --- a/Sources/System/FileSystem/Stat.swift +++ b/Sources/System/FileSystem/Stat.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift System open source project // -// Copyright (c) 2025 Apple Inc. and the Swift System project authors +// Copyright (c) 2025 - 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 @@ -35,7 +35,7 @@ import Android /// /// - Note: Only available on Unix-like platforms. @frozen -@available(System 99, *) +@available(System 1.7.0, *) public struct Stat: RawRepresentable, Sendable { /// The raw C `stat` struct. @@ -536,7 +536,7 @@ public struct Stat: RawRepresentable, Sendable { // MARK: - Equatable and Hashable -@available(System 99, *) +@available(System 1.7.0, *) extension Stat: Equatable { @_alwaysEmitIntoClient /// Compares the raw bytes of two `Stat` structs for equality. @@ -549,7 +549,7 @@ extension Stat: Equatable { } } -@available(System 99, *) +@available(System 1.7.0, *) extension Stat: Hashable { @_alwaysEmitIntoClient /// Hashes the raw bytes of this `Stat` struct. @@ -564,7 +564,7 @@ extension Stat: Hashable { // MARK: - FileDescriptor Extensions -@available(System 99, *) +@available(System 1.7.0, *) extension FileDescriptor { /// Creates a `Stat` struct for the file referenced by this `FileDescriptor`. @@ -580,7 +580,7 @@ extension FileDescriptor { // MARK: - FilePath Extensions -@available(System 99, *) +@available(System 1.7.0, *) extension FilePath { /// Creates a `Stat` struct for the file referenced by this `FilePath`. diff --git a/Sources/System/Internals/CInterop.swift b/Sources/System/Internals/CInterop.swift index 3a31660..e6af1b2 100644 --- a/Sources/System/Internals/CInterop.swift +++ b/Sources/System/Internals/CInterop.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift System open source project - Copyright (c) 2020 - 2024 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 @@ -106,7 +106,7 @@ extension CInterop { } } -@available(System 99, *) +@available(System 1.7.0, *) extension CInterop { public typealias DeviceID = dev_t public typealias Inode = ino_t diff --git a/Sources/System/Internals/Exports.swift b/Sources/System/Internals/Exports.swift index 57e5c13..aa3506e 100644 --- a/Sources/System/Internals/Exports.swift +++ b/Sources/System/Internals/Exports.swift @@ -1,7 +1,7 @@ /* This source file is part of the Swift System open source project - Copyright (c) 2020 - 2024 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 @@ -96,15 +96,15 @@ internal func system_strlen(_ s: UnsafeMutablePointer) -> Int { internal func system_stat(_ p: UnsafePointer, _ s: inout CInterop.Stat) -> Int32 { stat(p, &s) } -@available(System 99, *) +@available(System 1.7.0, *) internal func system_lstat(_ p: UnsafePointer, _ s: inout CInterop.Stat) -> Int32 { lstat(p, &s) } -@available(System 99, *) +@available(System 1.7.0, *) internal func system_fstat(_ fd: CInt, _ s: inout CInterop.Stat) -> Int32 { fstat(fd, &s) } -@available(System 99, *) +@available(System 1.7.0, *) internal func system_fstatat(_ fd: CInt, _ p: UnsafePointer, _ s: inout CInterop.Stat, _ flags: CInt) -> Int32 { fstatat(fd, p, &s, flags) } diff --git a/Tests/SystemTests/FileModeTests.swift b/Tests/SystemTests/FileModeTests.swift index 46c3a5d..d24fd09 100644 --- a/Tests/SystemTests/FileModeTests.swift +++ b/Tests/SystemTests/FileModeTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift System open source project // -// Copyright (c) 2025 Apple Inc. and the Swift System project authors +// Copyright (c) 2025 - 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 @@ -36,7 +36,7 @@ import Android @Suite("FileMode") private struct FileModeTests { - @available(System 99, *) + @available(System 1.7.0, *) @Test func basics() async throws { var mode = FileMode(rawValue: S_IFREG | 0o644) // Regular file, rw-r--r-- #expect(mode.type == .regular) @@ -67,7 +67,7 @@ private struct FileModeTests { #expect(mode.type == mode2.type) } - @available(System 99, *) + @available(System 1.7.0, *) @Test func invalidInput() async throws { // No permissions, all other bits set var invalidMode = FileMode(rawValue: ~0o7777) diff --git a/Tests/SystemTests/StatTests.swift b/Tests/SystemTests/StatTests.swift index e80ede1..715b8a7 100644 --- a/Tests/SystemTests/StatTests.swift +++ b/Tests/SystemTests/StatTests.swift @@ -2,7 +2,7 @@ // // This source file is part of the Swift System open source project // -// Copyright (c) 2025 Apple Inc. and the Swift System project authors +// Copyright (c) 2025 - 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 @@ -39,7 +39,7 @@ import Android @Suite("Stat") private struct StatTests { - @available(System 99, *) + @available(System 1.7.0, *) @Test func basics() async throws { try withTemporaryFilePath(basename: "Stat_basics") { tempDir in let dirStatFromFilePath = try tempDir.stat() @@ -81,7 +81,7 @@ private struct StatTests { } } - @available(System 99, *) + @available(System 1.7.0, *) @Test func followSymlinkInits() async throws { try withTemporaryFilePath(basename: "Stat_followSymlinkInits") { tempDir in let targetFilePath = tempDir.appending("target.txt") @@ -190,7 +190,7 @@ private struct StatTests { } } - @available(System 99, *) + @available(System 1.7.0, *) @Test func permissions() async throws { try withTemporaryFilePath(basename: "Stat_permissions") { tempDir in let testFile = tempDir.appending("test.txt") @@ -220,7 +220,7 @@ private struct StatTests { } } - @available(System 99, *) + @available(System 1.7.0, *) @Test func times() async throws { var start = timespec() try #require(clock_gettime(CLOCK_REALTIME, &start) == 0, "\(Errno.current)") @@ -349,7 +349,7 @@ private struct StatTests { } #if SYSTEM_PACKAGE_DARWIN || os(FreeBSD) || os(OpenBSD) - @available(System 99, *) + @available(System 1.7.0, *) @Test func flags() async throws { try withTemporaryFilePath(basename: "Stat_flags") { tempDir in let filePath = tempDir.appending("test.txt") From 7cb32eb7a4320c33df6181924d67507903e11a1e Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Thu, 16 Jul 2026 09:36:53 -0700 Subject: [PATCH 04/10] Cherry-pick: remove unnecessary type casting The compiler now imports these as their canonical type, allowing us to directly use without the explicit type cast. Due to the floor of Swift 6.3, we must preserve the type cast values. Introduce an overlay to explicitly cast the values in the older compilers. Cherry-pick of #308 --- .../System/FilePath/FilePathTempWindows.swift | 4 +- Sources/System/FilePath/FilePathWindows.swift | 2 +- .../Internals/WindowsSyscallAdapters.swift | 96 ++-- Sources/System/WinSDK+Overlay.swift | 439 ++++++++++++++++++ .../FileOperationsTestWindows.swift | 58 +-- 5 files changed, 522 insertions(+), 77 deletions(-) create mode 100644 Sources/System/WinSDK+Overlay.swift diff --git a/Sources/System/FilePath/FilePathTempWindows.swift b/Sources/System/FilePath/FilePathTempWindows.swift index 259aaaf..0321d52 100644 --- a/Sources/System/FilePath/FilePathTempWindows.swift +++ b/Sources/System/FilePath/FilePathTempWindows.swift @@ -73,7 +73,7 @@ internal func _recursiveRemove( ) throws { // First, deal with subdirectories try forEachFile(at: path) { findData in - if (findData.dwFileAttributes & DWORD(FILE_ATTRIBUTE_DIRECTORY)) != 0 { + if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0 { let name = withUnsafeBytes(of: findData.cFileName) { return SystemString(platformString: $0.assumingMemoryBound( to: CInterop.PlatformChar.self).baseAddress!) @@ -94,7 +94,7 @@ internal func _recursiveRemove( let component = FilePath.Component(name)! let subpath = path.appending(component) - if (findData.dwFileAttributes & DWORD(FILE_ATTRIBUTE_DIRECTORY)) == 0 { + if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0 { try subpath.withPlatformString { subpath in if try !subpath.withCanonicalPathRepresentation({ DeleteFileW($0) }) { throw Errno(windowsError: GetLastError()) diff --git a/Sources/System/FilePath/FilePathWindows.swift b/Sources/System/FilePath/FilePathWindows.swift index 2226816..0828978 100644 --- a/Sources/System/FilePath/FilePathWindows.swift +++ b/Sources/System/FilePath/FilePathWindows.swift @@ -529,7 +529,7 @@ fileprivate func SUCCEEDED(_ hr: HRESULT) -> Bool { // an HRESULT to a Win32 error code. @inline(__always) fileprivate func WIN32_FROM_HRESULT(_ hr: HRESULT) -> DWORD { - if SUCCEEDED(hr) { return DWORD(ERROR_SUCCESS) } + if SUCCEEDED(hr) { return ERROR_SUCCESS } if HRESULT_FACILITY(hr) == FACILITY_WIN32 { return HRESULT_CODE(hr) } diff --git a/Sources/System/Internals/WindowsSyscallAdapters.swift b/Sources/System/Internals/WindowsSyscallAdapters.swift index 6437d16..21cdaad 100644 --- a/Sources/System/Internals/WindowsSyscallAdapters.swift +++ b/Sources/System/Internals/WindowsSyscallAdapters.swift @@ -38,9 +38,9 @@ internal func open( guard let hFile = try? path.withCanonicalPathRepresentation({ path in CreateFileW(path, decodedFlags.dwDesiredAccess, - DWORD(FILE_SHARE_DELETE - | FILE_SHARE_READ - | FILE_SHARE_WRITE), + FILE_SHARE_DELETE + | FILE_SHARE_READ + | FILE_SHARE_WRITE, &saAttrs, decodedFlags.dwCreationDisposition, decodedFlags.dwFlagsAndAttributes, @@ -80,9 +80,9 @@ internal func open( guard let hFile = try? path.withCanonicalPathRepresentation({ path in CreateFileW(path, decodedFlags.dwDesiredAccess, - DWORD(FILE_SHARE_DELETE - | FILE_SHARE_READ - | FILE_SHARE_WRITE), + FILE_SHARE_DELETE + | FILE_SHARE_READ + | FILE_SHARE_WRITE, &saAttrs, decodedFlags.dwCreationDisposition, decodedFlags.dwFlagsAndAttributes, @@ -202,16 +202,16 @@ internal func ftruncate(_ fd: Int32, _ length: off_t) -> Int32 { // Save the current position and restore it when we're done if !SetFilePointerEx(hFile, liCurrentOffset, &liCurrentOffset, - DWORD(FILE_CURRENT)) { + FILE_CURRENT) { ucrt._set_errno(_mapWindowsErrorToErrno(GetLastError())) return -1 } defer { - _ = SetFilePointerEx(hFile, liCurrentOffset, nil, DWORD(FILE_BEGIN)); + _ = SetFilePointerEx(hFile, liCurrentOffset, nil, FILE_BEGIN); } // Truncate (or extend) the file - if !SetFilePointerEx(hFile, liDesiredLength, nil, DWORD(FILE_BEGIN)) + if !SetFilePointerEx(hFile, liDesiredLength, nil, FILE_BEGIN) || !SetEndOfFile(hFile) { ucrt._set_errno(_mapWindowsErrorToErrno(GetLastError())) return -1 @@ -263,7 +263,7 @@ internal func rmdir( } internal func _mapWindowsErrorToErrno(_ errorCode: DWORD) -> CInt { - switch Int32(errorCode) { + switch errorCode { case ERROR_SUCCESS: return 0 case ERROR_INVALID_FUNCTION, @@ -342,28 +342,28 @@ fileprivate func rightsFromModeBits( var rights: DWORD = 0 if (bits & 0o4) != 0 { - rights |= DWORD(FILE_READ_ATTRIBUTES - | FILE_READ_DATA - | FILE_READ_EA - | STANDARD_RIGHTS_READ - | SYNCHRONIZE) + rights |= (FILE_READ_ATTRIBUTES + | FILE_READ_DATA + | FILE_READ_EA + | STANDARD_RIGHTS_READ + | SYNCHRONIZE) } if (bits & 0o2) != 0 { - rights |= DWORD(FILE_APPEND_DATA - | FILE_WRITE_ATTRIBUTES - | FILE_WRITE_DATA - | FILE_WRITE_EA - | STANDARD_RIGHTS_WRITE - | SYNCHRONIZE) + rights |= (FILE_APPEND_DATA + | FILE_WRITE_ATTRIBUTES + | FILE_WRITE_DATA + | FILE_WRITE_EA + | STANDARD_RIGHTS_WRITE + | SYNCHRONIZE) if fileOrDirectory == .directory && !sticky { - rights |= DWORD(FILE_DELETE_CHILD) + rights |= FILE_DELETE_CHILD } } if (bits & 0o1) != 0 { - rights |= DWORD(FILE_EXECUTE - | FILE_READ_ATTRIBUTES - | STANDARD_RIGHTS_EXECUTE - | SYNCHRONIZE) + rights |= (FILE_EXECUTE + | FILE_READ_ATTRIBUTES + | STANDARD_RIGHTS_EXECUTE + | SYNCHRONIZE) } return rights @@ -431,7 +431,7 @@ internal func _createSecurityDescriptor(from mode: CInterop.Mode, var everyone: PSID? = nil guard AllocateAndInitializeSid(&SIDAuthWorld, 1, - DWORD(SECURITY_WORLD_RID), + SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &everyone) else { return nil @@ -472,7 +472,7 @@ internal func _createSecurityDescriptor(from mode: CInterop.Mode, EXPLICIT_ACCESS_W( grfAccessPermissions: ownerRights, grfAccessMode: GRANT_ACCESS, - grfInheritance: DWORD(NO_INHERITANCE), + grfInheritance: NO_INHERITANCE, Trustee: TRUSTEE_W( pMultipleTrustee: nil, MultipleTrusteeOperation: NO_MULTIPLE_TRUSTEE, @@ -485,7 +485,7 @@ internal func _createSecurityDescriptor(from mode: CInterop.Mode, EXPLICIT_ACCESS_W( grfAccessPermissions: groupRights, grfAccessMode: GRANT_ACCESS, - grfInheritance: DWORD(NO_INHERITANCE), + grfInheritance: NO_INHERITANCE, Trustee: TRUSTEE_W( pMultipleTrustee: nil, MultipleTrusteeOperation: NO_MULTIPLE_TRUSTEE, @@ -498,7 +498,7 @@ internal func _createSecurityDescriptor(from mode: CInterop.Mode, EXPLICIT_ACCESS_W( grfAccessPermissions: otherRights, grfAccessMode: GRANT_ACCESS, - grfInheritance: DWORD(NO_INHERITANCE), + grfInheritance: NO_INHERITANCE, Trustee: TRUSTEE_W( pMultipleTrustee: nil, MultipleTrusteeOperation: NO_MULTIPLE_TRUSTEE, @@ -515,7 +515,7 @@ internal func _createSecurityDescriptor(from mode: CInterop.Mode, EXPLICIT_ACCESS_W( grfAccessPermissions: ownerDenyRights, grfAccessMode: DENY_ACCESS, - grfInheritance: DWORD(NO_INHERITANCE), + grfInheritance: NO_INHERITANCE, Trustee: TRUSTEE_W( pMultipleTrustee: nil, MultipleTrusteeOperation: NO_MULTIPLE_TRUSTEE, @@ -533,7 +533,7 @@ internal func _createSecurityDescriptor(from mode: CInterop.Mode, EXPLICIT_ACCESS_W( grfAccessPermissions: groupDenyRights, grfAccessMode: DENY_ACCESS, - grfInheritance: DWORD(NO_INHERITANCE), + grfInheritance: NO_INHERITANCE, Trustee: TRUSTEE_W( pMultipleTrustee: nil, MultipleTrusteeOperation: NO_MULTIPLE_TRUSTEE, @@ -562,13 +562,13 @@ internal func _createSecurityDescriptor(from mode: CInterop.Mode, var descriptor = SECURITY_DESCRIPTOR() guard InitializeSecurityDescriptor(&descriptor, - DWORD(SECURITY_DESCRIPTOR_REVISION)) else { + SECURITY_DESCRIPTOR_REVISION) else { return nil } guard SetSecurityDescriptorControl(&descriptor, - SECURITY_DESCRIPTOR_CONTROL(SE_DACL_PROTECTED), - SECURITY_DESCRIPTOR_CONTROL(SE_DACL_PROTECTED)) + SE_DACL_PROTECTED, + SE_DACL_PROTECTED) && SetSecurityDescriptorOwner(&descriptor, user, false) && SetSecurityDescriptorGroup(&descriptor, group, false) && SetSecurityDescriptorDacl(&descriptor, @@ -608,15 +608,15 @@ fileprivate struct DecodedOpenFlags { init(_ oflag: Int32) { switch oflag & (_O_CREAT | _O_EXCL | _O_TRUNC) { case _O_CREAT | _O_EXCL, _O_CREAT | _O_EXCL | _O_TRUNC: - dwCreationDisposition = DWORD(CREATE_NEW) + dwCreationDisposition = CREATE_NEW case _O_CREAT: - dwCreationDisposition = DWORD(OPEN_ALWAYS) + dwCreationDisposition = OPEN_ALWAYS case _O_CREAT | _O_TRUNC: - dwCreationDisposition = DWORD(CREATE_ALWAYS) + dwCreationDisposition = CREATE_ALWAYS case _O_TRUNC: - dwCreationDisposition = DWORD(TRUNCATE_EXISTING) + dwCreationDisposition = TRUNCATE_EXISTING default: - dwCreationDisposition = DWORD(OPEN_EXISTING) + dwCreationDisposition = OPEN_EXISTING } // The _O_RDONLY, _O_WRONLY and _O_RDWR flags are non-overlapping @@ -625,11 +625,11 @@ fileprivate struct DecodedOpenFlags { dwDesiredAccess = 0 switch (oflag & (_O_RDONLY|_O_WRONLY|_O_RDWR)) { case _O_RDONLY: - dwDesiredAccess |= DWORD(GENERIC_READ) + dwDesiredAccess |= GENERIC_READ case _O_WRONLY: - dwDesiredAccess |= DWORD(GENERIC_WRITE) + dwDesiredAccess |= GENERIC_WRITE case _O_RDWR: - dwDesiredAccess |= DWORD(GENERIC_READ) | DWORD(GENERIC_WRITE) + dwDesiredAccess |= GENERIC_READ | GENERIC_WRITE default: break } @@ -638,19 +638,19 @@ fileprivate struct DecodedOpenFlags { dwFlagsAndAttributes = 0 if (oflag & _O_SEQUENTIAL) != 0 { - dwFlagsAndAttributes |= DWORD(FILE_FLAG_SEQUENTIAL_SCAN) + dwFlagsAndAttributes |= FILE_FLAG_SEQUENTIAL_SCAN } if (oflag & _O_RANDOM) != 0 { - dwFlagsAndAttributes |= DWORD(FILE_FLAG_RANDOM_ACCESS) + dwFlagsAndAttributes |= FILE_FLAG_RANDOM_ACCESS } if (oflag & _O_TEMPORARY) != 0 { - dwFlagsAndAttributes |= DWORD(FILE_FLAG_DELETE_ON_CLOSE) + dwFlagsAndAttributes |= FILE_FLAG_DELETE_ON_CLOSE } if (oflag & _O_SHORT_LIVED) != 0 { - dwFlagsAndAttributes |= DWORD(FILE_ATTRIBUTE_TEMPORARY) + dwFlagsAndAttributes |= FILE_ATTRIBUTE_TEMPORARY } else { - dwFlagsAndAttributes |= DWORD(FILE_ATTRIBUTE_NORMAL) + dwFlagsAndAttributes |= FILE_ATTRIBUTE_NORMAL } } } diff --git a/Sources/System/WinSDK+Overlay.swift b/Sources/System/WinSDK+Overlay.swift new file mode 100644 index 0000000..41a292c --- /dev/null +++ b/Sources/System/WinSDK+Overlay.swift @@ -0,0 +1,439 @@ +/* + This source file is part of the Swift System open source project + + Copyright (c) 2024 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 +*/ + +#if os(Windows) + +import WinSDK + +@_transparent +internal var CREATE_ALWAYS: DWORD { + DWORD(WinSDK.CREATE_ALWAYS) +} + +@_transparent +internal var CREATE_NEW: DWORD { + DWORD(WinSDK.CREATE_NEW) +} + +@_transparent +internal var ERROR_ACCESS_DENIED: DWORD { + DWORD(WinSDK.ERROR_ACCESS_DENIED) +} + +@_transparent +internal var ERROR_ALREADY_EXISTS: DWORD { + DWORD(WinSDK.ERROR_ALREADY_EXISTS) +} + +@_transparent +internal var ERROR_ARENA_TRASHED: DWORD { + DWORD(WinSDK.ERROR_ARENA_TRASHED) +} + +@_transparent +internal var ERROR_BAD_ENVIRONMENT: DWORD { + DWORD(WinSDK.ERROR_BAD_ENVIRONMENT) +} + +@_transparent +internal var ERROR_BAD_FORMAT: DWORD { + DWORD(WinSDK.ERROR_BAD_FORMAT) +} + +@_transparent +internal var ERROR_BAD_NET_NAME: DWORD { + DWORD(WinSDK.ERROR_BAD_NET_NAME) +} + +@_transparent +internal var ERROR_BAD_NETPATH: DWORD { + DWORD(WinSDK.ERROR_BAD_NETPATH) +} + +@_transparent +internal var ERROR_BAD_PATHNAME: DWORD { + DWORD(WinSDK.ERROR_BAD_PATHNAME) +} + +@_transparent +internal var ERROR_BROKEN_PIPE: DWORD { + DWORD(WinSDK.ERROR_BROKEN_PIPE) +} + +@_transparent +internal var ERROR_CANNOT_MAKE: DWORD { + DWORD(WinSDK.ERROR_CANNOT_MAKE) +} + +@_transparent +internal var ERROR_CHILD_NOT_COMPLETE: DWORD { + DWORD(WinSDK.ERROR_CHILD_NOT_COMPLETE) +} + +@_transparent +internal var ERROR_CURRENT_DIRECTORY: DWORD { + DWORD(WinSDK.ERROR_CURRENT_DIRECTORY) +} + +@_transparent +internal var ERROR_DIR_NOT_EMPTY: DWORD { + DWORD(WinSDK.ERROR_DIR_NOT_EMPTY) +} + +@_transparent +internal var ERROR_DISK_FULL: DWORD { + DWORD(WinSDK.ERROR_DISK_FULL) +} + +@_transparent +internal var ERROR_DRIVE_LOCKED: DWORD { + DWORD(WinSDK.ERROR_DRIVE_LOCKED) +} + +@_transparent +internal var ERROR_DIRECT_ACCESS_HANDLE: DWORD { + DWORD(WinSDK.ERROR_DIRECT_ACCESS_HANDLE) +} + +@_transparent +internal var ERROR_FILE_EXISTS: DWORD { + DWORD(WinSDK.ERROR_FILE_EXISTS) +} + +@_transparent +internal var ERROR_FILE_NOT_FOUND: DWORD { + DWORD(WinSDK.ERROR_FILE_NOT_FOUND) +} + +@_transparent +internal var ERROR_FAIL_I24: DWORD { + DWORD(WinSDK.ERROR_FAIL_I24) +} + +@_transparent +internal var ERROR_FILENAME_EXCED_RANGE: DWORD { + DWORD(WinSDK.ERROR_FILENAME_EXCED_RANGE) +} + +@_transparent +internal var ERROR_NEGATIVE_SEEK: DWORD { + DWORD(WinSDK.ERROR_NEGATIVE_SEEK) +} + +@_transparent +internal var ERROR_NO_MORE_FILES: DWORD { + DWORD(WinSDK.ERROR_NO_MORE_FILES) +} + +@_transparent +internal var ERROR_NO_UNICODE_TRANSLATION: DWORD { + DWORD(WinSDK.ERROR_NO_UNICODE_TRANSLATION) +} + +@_transparent +internal var ERROR_NOT_ENOUGH_MEMORY: DWORD { + DWORD(WinSDK.ERROR_NOT_ENOUGH_MEMORY) +} + +@_transparent +internal var ERROR_INVALID_ACCESS: DWORD { + DWORD(WinSDK.ERROR_INVALID_ACCESS) +} + +@_transparent +internal var ERROR_INVALID_BLOCK: DWORD { + DWORD(WinSDK.ERROR_INVALID_BLOCK) +} + +@_transparent +internal var ERROR_INVALID_DATA: DWORD { + DWORD(WinSDK.ERROR_INVALID_DATA) +} + +@_transparent +internal var ERROR_INVALID_DRIVE: DWORD { + DWORD(WinSDK.ERROR_INVALID_DRIVE) +} + +@_transparent +internal var ERROR_INVALID_FUNCTION: DWORD { + DWORD(WinSDK.ERROR_INVALID_FUNCTION) +} + +@_transparent +internal var ERROR_INVALID_HANDLE: DWORD { + DWORD(WinSDK.ERROR_INVALID_HANDLE) +} + +@_transparent +internal var ERROR_INFLOOP_IN_RELOC_CHAIN: DWORD { + DWORD(WinSDK.ERROR_INFLOOP_IN_RELOC_CHAIN) +} + +@_transparent +internal var ERROR_INVALID_PARAMETER: DWORD { + DWORD(WinSDK.ERROR_INVALID_PARAMETER) +} + +@_transparent +internal var ERROR_INVALID_STARTING_CODESEG: DWORD { + DWORD(WinSDK.ERROR_INVALID_STARTING_CODESEG) +} + +@_transparent +internal var ERROR_INVALID_TARGET_HANDLE: DWORD { + DWORD(WinSDK.ERROR_INVALID_TARGET_HANDLE) +} + +@_transparent +internal var ERROR_LOCK_FAILED: DWORD { + DWORD(WinSDK.ERROR_LOCK_FAILED) +} + +@_transparent +internal var ERROR_LOCK_VIOLATION: DWORD { + DWORD(WinSDK.ERROR_LOCK_VIOLATION) +} + +@_transparent +internal var ERROR_MAX_THRDS_REACHED: DWORD { + DWORD(WinSDK.ERROR_MAX_THRDS_REACHED) +} + +@_transparent +internal var ERROR_NESTING_NOT_ALLOWED: DWORD { + DWORD(WinSDK.ERROR_NESTING_NOT_ALLOWED) +} + +@_transparent +internal var ERROR_NETWORK_ACCESS_DENIED: DWORD { + DWORD(WinSDK.ERROR_NETWORK_ACCESS_DENIED) +} + +@_transparent +internal var ERROR_NO_PROC_SLOTS: DWORD { + DWORD(WinSDK.ERROR_NO_PROC_SLOTS) +} + +@_transparent +internal var ERROR_NOT_ENOUGH_QUOTA: DWORD { + DWORD(WinSDK.ERROR_NOT_ENOUGH_QUOTA) +} + +@_transparent +internal var ERROR_NOT_LOCKED: DWORD { + DWORD(WinSDK.ERROR_NOT_LOCKED) +} + +@_transparent +internal var ERROR_NOT_SAME_DEVICE: DWORD { + DWORD(WinSDK.ERROR_NOT_SAME_DEVICE) +} + +@_transparent +internal var ERROR_PATH_NOT_FOUND: DWORD { + DWORD(WinSDK.ERROR_PATH_NOT_FOUND) +} + +@_transparent +internal var ERROR_SEEK_ON_DEVICE: DWORD { + DWORD(WinSDK.ERROR_SEEK_ON_DEVICE) +} + +@_transparent +internal var ERROR_SHARING_BUFFER_EXCEEDED: DWORD { + DWORD(WinSDK.ERROR_SHARING_BUFFER_EXCEEDED) +} + +@_transparent +internal var ERROR_SUCCESS: DWORD { + DWORD(WinSDK.ERROR_SUCCESS) +} + +@_transparent +internal var ERROR_WAIT_NO_CHILDREN: DWORD { + DWORD(WinSDK.ERROR_WAIT_NO_CHILDREN) +} + +@_transparent +internal var ERROR_WRITE_PROTECT: DWORD { + DWORD(WinSDK.ERROR_WRITE_PROTECT) +} + +@_transparent +internal var ERROR_TOO_MANY_OPEN_FILES: DWORD { + DWORD(WinSDK.ERROR_TOO_MANY_OPEN_FILES) +} + +@_transparent +internal var FILE_APPEND_DATA: DWORD { + DWORD(WinSDK.FILE_APPEND_DATA) +} + +@_transparent +internal var FILE_ATTRIBUTE_DIRECTORY: DWORD { + DWORD(WinSDK.FILE_ATTRIBUTE_DIRECTORY) +} + +@_transparent +internal var FILE_ATTRIBUTE_NORMAL: DWORD { + DWORD(WinSDK.FILE_ATTRIBUTE_NORMAL) +} + +@_transparent +internal var FILE_ATTRIBUTE_TEMPORARY: DWORD { + DWORD(WinSDK.FILE_ATTRIBUTE_TEMPORARY) +} + +@_transparent +internal var FILE_BEGIN: DWORD { + DWORD(WinSDK.FILE_BEGIN) +} + +@_transparent +internal var FILE_CURRENT: DWORD { + DWORD(WinSDK.FILE_CURRENT) +} + +@_transparent +internal var FILE_DELETE_CHILD: DWORD { + DWORD(WinSDK.FILE_DELETE_CHILD) +} + +@_transparent +package var FILE_EXECUTE: DWORD { + DWORD(WinSDK.FILE_EXECUTE) +} + +@_transparent +internal var FILE_FLAG_DELETE_ON_CLOSE: DWORD { + DWORD(WinSDK.FILE_FLAG_DELETE_ON_CLOSE) +} + +@_transparent +internal var FILE_FLAG_RANDOM_ACCESS: DWORD { + DWORD(WinSDK.FILE_FLAG_RANDOM_ACCESS) +} + +@_transparent +internal var FILE_FLAG_SEQUENTIAL_SCAN: DWORD { + DWORD(WinSDK.FILE_FLAG_SEQUENTIAL_SCAN) +} + +@_transparent +package var FILE_READ_ATTRIBUTES: DWORD { + DWORD(WinSDK.FILE_READ_ATTRIBUTES) +} + +@_transparent +internal var FILE_READ_DATA: DWORD { + DWORD(WinSDK.FILE_READ_DATA) +} + +@_transparent +internal var FILE_READ_EA: DWORD { + DWORD(WinSDK.FILE_READ_EA) +} + +@_transparent +internal var FILE_SHARE_DELETE: DWORD { + DWORD(WinSDK.FILE_SHARE_DELETE) +} + +@_transparent +internal var FILE_SHARE_READ: DWORD { + DWORD(WinSDK.FILE_SHARE_READ) +} + +@_transparent +internal var FILE_SHARE_WRITE: DWORD { + DWORD(WinSDK.FILE_SHARE_WRITE) +} + +@_transparent +package var FILE_WRITE_ATTRIBUTES: DWORD { + DWORD(WinSDK.FILE_WRITE_ATTRIBUTES) +} + +@_transparent +internal var FILE_WRITE_DATA: DWORD { + DWORD(WinSDK.FILE_WRITE_DATA) +} + +@_transparent +internal var FILE_WRITE_EA: DWORD { + DWORD(WinSDK.FILE_WRITE_EA) +} + +@_transparent +internal var GENERIC_READ: DWORD { + DWORD(WinSDK.GENERIC_READ) +} + +@_transparent +internal var GENERIC_WRITE: DWORD { + DWORD(WinSDK.GENERIC_WRITE) +} + +@_transparent +internal var NO_INHERITANCE: DWORD { + DWORD(WinSDK.NO_INHERITANCE) +} + +@_transparent +internal var OPEN_ALWAYS: DWORD { + DWORD(WinSDK.OPEN_ALWAYS) +} + +@_transparent +internal var OPEN_EXISTING: DWORD { + DWORD(WinSDK.OPEN_EXISTING) +} + +@_transparent +internal var SE_DACL_PROTECTED: SECURITY_DESCRIPTOR_CONTROL { + SECURITY_DESCRIPTOR_CONTROL(WinSDK.SE_DACL_PROTECTED) +} + +@_transparent +internal var SECURITY_DESCRIPTOR_REVISION: DWORD { + DWORD(WinSDK.SECURITY_DESCRIPTOR_REVISION) +} + +@_transparent +internal var SECURITY_WORLD_RID: DWORD { + DWORD(WinSDK.SECURITY_WORLD_RID) +} + +@_transparent +internal var STANDARD_RIGHTS_READ: DWORD { + DWORD(WinSDK.STANDARD_RIGHTS_READ) +} + +@_transparent +internal var STANDARD_RIGHTS_EXECUTE: DWORD { + DWORD(WinSDK.STANDARD_RIGHTS_EXECUTE) +} + +@_transparent +internal var STANDARD_RIGHTS_WRITE: DWORD { + DWORD(WinSDK.STANDARD_RIGHTS_WRITE) +} + +@_transparent +internal var SYNCHRONIZE: DWORD { + DWORD(WinSDK.SYNCHRONIZE) +} + +@_transparent +internal var TRUNCATE_EXISTING: DWORD { + DWORD(WinSDK.TRUNCATE_EXISTING) +} + +#endif diff --git a/Tests/SystemTests/FileOperationsTestWindows.swift b/Tests/SystemTests/FileOperationsTestWindows.swift index 7b87b35..c5ed9f6 100644 --- a/Tests/SystemTests/FileOperationsTestWindows.swift +++ b/Tests/SystemTests/FileOperationsTestWindows.swift @@ -19,6 +19,10 @@ import XCTest import WinSDK +private let FILE_APPEND_DATA = DWORD(WinSDK.FILE_APPEND_DATA) +private let FILE_EXECUTE = DWORD(WinSDK.FILE_EXECUTE) +private let FILE_READ_ATTRIBUTES = DWORD(WinSDK.FILE_READ_ATTRIBUTES) + @available(iOS 8, *) final class FileOperationsTestWindows: XCTestCase { private let r = ACCESS_MASK( @@ -43,6 +47,8 @@ final class FileOperationsTestWindows: XCTestCase { | SYNCHRONIZE ) + private let none = ACCESS_MASK(0) + private struct Test { var permissions: CModeT var ownerAccess: ACCESS_MASK @@ -72,7 +78,7 @@ final class FileOperationsTestWindows: XCTestCase { var psidEveryone: PSID? = nil XCTAssert(AllocateAndInitializeSid(&SIDAuthWorld, 1, - DWORD(SECURITY_WORLD_RID), + SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &psidEveryone)) defer { @@ -106,7 +112,7 @@ final class FileOperationsTestWindows: XCTestCase { &psidGroup, &pDacl, nil, - &pSD), DWORD(ERROR_SUCCESS)) + &pSD), ERROR_SUCCESS) defer { LocalFree(pSD) } @@ -135,15 +141,15 @@ final class FileOperationsTestWindows: XCTestCase { XCTAssertEqual(GetEffectiveRightsFromAclW( pDacl, &owner, - &ownerAccess), DWORD(ERROR_SUCCESS)) + &ownerAccess), ERROR_SUCCESS) XCTAssertEqual(GetEffectiveRightsFromAclW( pDacl, &group, - &groupAccess), DWORD(ERROR_SUCCESS)) + &groupAccess), ERROR_SUCCESS) XCTAssertEqual(GetEffectiveRightsFromAclW( pDacl, &everyone, - &otherAccess), DWORD(ERROR_SUCCESS)) + &otherAccess), ERROR_SUCCESS) return (ownerAccess, groupAccess, otherAccess) } @@ -182,9 +188,9 @@ final class FileOperationsTestWindows: XCTestCase { try withTemporaryFilePath(basename: "testUmask") { path in let tests = [ - Test(0o000, 0, 0, 0), - Test(0o700, r|w|x, 0, 0), - Test(0o770, r|w|x, r|x, 0), + Test(0o000, none, none, none), + Test(0o700, r|w|x, none, none), + Test(0o770, r|w|x, r|x, none), Test(0o777, r|w|x, r|x, r|x) ] @@ -195,9 +201,9 @@ final class FileOperationsTestWindows: XCTestCase { .otherWrite, .otherExecute]) { try withTemporaryFilePath(basename: "testUmask") { path in let tests = [ - Test(0o000, 0, 0, 0), - Test(0o700, r|w|x, 0, 0), - Test(0o770, r|w|x, r, 0), + Test(0o000, none, none, none), + Test(0o700, r|w|x, none, none), + Test(0o770, r|w|x, r, none), Test(0o777, r|w|x, r, r) ] @@ -214,28 +220,28 @@ final class FileOperationsTestWindows: XCTestCase { try FilePermissions.withCreationMask([]) { try withTemporaryFilePath(basename: "testPermissions") { path in let tests = [ - Test(0o000, 0, 0, 0), + Test(0o000, none, none, none), - Test(0o400, r, 0, 0), - Test(0o200, w, 0, 0), - Test(0o100, x, 0, 0), - Test(0o040, 0, r, 0), - Test(0o020, 0, w, 0), - Test(0o010, 0, x, 0), - Test(0o004, 0, 0, r), - Test(0o002, 0, 0, w), - Test(0o001, 0, 0, x), + Test(0o400, r, none, none), + Test(0o200, w, none, none), + Test(0o100, x, none, none), + Test(0o040, none, r, none), + Test(0o020, none, w, none), + Test(0o010, none, x, none), + Test(0o004, none, none, r), + Test(0o002, none, none, w), + Test(0o001, none, none, x), - Test(0o700, r|w|x, 0, 0), - Test(0o770, r|w|x, r|w|x, 0), + Test(0o700, r|w|x, none, none), + Test(0o770, r|w|x, r|w|x, none), Test(0o777, r|w|x, r|w|x, r|w|x), Test(0o755, r|w|x, r|x, r|x), Test(0o644, r|w, r, r), - Test(0o007, 0, 0, r|w|x), - Test(0o070, 0, r|w|x, 0), - Test(0o077, 0, r|w|x, r|w|x), + Test(0o007, none, none, r|w|x), + Test(0o070, none, r|w|x, none), + Test(0o077, none, r|w|x, r|w|x), ] try runTests(tests, at: path) From b349ff8c050de13f392464edd8a345495531f1ba Mon Sep 17 00:00:00 2001 From: Guillaume Lessard Date: Thu, 16 Jul 2026 11:23:01 -0700 Subject: [PATCH 05/10] Update pull request workflow --- .github/workflows/pull_request.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 8fa4b21..bfc1807 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -23,6 +23,8 @@ jobs: {"os_version": "focal", "swift_version": "6.2"}, {"os_version": "focal", "swift_version": "nightly-6.3"}, {"os_version": "focal", "swift_version": "6.3"}, + {"os_version": "focal", "swift_version": "nightly-6.4.x"}, + {"os_version": "focal", "swift_version": "6.4.x"}, {"os_version": "focal", "swift_version": "nightly-main"}, ] enable_macos_checks: true @@ -40,6 +42,8 @@ jobs: {"os_version": "focal", "swift_version": "6.2"}, {"os_version": "focal", "swift_version": "nightly-6.3"}, {"os_version": "focal", "swift_version": "6.3"}, + {"os_version": "focal", "swift_version": "nightly-6.4.x"}, + {"os_version": "focal", "swift_version": "6.4.x"}, {"os_version": "focal", "swift_version": "nightly-main"}, ] enable_wasm_sdk_build: true @@ -49,6 +53,8 @@ jobs: {"os_version": "focal", "swift_version": "6.2"}, {"os_version": "focal", "swift_version": "nightly-6.3"}, {"os_version": "focal", "swift_version": "6.3"}, + {"os_version": "focal", "swift_version": "nightly-6.4.x"}, + {"os_version": "focal", "swift_version": "6.4.x"}, {"os_version": "focal", "swift_version": "nightly-main"}, ] enable_android_sdk_build: true From 2b266acf85ceb7e1c3bd9ea6fb3b38577c8bdc30 Mon Sep 17 00:00:00 2001 From: Jonathan Flat Date: Fri, 17 Jul 2026 15:15:09 -0600 Subject: [PATCH 06/10] Don't compare padding/reserved fields for Stat equality --- Proposals/0006-system-stat.md | 6 ++-- Sources/System/FileSystem/Stat.swift | 50 +++++++++++++++++++++++----- Tests/SystemTests/StatTests.swift | 32 ++++++++++++++++++ 3 files changed, 77 insertions(+), 11 deletions(-) diff --git a/Proposals/0006-system-stat.md b/Proposals/0006-system-stat.md index 6214b76..8a09f5d 100644 --- a/Proposals/0006-system-stat.md +++ b/Proposals/0006-system-stat.md @@ -705,12 +705,14 @@ public struct Stat: RawRepresentable, Sendable { // MARK: - Equatable and Hashable extension Stat: Equatable { - /// Compares the raw bytes of two `Stat` structs for equality. + /// Compares the meaningful file-metadata fields of two `Stat` values. + /// + /// Alignment padding and platform reserved/"spare" fields are not compared. public static func == (lhs: Self, rhs: Self) -> Bool } extension Stat: Hashable { - /// Hashes the raw bytes of this `Stat` struct. + /// Hashes a subset of the fields compared by `==` that identify a file. public func hash(into hasher: inout Hasher) } ``` diff --git a/Sources/System/FileSystem/Stat.swift b/Sources/System/FileSystem/Stat.swift index fd6fb5c..1fd777c 100644 --- a/Sources/System/FileSystem/Stat.swift +++ b/Sources/System/FileSystem/Stat.swift @@ -538,25 +538,57 @@ public struct Stat: RawRepresentable, Sendable { @available(System 1.7.0, *) extension Stat: Equatable { + /// Compares the meaningful file-metadata fields of two `Stat` values. + /// + /// Alignment padding and platform reserved/"spare" fields are not compared. @_alwaysEmitIntoClient - /// Compares the raw bytes of two `Stat` structs for equality. public static func == (lhs: Self, rhs: Self) -> Bool { - return withUnsafeBytes(of: lhs.rawValue) { lhsBytes in - withUnsafeBytes(of: rhs.rawValue) { rhsBytes in - lhsBytes.elementsEqual(rhsBytes) - } + guard lhs.rawValue.st_dev == rhs.rawValue.st_dev, + lhs.rawValue.st_ino == rhs.rawValue.st_ino, + lhs.rawValue.st_mode == rhs.rawValue.st_mode, + lhs.rawValue.st_nlink == rhs.rawValue.st_nlink, + lhs.rawValue.st_uid == rhs.rawValue.st_uid, + lhs.rawValue.st_gid == rhs.rawValue.st_gid, + lhs.rawValue.st_rdev == rhs.rawValue.st_rdev, + lhs.rawValue.st_size == rhs.rawValue.st_size, + lhs.rawValue.st_blksize == rhs.rawValue.st_blksize, + lhs.rawValue.st_blocks == rhs.rawValue.st_blocks, + lhs.st_atim.tv_sec == rhs.st_atim.tv_sec, + lhs.st_atim.tv_nsec == rhs.st_atim.tv_nsec, + lhs.st_mtim.tv_sec == rhs.st_mtim.tv_sec, + lhs.st_mtim.tv_nsec == rhs.st_mtim.tv_nsec, + lhs.st_ctim.tv_sec == rhs.st_ctim.tv_sec, + lhs.st_ctim.tv_nsec == rhs.st_ctim.tv_nsec else { + return false } + #if SYSTEM_PACKAGE_DARWIN || os(FreeBSD) + guard lhs.st_birthtim.tv_sec == rhs.st_birthtim.tv_sec, + lhs.st_birthtim.tv_nsec == rhs.st_birthtim.tv_nsec else { + return false + } + #endif + #if SYSTEM_PACKAGE_DARWIN || os(FreeBSD) || os(OpenBSD) + guard lhs.rawValue.st_flags == rhs.rawValue.st_flags, + lhs.rawValue.st_gen == rhs.rawValue.st_gen else { + return false + } + #endif + return true } } @available(System 1.7.0, *) extension Stat: Hashable { + /// Hashes a subset of `Stat` fields that identify a file: the device and + /// inode identity plus a couple of high-entropy discriminators (size and + /// modification time). @_alwaysEmitIntoClient - /// Hashes the raw bytes of this `Stat` struct. public func hash(into hasher: inout Hasher) { - withUnsafeBytes(of: rawValue) { bytes in - hasher.combine(bytes: bytes) - } + hasher.combine(rawValue.st_dev) + hasher.combine(rawValue.st_ino) + hasher.combine(rawValue.st_size) + hasher.combine(st_mtim.tv_sec) + hasher.combine(st_mtim.tv_nsec) } } diff --git a/Tests/SystemTests/StatTests.swift b/Tests/SystemTests/StatTests.swift index 715b8a7..80062e2 100644 --- a/Tests/SystemTests/StatTests.swift +++ b/Tests/SystemTests/StatTests.swift @@ -397,6 +397,38 @@ private struct StatTests { } #endif + @available(System 1.7.0, *) + @Test func equalityAndHashing() async throws { + try withTemporaryFilePath(basename: "Stat_equality") { tempDir in + let file = tempDir.appending("test.txt") + let fd = try FileDescriptor.open( + file, .writeOnly, options: .create, permissions: .ownerReadWrite) + defer { try? fd.close() } + + // Two stats of the same, unchanged file compare equal and hash equal, + // so they coalesce in a Set. + let stat1 = try file.stat() + var stat2 = try file.stat() + stat2.st_atim = stat1.st_atim // stat() can bump access time + #expect(stat1 == stat2) + #expect(stat1.hashValue == stat2.hashValue) + #expect(Set([stat1, stat2]).count == 1) + + // Reserved/"spare" and padding bytes must not affect equality. + // Poke a reserved field and confirm equality/hashing are stable. + #if SYSTEM_PACKAGE_DARWIN + var stat3 = stat1 + stat3.rawValue.st_lspare = stat1.rawValue.st_lspare &+ 1 + #expect(stat1 == stat3) + #expect(stat1.hashValue == stat3.hashValue) + #endif + + // A stat of a different file (the containing directory) is not equal. + let dirStat = try tempDir.stat() + #expect(stat1 != dirStat) + } + } + } // Comparison operators for timespec until UTCClock.Instant properties are available From 5d61ccdc7e08ce6cdb4bd78b1f3cdd9f13ade5db Mon Sep 17 00:00:00 2001 From: Jonathan Flat Date: Mon, 20 Jul 2026 11:48:41 -0600 Subject: [PATCH 07/10] Remove `@_alwaysEmitIntoClient` from `==` and `hash(into:)` The implementations of these functions are non-trivial, so remove the annotation to reduce client code size. --- Proposals/0006-system-stat.md | 2 +- Sources/System/FileSystem/Stat.swift | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/Proposals/0006-system-stat.md b/Proposals/0006-system-stat.md index 8a09f5d..9ef56ec 100644 --- a/Proposals/0006-system-stat.md +++ b/Proposals/0006-system-stat.md @@ -79,7 +79,7 @@ These initializers use a typed `throws(Errno)` and require Swift 6.0 or later. See the **Appendix** section at the end of this proposal for a table view of Swift API to C mappings. -All API are marked `@_alwaysEmitIntoClient` for performance and back-dating of availability. +All API are marked `@_alwaysEmitIntoClient` for performance and back-dating of availability, except `Stat`'s `==` and `hash(into:)`, which are ordinary `public` API. ### FileType diff --git a/Sources/System/FileSystem/Stat.swift b/Sources/System/FileSystem/Stat.swift index 1fd777c..30c4e81 100644 --- a/Sources/System/FileSystem/Stat.swift +++ b/Sources/System/FileSystem/Stat.swift @@ -541,7 +541,6 @@ extension Stat: Equatable { /// Compares the meaningful file-metadata fields of two `Stat` values. /// /// Alignment padding and platform reserved/"spare" fields are not compared. - @_alwaysEmitIntoClient public static func == (lhs: Self, rhs: Self) -> Bool { guard lhs.rawValue.st_dev == rhs.rawValue.st_dev, lhs.rawValue.st_ino == rhs.rawValue.st_ino, @@ -582,7 +581,6 @@ extension Stat: Hashable { /// Hashes a subset of `Stat` fields that identify a file: the device and /// inode identity plus a couple of high-entropy discriminators (size and /// modification time). - @_alwaysEmitIntoClient public func hash(into hasher: inout Hasher) { hasher.combine(rawValue.st_dev) hasher.combine(rawValue.st_ino) From 7c072c0d97745406fb73a8085b7cb67b8628afbb Mon Sep 17 00:00:00 2001 From: Jonathan Flat Date: Mon, 20 Jul 2026 13:23:25 -0600 Subject: [PATCH 08/10] Hash the same fields compared by `==` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From the `hash(into:)` docs: "The components used for hashing must be the same as the components compared in your type’s == operator implementation." --- Proposals/0006-system-stat.md | 2 +- Sources/System/FileSystem/Stat.swift | 26 +++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Proposals/0006-system-stat.md b/Proposals/0006-system-stat.md index 9ef56ec..a1fbd41 100644 --- a/Proposals/0006-system-stat.md +++ b/Proposals/0006-system-stat.md @@ -712,7 +712,7 @@ extension Stat: Equatable { } extension Stat: Hashable { - /// Hashes a subset of the fields compared by `==` that identify a file. + /// Hashes the meaningful file-metadata fields of a `Stat` struct. public func hash(into hasher: inout Hasher) } ``` diff --git a/Sources/System/FileSystem/Stat.swift b/Sources/System/FileSystem/Stat.swift index 30c4e81..ba822bc 100644 --- a/Sources/System/FileSystem/Stat.swift +++ b/Sources/System/FileSystem/Stat.swift @@ -578,15 +578,35 @@ extension Stat: Equatable { @available(System 1.7.0, *) extension Stat: Hashable { - /// Hashes a subset of `Stat` fields that identify a file: the device and - /// inode identity plus a couple of high-entropy discriminators (size and - /// modification time). + /// Hashes the meaningful file-metadata fields of a `Stat` struct. + /// + /// These are the same fields compared by `==`, fed in the same order. + /// Alignment padding and platform reserved/"spare" fields are not hashed. public func hash(into hasher: inout Hasher) { hasher.combine(rawValue.st_dev) hasher.combine(rawValue.st_ino) + hasher.combine(rawValue.st_mode) + hasher.combine(rawValue.st_nlink) + hasher.combine(rawValue.st_uid) + hasher.combine(rawValue.st_gid) + hasher.combine(rawValue.st_rdev) hasher.combine(rawValue.st_size) + hasher.combine(rawValue.st_blksize) + hasher.combine(rawValue.st_blocks) + hasher.combine(st_atim.tv_sec) + hasher.combine(st_atim.tv_nsec) hasher.combine(st_mtim.tv_sec) hasher.combine(st_mtim.tv_nsec) + hasher.combine(st_ctim.tv_sec) + hasher.combine(st_ctim.tv_nsec) + #if SYSTEM_PACKAGE_DARWIN || os(FreeBSD) + hasher.combine(st_birthtim.tv_sec) + hasher.combine(st_birthtim.tv_nsec) + #endif + #if SYSTEM_PACKAGE_DARWIN || os(FreeBSD) || os(OpenBSD) + hasher.combine(rawValue.st_flags) + hasher.combine(rawValue.st_gen) + #endif } } From bd155c104f0db13c12437a0b52945ce6c1de79a2 Mon Sep 17 00:00:00 2001 From: Jonathan Flat Date: Mon, 20 Jul 2026 20:35:00 -0600 Subject: [PATCH 09/10] Enable FreeBSD checks --- .github/workflows/pull_request.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 9aade4d..84b09ac 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -61,6 +61,7 @@ jobs: ] enable_android_sdk_build: true enable_android_sdk_checks: true + enable_freebsd_checks: true build-abi-stable: name: Build ABI Stable From 50688cacbd41d547e9eb9f7a213542340b7c442b Mon Sep 17 00:00:00 2001 From: Jonathan Flat Date: Mon, 20 Jul 2026 16:21:42 -0600 Subject: [PATCH 10/10] Update Stat.generationNumber to UInt64 --- Proposals/0006-system-stat.md | 9 +++++---- Sources/System/FileSystem/Stat.swift | 13 +++++++------ 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Proposals/0006-system-stat.md b/Proposals/0006-system-stat.md index a1fbd41..4b1c2ec 100644 --- a/Proposals/0006-system-stat.md +++ b/Proposals/0006-system-stat.md @@ -693,12 +693,13 @@ public struct Stat: RawRepresentable, Sendable { /// File generation number /// - /// The file generation number is used to distinguish between different files - /// that have used the same inode over time. + /// The file generation number may be used to distinguish between different + /// files that have used the same inode over time. /// /// The corresponding C property is `st_gen`. - /// - Note: Only available on Darwin, FreeBSD, and OpenBSD. - public var generationNumber: Int { get set } + /// - Note: Only available on Darwin, FreeBSD, and OpenBSD. The underlying C + /// field is 32-bit on Darwin and OpenBSD, and 64-bit on FreeBSD. + public var generationNumber: UInt64 { get set } #endif } diff --git a/Sources/System/FileSystem/Stat.swift b/Sources/System/FileSystem/Stat.swift index ba822bc..ce4b6b5 100644 --- a/Sources/System/FileSystem/Stat.swift +++ b/Sources/System/FileSystem/Stat.swift @@ -521,15 +521,16 @@ public struct Stat: RawRepresentable, Sendable { /// File generation number /// - /// The file generation number is used to distinguish between different files - /// that have used the same inode over time. + /// The file generation number may be used to distinguish between different + /// files that have used the same inode over time. /// /// The corresponding C property is `st_gen`. - /// - Note: Only available on Darwin, FreeBSD, and OpenBSD. + /// - Note: Only available on Darwin, FreeBSD, and OpenBSD. The underlying C + /// field is 32-bit on Darwin and OpenBSD, and 64-bit on FreeBSD. @_alwaysEmitIntoClient - public var generationNumber: Int { - get { Int(rawValue.st_gen) } - set { rawValue.st_gen = numericCast(newValue)} + public var generationNumber: UInt64 { + get { UInt64(rawValue.st_gen) } + set { rawValue.st_gen = numericCast(newValue) } } #endif }