Skip to content

Commit 433baa1

Browse files
committed
WIP: Ideas for stat.h interface
1 parent 2fa2678 commit 433baa1

11 files changed

+1169
-8
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/*.xcodeproj
55
xcuserdata/
66
.*.sw?
7+
.swiftpm
+202
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
1+
/*
2+
This source file is part of the Swift System open source project
3+
4+
Copyright (c) 2021 Apple Inc. and the Swift System project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
*/
9+
10+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
11+
12+
// FIXME: Document
13+
@frozen
14+
// @available(macOS 12, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
15+
public struct FileFlags: OptionSet {
16+
/// The raw C file flags.
17+
@_alwaysEmitIntoClient
18+
public let rawValue: CInterop.FileFlags
19+
20+
/// Create a strongly-typed file flags from a raw C value.
21+
@_alwaysEmitIntoClient
22+
public init(rawValue: CInterop.FileFlags) { self.rawValue = rawValue }
23+
24+
@_alwaysEmitIntoClient
25+
private init(_ raw: CInterop.FileFlags) { self.init(rawValue: raw) }
26+
27+
/// Do not dump the file. Modifiable by file owner or super-user.
28+
///
29+
/// The corresponding C constant is `UF_NODUMP`
30+
@_alwaysEmitIntoClient
31+
public static var noDump: FileFlags { FileFlags(_UF_NODUMP) }
32+
33+
@_alwaysEmitIntoClient
34+
@available(*, unavailable, renamed: "noDump")
35+
public static var UF_NODUMP: FileFlags { noDump }
36+
37+
/// The file may not be changed. Modifiable by file owner or super-user.
38+
///
39+
/// The corresponding C constant is `UF_IMMUTABLE`
40+
@_alwaysEmitIntoClient
41+
public static var immutable: FileFlags { FileFlags(_UF_IMMUTABLE) }
42+
43+
@_alwaysEmitIntoClient
44+
@available(*, unavailable, renamed: "immutable")
45+
public static var UF_IMMUTABLE: FileFlags { immutable }
46+
47+
/// The file may only be appended to. Modifiable by file owner or super-user.
48+
///
49+
/// The corresponding C constant is `UF_APPEND`
50+
@_alwaysEmitIntoClient
51+
public static var appendOnly: FileFlags { FileFlags(_UF_APPEND) }
52+
53+
@_alwaysEmitIntoClient
54+
@available(*, unavailable, renamed: "appendOnly")
55+
public static var UF_APPEND: FileFlags { appendOnly }
56+
57+
/// The directory is opaque when viewed through a union stack. Modifiable by file owner or super-user.
58+
///
59+
/// The corresponding C constant is `UF_OPAQUE`
60+
@_alwaysEmitIntoClient
61+
public static var opaque: FileFlags { FileFlags(_UF_OPAQUE) }
62+
63+
@_alwaysEmitIntoClient
64+
@available(*, unavailable, renamed: "opaque")
65+
public static var UF_OPAQUE: FileFlags { opaque }
66+
67+
#if os(FreeBSD)
68+
/// The file may not be removed or renamed. Modifiable by file owner or super-user.
69+
///
70+
/// The corresponding C constant is `UF_NOUNLINK`
71+
@_alwaysEmitIntoClient
72+
public static var noUnlink: FileFlags { FileFlags(_UF_NOUNLINK) }
73+
74+
@_alwaysEmitIntoClient
75+
@available(*, unavailable, renamed: "noUnlink")
76+
public static var UF_NOUNLINK: FileFlags { noUnlink }
77+
#endif
78+
79+
/// The file is compressed (some file-systems). Modifiable by file owner or super-user.
80+
///
81+
/// The corresponding C constant is `UF_COMPRESSED`
82+
@_alwaysEmitIntoClient
83+
public static var compressed: FileFlags { FileFlags(_UF_COMPRESSED) }
84+
85+
@_alwaysEmitIntoClient
86+
@available(*, unavailable, renamed: "compressed")
87+
public static var UF_COMPRESSED: FileFlags { compressed }
88+
89+
/// No notifications will be issued for deletes or renames. Modifiable by file owner or super-user.
90+
///
91+
/// The corresponding C constant is `UF_TRACKED`
92+
@_alwaysEmitIntoClient
93+
public static var tracked: FileFlags { FileFlags(_UF_TRACKED) }
94+
95+
@_alwaysEmitIntoClient
96+
@available(*, unavailable, renamed: "tracked")
97+
public static var UF_TRACKED: FileFlags { tracked }
98+
99+
/// The file requires entitlement required for reading and writing. Modifiable by file owner or super-user.
100+
///
101+
/// The corresponding C constant is `UF_DATAVAULT`
102+
@_alwaysEmitIntoClient
103+
public static var dataVault: FileFlags { FileFlags(_UF_DATAVAULT) }
104+
105+
@_alwaysEmitIntoClient
106+
@available(*, unavailable, renamed: "dataVault")
107+
public static var UF_DATAVAULT: FileFlags { dataVault }
108+
109+
/// The file or directory is not intended to be displayed to the user. Modifiable by file owner or super-user.
110+
///
111+
/// The corresponding C constant is `UF_HIDDEN`
112+
@_alwaysEmitIntoClient
113+
public static var hidden: FileFlags { FileFlags(_UF_HIDDEN) }
114+
115+
@_alwaysEmitIntoClient
116+
@available(*, unavailable, renamed: "hidden")
117+
public static var UF_HIDDEN: FileFlags { hidden }
118+
119+
/// The file has been archived. Only modifiable by the super-user.
120+
///
121+
/// The corresponding C constant is `SF_ARCHIVED`
122+
@_alwaysEmitIntoClient
123+
public static var superUserArchived: FileFlags { FileFlags(_SF_ARCHIVED) }
124+
125+
@_alwaysEmitIntoClient
126+
@available(*, unavailable, renamed: "superUserArchived")
127+
public static var SF_ARCHIVED: FileFlags { superUserArchived }
128+
129+
/// The file may not be changed. Only modifiable by the super-user.
130+
///
131+
/// The corresponding C constant is `SF_IMMUTABLE`
132+
@_alwaysEmitIntoClient
133+
public static var superUserImmutable: FileFlags { FileFlags(_SF_IMMUTABLE) }
134+
135+
@_alwaysEmitIntoClient
136+
@available(*, unavailable, renamed: "superUserImmutable")
137+
public static var SF_IMMUTABLE: FileFlags { superUserImmutable }
138+
139+
/// The file may only be appended to. Only modifiable by the super-user.
140+
///
141+
/// The corresponding C constant is `SF_APPEND`
142+
@_alwaysEmitIntoClient
143+
public static var superUserAppend: FileFlags { FileFlags(_SF_APPEND) }
144+
145+
@_alwaysEmitIntoClient
146+
@available(*, unavailable, renamed: "superUserAppend")
147+
public static var SF_APPEND: FileFlags { superUserAppend }
148+
149+
/// The file requires entitlement required for reading and writing. Only modifiable by the super-user.
150+
///
151+
/// The corresponding C constant is `SF_RESTRICTED`
152+
@_alwaysEmitIntoClient
153+
public static var superUserRestricted: FileFlags { FileFlags(_SF_RESTRICTED) }
154+
155+
@_alwaysEmitIntoClient
156+
@available(*, unavailable, renamed: "superUserRestricted")
157+
public static var SF_RESTRICTED: FileFlags { superUserRestricted }
158+
159+
/// The file may not be removed, renamed or mounted on. Only modifiable by the super-user.
160+
///
161+
/// The corresponding C constant is `SF_NOUNLINK`
162+
@_alwaysEmitIntoClient
163+
public static var superUserNoUnlink: FileFlags { FileFlags(_SF_NOUNLINK) }
164+
165+
@_alwaysEmitIntoClient
166+
@available(*, unavailable, renamed: "superUserNoUnlink")
167+
public static var SF_NOUNLINK: FileFlags { superUserNoUnlink }
168+
169+
#if os(FreeBSD)
170+
/// The file is a snapshot file. Only modifiable by the super-user.
171+
///
172+
/// The corresponding C constant is `SF_SNAPSHOT`
173+
@_alwaysEmitIntoClient
174+
public static var superUserSnapshot: FileFlags { FileFlags(_SF_SNAPSHOT) }
175+
176+
@_alwaysEmitIntoClient
177+
@available(*, unavailable, renamed: "superUserSnapshot")
178+
public static var SF_SNAPSHOT: FileFlags { superUserSnapshot }
179+
#endif
180+
181+
/// The file is a firmlink. Only modifiable by the super-user.
182+
///
183+
/// The corresponding C constant is `SF_FIRMLINK`
184+
@_alwaysEmitIntoClient
185+
public static var superUserFirmlink: FileFlags { FileFlags(_SF_FIRMLINK) }
186+
187+
@_alwaysEmitIntoClient
188+
@available(*, unavailable, renamed: "superUserFirmlink")
189+
public static var SF_FIRMLINK: FileFlags { superUserFirmlink }
190+
191+
/// The file is a dataless placeholder. The system will attempt to materialize it when accessed according to the dataless file materialization policy of the accessing thread or process. Cannot be modified in user-space.
192+
///
193+
/// The corresponding C constant is `SF_DATALESS`
194+
@_alwaysEmitIntoClient
195+
public static var kernelDataless: FileFlags { FileFlags(_SF_DATALESS) }
196+
197+
@_alwaysEmitIntoClient
198+
@available(*, unavailable, renamed: "kernelDataless")
199+
public static var SF_DATALESS: FileFlags { kernelDataless }
200+
}
201+
202+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
This source file is part of the Swift System open source project
3+
4+
Copyright (c) 2021 Apple Inc. and the Swift System project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
*/
9+
10+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
11+
12+
// FIXME: should the subtypes of Mode mask their rawValues to only allow their bits to be changed?
13+
14+
// FIXME: Document
15+
@frozen
16+
// @available(macOS 12, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
17+
public struct FileMode: RawRepresentable {
18+
/// The raw C file mode.
19+
@_alwaysEmitIntoClient
20+
public var rawValue: CInterop.Mode
21+
22+
/// Create a strongly-typed file mode from a raw C value.
23+
@_alwaysEmitIntoClient
24+
public init(rawValue: CInterop.Mode) { self.rawValue = rawValue }
25+
26+
/// Subset of mode for accessing and modifying file permissions.
27+
@_alwaysEmitIntoClient
28+
public var permissions: FilePermissions {
29+
get { FilePermissions(rawValue: rawValue & _MODE_PERMISSIONS) }
30+
set { rawValue = (rawValue & ~_MODE_PERMISSIONS) | (newValue.rawValue & _MODE_PERMISSIONS ) }
31+
}
32+
33+
/// Subset of mode for accessing and modifying file mode other.
34+
@_alwaysEmitIntoClient
35+
public var other: FileModeOther {
36+
get { FileModeOther(rawValue: rawValue & _MODE_OTHER) }
37+
set { rawValue = (rawValue & ~_MODE_OTHER) | (newValue.rawValue & _MODE_OTHER ) }
38+
}
39+
40+
/// Subset of mode for accessing and modifying file type.
41+
@_alwaysEmitIntoClient
42+
public var type: FileType {
43+
get { FileType(rawValue: rawValue & _MODE_TYPE) }
44+
set { rawValue = (rawValue & ~_MODE_TYPE) | (newValue.rawValue & _MODE_TYPE ) }
45+
}
46+
}
47+
48+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
This source file is part of the Swift System open source project
3+
4+
Copyright (c) 2021 Apple Inc. and the Swift System project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
*/
9+
10+
#if os(macOS) || os(iOS) || os(watchOS) || os(tvOS)
11+
12+
// FIXME: Rename
13+
// FIXME: Document
14+
@frozen
15+
// @available(macOS 12, iOS 15.0, watchOS 8.0, tvOS 15.0, *)
16+
public struct FileModeOther: OptionSet {
17+
/// The raw C file mode other.
18+
@_alwaysEmitIntoClient
19+
public var rawValue: CInterop.Mode
20+
21+
/// Create a strongly-typed file mode other from a raw C value.
22+
@_alwaysEmitIntoClient
23+
public init(rawValue: CInterop.Mode) { self.rawValue = rawValue }
24+
25+
@_alwaysEmitIntoClient
26+
private init(_ raw: CInterop.Mode) { self.init(rawValue: raw) }
27+
28+
/// Indicates that the file is executed as the owner.
29+
///
30+
/// For more information, see the `setuid(2)` man page.
31+
@_alwaysEmitIntoClient
32+
public static var setUserID: FileModeOther { FileModeOther(0o4000) }
33+
34+
/// Indicates that the file is executed as the group.
35+
///
36+
/// For more information, see the `setgid(2)` man page.
37+
@_alwaysEmitIntoClient
38+
public static var setGroupID: FileModeOther { FileModeOther(0o2000) }
39+
40+
/// Indicates that executable's text segment
41+
/// should be kept in swap space even after it exits.
42+
///
43+
/// For more information, see the `chmod(2)` man page's
44+
/// discussion of `S_ISVTX` (the sticky bit).
45+
@_alwaysEmitIntoClient
46+
public static var saveText: FileModeOther { FileModeOther(0o1000) }
47+
}
48+
49+
#endif

0 commit comments

Comments
 (0)