forked from apple/containerization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEXT4+Types.swift
More file actions
633 lines (592 loc) · 25 KB
/
Copy pathEXT4+Types.swift
File metadata and controls
633 lines (592 loc) · 25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
//===----------------------------------------------------------------------===//
// Copyright © 2025-2026 Apple Inc. and the Containerization project authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//
// swiftlint:disable large_tuple
import Foundation
extension EXT4 {
public struct SuperBlock {
public var inodesCount: UInt32 = 0
public var blocksCountLow: UInt32 = 0
public var reservedBlocksCountLow: UInt32 = 0
public var freeBlocksCountLow: UInt32 = 0
public var freeInodesCount: UInt32 = 0
public var firstDataBlock: UInt32 = 0
public var logBlockSize: UInt32 = 0
public var logClusterSize: UInt32 = 0
public var blockSize: UInt32 { 1024 << logBlockSize }
public var blocksPerGroup: UInt32 = 0
public var clustersPerGroup: UInt32 = 0
public var inodesPerGroup: UInt32 = 0
public var mtime: UInt32 = 0
public var wtime: UInt32 = 0
public var mountCount: UInt16 = 0
public var maxMountCount: UInt16 = 0
public var magic: UInt16 = 0
public var state: UInt16 = 0
public var errors: UInt16 = 0
public var minorRevisionLevel: UInt16 = 0
public var lastCheck: UInt32 = 0
public var checkInterval: UInt32 = 0
public var creatorOS: UInt32 = 0
public var revisionLevel: UInt32 = 0
public var defaultReservedUid: UInt16 = 0
public var defaultReservedGid: UInt16 = 0
public var firstInode: UInt32 = 0
public var inodeSize: UInt16 = 0
public var blockGroupNr: UInt16 = 0
public var featureCompat: UInt32 = 0
public var featureIncompat: UInt32 = 0
public var featureRoCompat: UInt32 = 0
public var uuid:
(
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
) = (
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
)
public var volumeName:
(
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
) = (
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
)
public var lastMounted:
(
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
) = (
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
)
public var algorithmUsageBitmap: UInt32 = 0
public var preallocBlocks: UInt8 = 0
public var preallocDirBlocks: UInt8 = 0
public var reservedGdtBlocks: UInt16 = 0
public var journalUUID:
(
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
) = (
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
)
public var journalInum: UInt32 = 0
public var journalDev: UInt32 = 0
public var lastOrphan: UInt32 = 0
public var hashSeed: (UInt32, UInt32, UInt32, UInt32) = (0, 0, 0, 0)
public var defHashVersion: UInt8 = 0
public var journalBackupType: UInt8 = 0
public var descSize: UInt16 = UInt16(MemoryLayout<GroupDescriptor>.size)
public var defaultMountOpts: UInt32 = 0
public var firstMetaBg: UInt32 = 0
public var mkfsTime: UInt32 = 0
public var journalBlocks:
(
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
UInt32
) = (
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0
)
public var blocksCountHigh: UInt32 = 0
public var reservedBlocksCountHigh: UInt32 = 0
public var freeBlocksCountHigh: UInt32 = 0
public var minExtraIsize: UInt16 = 0
public var wantExtraIsize: UInt16 = 0
public var flags: UInt32 = 0
public var raidStride: UInt16 = 0
public var mmpInterval: UInt16 = 0
public var mmpBlock: UInt64 = 0
public var raidStripeWidth: UInt32 = 0
public var logGroupsPerFlex: UInt8 = 0
public var checksumType: UInt8 = 0
public var reservedPad: UInt16 = 0
public var kbytesWritten: UInt64 = 0
public var snapshotInum: UInt32 = 0
public var snapshotID: UInt32 = 0
public var snapshotRBlocksCount: UInt64 = 0
public var snapshotList: UInt32 = 0
public var errorCount: UInt32 = 0
public var firstErrorTime: UInt32 = 0
public var firstErrorInode: UInt32 = 0
public var firstErrorBlock: UInt64 = 0
public var firstErrorFunc:
(
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
) = (
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
)
public var firstErrorLine: UInt32 = 0
public var lastErrorTime: UInt32 = 0
public var lastErrorInode: UInt32 = 0
public var lastErrorLine: UInt32 = 0
public var lastErrorBlock: UInt64 = 0
public var lastErrorFunc:
(
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
) = (
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
)
public var mountOpts:
(
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
) = (
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
)
public var userQuotaInum: UInt32 = 0
public var groupQuotaInum: UInt32 = 0
public var overheadBlocks: UInt32 = 0
public var backupBgs: (UInt32, UInt32) = (0, 0)
public var encryptAlgos: (UInt8, UInt8, UInt8, UInt8) = (0, 0, 0, 0)
public var encryptPwSalt:
(
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
) = (
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
)
public var lpfInode: UInt32 = 0
public var projectQuotaInum: UInt32 = 0
public var checksumSeed: UInt32 = 0
public var wtimeHigh: UInt8 = 0
public var mtimeHigh: UInt8 = 0
public var mkfsTimeHigh: UInt8 = 0
public var lastcheckHigh: UInt8 = 0
public var firstErrorTimeHigh: UInt8 = 0
public var lastErrorTimeHigh: UInt8 = 0
public var pad: (UInt8, UInt8) = (0, 0)
public var reserved:
(
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32
) = (
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
)
public var checksum: UInt32 = 0
}
static let JournalMagic: UInt32 = 0xC03B_3998
static let JournalInode: InodeNumber = 8
static let MinJournalBlocks: UInt32 = 1024 // JBD2_MIN_JOURNAL_BLOCKS
struct DefaultMountOpts {
static let journalData: UInt32 = 0x0020 // data=journal
static let journalOrdered: UInt32 = 0x0040 // data=ordered
static let journalWriteback: UInt32 = 0x0060 // data=writeback
}
struct CompatFeature {
let rawValue: UInt32
static let dirPrealloc = CompatFeature(rawValue: 0x1)
static let imagicInodes = CompatFeature(rawValue: 0x2)
static let hasJournal = CompatFeature(rawValue: 0x4)
static let extAttr = CompatFeature(rawValue: 0x8)
static let resizeInode = CompatFeature(rawValue: 0x10)
static let dirIndex = CompatFeature(rawValue: 0x20)
static let lazyBg = CompatFeature(rawValue: 0x40)
static let excludeInode = CompatFeature(rawValue: 0x80)
static let excludeBitmap = CompatFeature(rawValue: 0x100)
static let sparseSuper2 = CompatFeature(rawValue: 0x200)
}
struct IncompatFeature {
let rawValue: UInt32
static let compression = IncompatFeature(rawValue: 0x1)
static let filetype = IncompatFeature(rawValue: 0x2)
static let recover = IncompatFeature(rawValue: 0x4)
static let journalDev = IncompatFeature(rawValue: 0x8)
static let metaBg = IncompatFeature(rawValue: 0x10)
static let extents = IncompatFeature(rawValue: 0x40)
static let bit64 = IncompatFeature(rawValue: 0x80)
static let mmp = IncompatFeature(rawValue: 0x100)
static let flexBg = IncompatFeature(rawValue: 0x200)
static let eaInode = IncompatFeature(rawValue: 0x400)
static let dirdata = IncompatFeature(rawValue: 0x1000)
static let csumSeed = IncompatFeature(rawValue: 0x2000)
static let largedir = IncompatFeature(rawValue: 0x4000)
static let inlineData = IncompatFeature(rawValue: 0x8000)
static let encrypt = IncompatFeature(rawValue: 0x10000)
}
struct RoCompatFeature {
let rawValue: UInt32
static let sparseSuper = RoCompatFeature(rawValue: 0x1)
static let largeFile = RoCompatFeature(rawValue: 0x2)
static let btreeDir = RoCompatFeature(rawValue: 0x4)
static let hugeFile = RoCompatFeature(rawValue: 0x8)
static let gdtCsum = RoCompatFeature(rawValue: 0x10)
static let dirNlink = RoCompatFeature(rawValue: 0x20)
static let extraIsize = RoCompatFeature(rawValue: 0x40)
static let hasSnapshot = RoCompatFeature(rawValue: 0x80)
static let quota = RoCompatFeature(rawValue: 0x100)
static let bigalloc = RoCompatFeature(rawValue: 0x200)
static let metadataCsum = RoCompatFeature(rawValue: 0x400)
static let replica = RoCompatFeature(rawValue: 0x800)
static let readonly = RoCompatFeature(rawValue: 0x1000)
static let project = RoCompatFeature(rawValue: 0x2000)
}
struct BlockGroupFlag {
let rawValue: UInt16
static let inodeUninit = BlockGroupFlag(rawValue: 0x1)
static let blockUninit = BlockGroupFlag(rawValue: 0x2)
static let inodeZeroed = BlockGroupFlag(rawValue: 0x4)
}
struct GroupDescriptor {
let blockBitmapLow: UInt32
let inodeBitmapLow: UInt32
let inodeTableLow: UInt32
let freeBlocksCountLow: UInt16
let freeInodesCountLow: UInt16
let usedDirsCountLow: UInt16
let flags: UInt16
let excludeBitmapLow: UInt32
let blockBitmapCsumLow: UInt16
let inodeBitmapCsumLow: UInt16
let itableUnusedLow: UInt16
let checksum: UInt16
}
struct GroupDescriptor64 {
let groupDescriptor: GroupDescriptor
let blockBitmapHigh: UInt32
let inodeBitmapHigh: UInt32
let inodeTableHigh: UInt32
let freeBlocksCountHigh: UInt16
let freeInodesCountHigh: UInt16
let usedDirsCountHigh: UInt16
let itableUnusedHigh: UInt16
let excludeBitmapHigh: UInt32
let blockBitmapCsumHigh: UInt16
let inodeBitmapCsumHigh: UInt16
let reserved: UInt32
}
public struct FileModeFlag: Sendable {
let rawValue: UInt16
public static let S_IXOTH = FileModeFlag(rawValue: 0x1)
public static let S_IWOTH = FileModeFlag(rawValue: 0x2)
public static let S_IROTH = FileModeFlag(rawValue: 0x4)
public static let S_IXGRP = FileModeFlag(rawValue: 0x8)
public static let S_IWGRP = FileModeFlag(rawValue: 0x10)
public static let S_IRGRP = FileModeFlag(rawValue: 0x20)
public static let S_IXUSR = FileModeFlag(rawValue: 0x40)
public static let S_IWUSR = FileModeFlag(rawValue: 0x80)
public static let S_IRUSR = FileModeFlag(rawValue: 0x100)
public static let S_ISVTX = FileModeFlag(rawValue: 0x200)
public static let S_ISGID = FileModeFlag(rawValue: 0x400)
public static let S_ISUID = FileModeFlag(rawValue: 0x800)
public static let S_IFIFO = FileModeFlag(rawValue: 0x1000)
public static let S_IFCHR = FileModeFlag(rawValue: 0x2000)
public static let S_IFDIR = FileModeFlag(rawValue: 0x4000)
public static let S_IFBLK = FileModeFlag(rawValue: 0x6000)
public static let S_IFREG = FileModeFlag(rawValue: 0x8000)
public static let S_IFLNK = FileModeFlag(rawValue: 0xA000)
public static let S_IFSOCK = FileModeFlag(rawValue: 0xC000)
public static let TypeMask = FileModeFlag(rawValue: 0xF000)
}
public typealias InodeNumber = UInt32
public struct Inode {
public var mode: UInt16 = 0
public var uid: UInt16 = 0
public var sizeLow: UInt32 = 0
public var atime: UInt32 = 0
public var ctime: UInt32 = 0
public var mtime: UInt32 = 0
public var dtime: UInt32 = 0
public var gid: UInt16 = 0
public var linksCount: UInt16 = 0
public var blocksLow: UInt32 = 0
public var flags: UInt32 = 0
public var version: UInt32 = 0
public var block:
(
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
) = (
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0
)
public var generation: UInt32 = 0
public var xattrBlockLow: UInt32 = 0
public var sizeHigh: UInt32 = 0
public var obsoleteFragmentAddr: UInt32 = 0
public var blocksHigh: UInt16 = 0
public var xattrBlockHigh: UInt16 = 0
public var uidHigh: UInt16 = 0
public var gidHigh: UInt16 = 0
public var checksumLow: UInt16 = 0
public var reserved: UInt16 = 0
public var extraIsize: UInt16 = 0
public var checksumHigh: UInt16 = 0
public var ctimeExtra: UInt32 = 0
public var mtimeExtra: UInt32 = 0
public var atimeExtra: UInt32 = 0
public var crtime: UInt32 = 0
public var crtimeExtra: UInt32 = 0
public var versionHigh: UInt32 = 0
public var projid: UInt32 = 0 // Size until this point is 160 bytes
public var inlineXattrs:
( // 96 bytes for extended attributes
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
) = (
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0
)
public static func Mode(_ mode: FileModeFlag, _ perm: UInt16) -> UInt16 {
mode.rawValue | perm
}
}
struct InodeFlag {
let rawValue: UInt32
static let secRm = InodeFlag(rawValue: 0x1)
static let unRm = InodeFlag(rawValue: 0x2)
static let compressed = InodeFlag(rawValue: 0x4)
static let sync = InodeFlag(rawValue: 0x8)
static let immutable = InodeFlag(rawValue: 0x10)
static let append = InodeFlag(rawValue: 0x20)
static let noDump = InodeFlag(rawValue: 0x40)
static let noAtime = InodeFlag(rawValue: 0x80)
static let dirtyCompressed = InodeFlag(rawValue: 0x100)
static let compressedClusters = InodeFlag(rawValue: 0x200)
static let noCompress = InodeFlag(rawValue: 0x400)
static let encrypted = InodeFlag(rawValue: 0x800)
static let hashedIndex = InodeFlag(rawValue: 0x1000)
static let magic = InodeFlag(rawValue: 0x2000)
static let journalData = InodeFlag(rawValue: 0x4000)
static let noTail = InodeFlag(rawValue: 0x8000)
static let dirSync = InodeFlag(rawValue: 0x10000)
static let topDir = InodeFlag(rawValue: 0x20000)
static let hugeFile = InodeFlag(rawValue: 0x40000)
static let extents = InodeFlag(rawValue: 0x80000)
static let eaInode = InodeFlag(rawValue: 0x200000)
static let eofBlocks = InodeFlag(rawValue: 0x400000)
static let snapfile = InodeFlag(rawValue: 0x0100_0000)
static let snapfileDeleted = InodeFlag(rawValue: 0x0400_0000)
static let snapfileShrunk = InodeFlag(rawValue: 0x0800_0000)
static let inlineData = InodeFlag(rawValue: 0x1000_0000)
static let projectIDInherit = InodeFlag(rawValue: 0x2000_0000)
static let reserved = InodeFlag(rawValue: 0x8000_0000)
}
struct ExtentHeader {
let magic: UInt16
let entries: UInt16
let max: UInt16
let depth: UInt16
let generation: UInt32
}
struct ExtentIndex {
let block: UInt32
let leafLow: UInt32
let leafHigh: UInt16
let unused: UInt16
}
struct ExtentLeaf {
let block: UInt32
let length: UInt16
let startHigh: UInt16
let startLow: UInt32
}
struct ExtentTail {
let checksum: UInt32
}
struct ExtentIndexNode {
var header: ExtentHeader
var indices: [ExtentIndex]
}
struct ExtentLeafNode {
var header: ExtentHeader
var leaves: [ExtentLeaf]
}
struct DirectoryEntry {
let inode: InodeNumber
let recordLength: UInt16
let nameLength: UInt8
let fileType: UInt8
// let name: [UInt8]
}
enum FileType: UInt8 {
case unknown = 0x0
case regular = 0x1
case directory = 0x2
case character = 0x3
case block = 0x4
case fifo = 0x5
case socket = 0x6
case symbolicLink = 0x7
}
struct DirectoryEntryTail {
let reservedZero1: UInt32
let recordLength: UInt16
let reservedZero2: UInt8
let fileType: UInt8
let checksum: UInt32
}
struct DirectoryTreeRoot {
let dot: DirectoryEntry
let dotName: [UInt8]
let dotDot: DirectoryEntry
let dotDotName: [UInt8]
let reservedZero: UInt32
let hashVersion: UInt8
let infoLength: UInt8
let indirectLevels: UInt8
let unusedFlags: UInt8
let limit: UInt16
let count: UInt16
let block: UInt32
// let entries: [DirectoryTreeEntry]
}
struct DirectoryTreeNode {
let fakeInode: UInt32
let fakeRecordLength: UInt16
let nameLength: UInt8
let fileType: UInt8
let limit: UInt16
let count: UInt16
let block: UInt32
// let entries: [DirectoryTreeEntry]
}
struct DirectoryTreeEntry {
let hash: UInt32
let block: UInt32
}
struct DirectoryTreeTail {
let reserved: UInt32
let checksum: UInt32
}
struct XAttrEntry {
let nameLength: UInt8
let nameIndex: UInt8
let valueOffset: UInt16
let valueInum: UInt32
let valueSize: UInt32
let hash: UInt32
}
struct XAttrHeader {
let magic: UInt32
let referenceCount: UInt32
let blocks: UInt32
let hash: UInt32
let checksum: UInt32
let reserved: [UInt32]
}
}
extension EXT4.Inode {
public static func Root() -> EXT4.Inode {
var inode = Self() // inode
inode.mode = Self.Mode(.S_IFDIR, 0o755)
inode.linksCount = 2
inode.uid = 0
inode.gid = 0
// time
let now = Date().fs()
let now_lo: UInt32 = now.lo
let now_hi: UInt32 = now.hi
inode.atime = now_lo
inode.atimeExtra = now_hi
inode.ctime = now_lo
inode.ctimeExtra = now_hi
inode.mtime = now_lo
inode.mtimeExtra = now_hi
inode.crtime = now_lo
inode.crtimeExtra = now_hi
inode.flags = EXT4.InodeFlag.hugeFile.rawValue
inode.extraIsize = UInt16(EXT4.ExtraIsize)
return inode
}
}