Skip to content

Commit 90dfc9d

Browse files
authored
EXT4: Adjustments to file names and visibilities (#112)
- FileTimestamps constructor that actually let you provide values was not public, so it wasn't possible to pass in values other than nil. This change makes the other constructor and the underlying fields public. - Rename EXT4+Format to EXT4+Formatter - Rename EXT4+Export to EXT4Reader+Export - Make the superblock publicly accessible in the reader like the docs for the product states.
1 parent 6d9e4b9 commit 90dfc9d

File tree

5 files changed

+126
-121
lines changed

5 files changed

+126
-121
lines changed
File renamed without changes.

Sources/ContainerizationEXT4/EXT4+Reader.swift

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,25 @@ import SystemPackage
2020
extension EXT4 {
2121
/// The `EXT4Reader` opens a block device, parses the superblock, and loads group descriptors & inodes.
2222
public class EXT4Reader {
23+
public var superBlock: EXT4.SuperBlock {
24+
self._superBlock
25+
}
26+
2327
let handle: FileHandle
24-
let superBlock: EXT4.SuperBlock
28+
let _superBlock: EXT4.SuperBlock
2529

2630
private var groupDescriptors: [UInt32: EXT4.GroupDescriptor] = [:]
2731
private var inodes: [InodeNumber: EXT4.Inode] = [:]
2832

2933
var hardlinks: [FilePath: InodeNumber] = [:]
3034
var tree: EXT4.FileTree = EXT4.FileTree(EXT4.RootInode, ".")
3135
var blockSize: UInt64 {
32-
UInt64(1024 * (1 << superBlock.logBlockSize))
36+
UInt64(1024 * (1 << _superBlock.logBlockSize))
3337
}
3438

3539
private var groupDescriptorSize: UInt16 {
36-
if superBlock.featureIncompat & EXT4.IncompatFeature.bit64.rawValue != 0 {
37-
return superBlock.descSize
40+
if _superBlock.featureIncompat & EXT4.IncompatFeature.bit64.rawValue != 0 {
41+
return _superBlock.descSize
3842
}
3943
return UInt16(MemoryLayout<EXT4.GroupDescriptor>.size)
4044
}
@@ -60,7 +64,7 @@ extension EXT4 {
6064
guard sb.magic == EXT4.SuperBlockMagic else {
6165
throw EXT4.Error.invalidSuperBlock
6266
}
63-
self.superBlock = sb
67+
self._superBlock = sb
6468
var items: [(item: Ptr<EXT4.FileTree.FileTreeNode>, inode: InodeNumber)] = [
6569
(self.tree.root, EXT4.RootInode)
6670
]
@@ -116,7 +120,7 @@ extension EXT4 {
116120
}
117121

118122
private func readGroupDescriptor(_ number: UInt32) throws -> GroupDescriptor {
119-
let bs = UInt64(1024 * (1 << superBlock.logBlockSize))
123+
let bs = UInt64(1024 * (1 << _superBlock.logBlockSize))
120124
let offset = bs + UInt64(number) * UInt64(self.groupDescriptorSize)
121125
try self.handle.seek(toOffset: offset)
122126
guard let data = try? self.handle.read(upToCount: MemoryLayout<EXT4.GroupDescriptor>.size) else {
@@ -129,13 +133,13 @@ extension EXT4 {
129133
}
130134

131135
private func readInode(_ number: UInt32) throws -> Inode {
132-
let inodeGroupNumber = ((number - 1) / self.superBlock.inodesPerGroup)
133-
let numberInGroup = UInt64((number - 1) % self.superBlock.inodesPerGroup)
136+
let inodeGroupNumber = ((number - 1) / self._superBlock.inodesPerGroup)
137+
let numberInGroup = UInt64((number - 1) % self._superBlock.inodesPerGroup)
134138

135139
let gd = try getGroupDescriptor(inodeGroupNumber)
136140
let inodeTableStart = UInt64(gd.inodeTableLow) * self.blockSize
137141

138-
let inodeOffset: UInt64 = inodeTableStart + numberInGroup * UInt64(superBlock.inodeSize)
142+
let inodeOffset: UInt64 = inodeTableStart + numberInGroup * UInt64(_superBlock.inodeSize)
139143
try self.handle.seek(toOffset: inodeOffset)
140144
guard let inodeData = try self.handle.read(upToCount: MemoryLayout<EXT4.Inode>.size) else {
141145
throw EXT4.Error.couldNotReadInode(number)

Sources/ContainerizationEXT4/EXT4+Types.swift

Lines changed: 100 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -19,55 +19,55 @@
1919
import Foundation
2020

2121
extension EXT4 {
22-
struct SuperBlock {
23-
var inodesCount: UInt32 = 0
24-
var blocksCountLow: UInt32 = 0
25-
var rootBlocksCountLow: UInt32 = 0
26-
var freeBlocksCountLow: UInt32 = 0
27-
var freeInodesCount: UInt32 = 0
28-
var firstDataBlock: UInt32 = 0
29-
var logBlockSize: UInt32 = 0
30-
var logClusterSize: UInt32 = 0
31-
var blocksPerGroup: UInt32 = 0
32-
var clustersPerGroup: UInt32 = 0
33-
var inodesPerGroup: UInt32 = 0
34-
var mtime: UInt32 = 0
35-
var wtime: UInt32 = 0
36-
var mountCount: UInt16 = 0
37-
var maxMountCount: UInt16 = 0
38-
var magic: UInt16 = 0
39-
var state: UInt16 = 0
40-
var errors: UInt16 = 0
41-
var minorRevisionLevel: UInt16 = 0
42-
var lastCheck: UInt32 = 0
43-
var checkInterval: UInt32 = 0
44-
var creatorOS: UInt32 = 0
45-
var revisionLevel: UInt32 = 0
46-
var defaultReservedUid: UInt16 = 0
47-
var defaultReservedGid: UInt16 = 0
48-
var firstInode: UInt32 = 0
49-
var inodeSize: UInt16 = 0
50-
var blockGroupNr: UInt16 = 0
51-
var featureCompat: UInt32 = 0
52-
var featureIncompat: UInt32 = 0
53-
var featureRoCompat: UInt32 = 0
54-
var uuid:
22+
public struct SuperBlock {
23+
public var inodesCount: UInt32 = 0
24+
public var blocksCountLow: UInt32 = 0
25+
public var rootBlocksCountLow: UInt32 = 0
26+
public var freeBlocksCountLow: UInt32 = 0
27+
public var freeInodesCount: UInt32 = 0
28+
public var firstDataBlock: UInt32 = 0
29+
public var logBlockSize: UInt32 = 0
30+
public var logClusterSize: UInt32 = 0
31+
public var blocksPerGroup: UInt32 = 0
32+
public var clustersPerGroup: UInt32 = 0
33+
public var inodesPerGroup: UInt32 = 0
34+
public var mtime: UInt32 = 0
35+
public var wtime: UInt32 = 0
36+
public var mountCount: UInt16 = 0
37+
public var maxMountCount: UInt16 = 0
38+
public var magic: UInt16 = 0
39+
public var state: UInt16 = 0
40+
public var errors: UInt16 = 0
41+
public var minorRevisionLevel: UInt16 = 0
42+
public var lastCheck: UInt32 = 0
43+
public var checkInterval: UInt32 = 0
44+
public var creatorOS: UInt32 = 0
45+
public var revisionLevel: UInt32 = 0
46+
public var defaultReservedUid: UInt16 = 0
47+
public var defaultReservedGid: UInt16 = 0
48+
public var firstInode: UInt32 = 0
49+
public var inodeSize: UInt16 = 0
50+
public var blockGroupNr: UInt16 = 0
51+
public var featureCompat: UInt32 = 0
52+
public var featureIncompat: UInt32 = 0
53+
public var featureRoCompat: UInt32 = 0
54+
public var uuid:
5555
(
5656
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
5757
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
5858
) = (
5959
0, 0, 0, 0, 0, 0, 0, 0,
6060
0, 0, 0, 0, 0, 0, 0, 0
6161
)
62-
var volumeName:
62+
public var volumeName:
6363
(
6464
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
6565
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
6666
) = (
6767
0, 0, 0, 0, 0, 0, 0, 0,
6868
0, 0, 0, 0, 0, 0, 0, 0
6969
)
70-
var lastMounted:
70+
public var lastMounted:
7171
(
7272
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
7373
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
@@ -87,29 +87,29 @@ extension EXT4 {
8787
0, 0, 0, 0, 0, 0, 0, 0,
8888
0, 0, 0, 0, 0, 0, 0, 0
8989
)
90-
var algorithmUsageBitmap: UInt32 = 0
91-
var preallocBlocks: UInt8 = 0
92-
var preallocDirBlocks: UInt8 = 0
93-
var reservedGdtBlocks: UInt16 = 0
94-
var journalUUID:
90+
public var algorithmUsageBitmap: UInt32 = 0
91+
public var preallocBlocks: UInt8 = 0
92+
public var preallocDirBlocks: UInt8 = 0
93+
public var reservedGdtBlocks: UInt16 = 0
94+
public var journalUUID:
9595
(
9696
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
9797
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
9898
) = (
9999
0, 0, 0, 0, 0, 0, 0, 0,
100100
0, 0, 0, 0, 0, 0, 0, 0
101101
)
102-
var journalInum: UInt32 = 0
103-
var journalDev: UInt32 = 0
104-
var lastOrphan: UInt32 = 0
105-
var hashSeed: (UInt32, UInt32, UInt32, UInt32) = (0, 0, 0, 0)
106-
var defHashVersion: UInt8 = 0
107-
var journalBackupType: UInt8 = 0
108-
var descSize: UInt16 = UInt16(MemoryLayout<GroupDescriptor>.size)
109-
var defaultMountOpts: UInt32 = 0
110-
var firstMetaBg: UInt32 = 0
111-
var mkfsTime: UInt32 = 0
112-
var journalBlocks:
102+
public var journalInum: UInt32 = 0
103+
public var journalDev: UInt32 = 0
104+
public var lastOrphan: UInt32 = 0
105+
public var hashSeed: (UInt32, UInt32, UInt32, UInt32) = (0, 0, 0, 0)
106+
public var defHashVersion: UInt8 = 0
107+
public var journalBackupType: UInt8 = 0
108+
public var descSize: UInt16 = UInt16(MemoryLayout<GroupDescriptor>.size)
109+
public var defaultMountOpts: UInt32 = 0
110+
public var firstMetaBg: UInt32 = 0
111+
public var mkfsTime: UInt32 = 0
112+
public var journalBlocks:
113113
(
114114
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
115115
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
@@ -119,29 +119,29 @@ extension EXT4 {
119119
0, 0, 0, 0, 0, 0, 0, 0,
120120
0
121121
)
122-
var blocksCountHigh: UInt32 = 0
123-
var rBlocksCountHigh: UInt32 = 0
124-
var freeBlocksCountHigh: UInt32 = 0
125-
var minExtraIsize: UInt16 = 0
126-
var wantExtraIsize: UInt16 = 0
127-
var flags: UInt32 = 0
128-
var raidStride: UInt16 = 0
129-
var mmpInterval: UInt16 = 0
130-
var mmpBlock: UInt64 = 0
131-
var raidStripeWidth: UInt32 = 0
132-
var logGroupsPerFlex: UInt8 = 0
133-
var checksumType: UInt8 = 0
134-
var reservedPad: UInt16 = 0
135-
var kbytesWritten: UInt64 = 0
136-
var snapshotInum: UInt32 = 0
137-
var snapshotID: UInt32 = 0
138-
var snapshotRBlocksCount: UInt64 = 0
139-
var snapshotList: UInt32 = 0
140-
var errorCount: UInt32 = 0
141-
var firstErrorTime: UInt32 = 0
142-
var firstErrorInode: UInt32 = 0
143-
var firstErrorBlock: UInt64 = 0
144-
var firstErrorFunc:
122+
public var blocksCountHigh: UInt32 = 0
123+
public var rBlocksCountHigh: UInt32 = 0
124+
public var freeBlocksCountHigh: UInt32 = 0
125+
public var minExtraIsize: UInt16 = 0
126+
public var wantExtraIsize: UInt16 = 0
127+
public var flags: UInt32 = 0
128+
public var raidStride: UInt16 = 0
129+
public var mmpInterval: UInt16 = 0
130+
public var mmpBlock: UInt64 = 0
131+
public var raidStripeWidth: UInt32 = 0
132+
public var logGroupsPerFlex: UInt8 = 0
133+
public var checksumType: UInt8 = 0
134+
public var reservedPad: UInt16 = 0
135+
public var kbytesWritten: UInt64 = 0
136+
public var snapshotInum: UInt32 = 0
137+
public var snapshotID: UInt32 = 0
138+
public var snapshotRBlocksCount: UInt64 = 0
139+
public var snapshotList: UInt32 = 0
140+
public var errorCount: UInt32 = 0
141+
public var firstErrorTime: UInt32 = 0
142+
public var firstErrorInode: UInt32 = 0
143+
public var firstErrorBlock: UInt64 = 0
144+
public var firstErrorFunc:
145145
(
146146
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
147147
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
@@ -153,12 +153,12 @@ extension EXT4 {
153153
0, 0, 0, 0, 0, 0, 0, 0,
154154
0, 0, 0, 0, 0, 0, 0, 0
155155
)
156-
var firstErrorLine: UInt32 = 0
157-
var lastErrorTime: UInt32 = 0
158-
var lastErrorInode: UInt32 = 0
159-
var lastErrorLine: UInt32 = 0
160-
var lastErrorBlock: UInt64 = 0
161-
var lastErrorFunc:
156+
public var firstErrorLine: UInt32 = 0
157+
public var lastErrorTime: UInt32 = 0
158+
public var lastErrorInode: UInt32 = 0
159+
public var lastErrorLine: UInt32 = 0
160+
public var lastErrorBlock: UInt64 = 0
161+
public var lastErrorFunc:
162162
(
163163
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
164164
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
@@ -170,7 +170,7 @@ extension EXT4 {
170170
0, 0, 0, 0, 0, 0, 0, 0,
171171
0, 0, 0, 0, 0, 0, 0, 0
172172
)
173-
var mountOpts:
173+
public var mountOpts:
174174
(
175175
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
176176
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
@@ -190,30 +190,30 @@ extension EXT4 {
190190
0, 0, 0, 0, 0, 0, 0, 0,
191191
0, 0, 0, 0, 0, 0, 0, 0
192192
)
193-
var userQuotaInum: UInt32 = 0
194-
var groupQuotaInum: UInt32 = 0
195-
var overheadBlocks: UInt32 = 0
196-
var backupBgs: (UInt32, UInt32) = (0, 0)
197-
var encryptAlgos: (UInt8, UInt8, UInt8, UInt8) = (0, 0, 0, 0)
198-
var encryptPwSalt:
193+
public var userQuotaInum: UInt32 = 0
194+
public var groupQuotaInum: UInt32 = 0
195+
public var overheadBlocks: UInt32 = 0
196+
public var backupBgs: (UInt32, UInt32) = (0, 0)
197+
public var encryptAlgos: (UInt8, UInt8, UInt8, UInt8) = (0, 0, 0, 0)
198+
public var encryptPwSalt:
199199
(
200200
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8,
201201
UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8, UInt8
202202
) = (
203203
0, 0, 0, 0, 0, 0, 0, 0,
204204
0, 0, 0, 0, 0, 0, 0, 0
205205
)
206-
var lpfInode: UInt32 = 0
207-
var projectQuotaInum: UInt32 = 0
208-
var checksumSeed: UInt32 = 0
209-
var wtimeHigh: UInt8 = 0
210-
var mtimeHigh: UInt8 = 0
211-
var mkfsTimeHigh: UInt8 = 0
212-
var lastcheckHigh: UInt8 = 0
213-
var firstErrorTimeHigh: UInt8 = 0
214-
var lastErrorTimeHigh: UInt8 = 0
215-
var pad: (UInt8, UInt8) = (0, 0)
216-
var reserved:
206+
public var lpfInode: UInt32 = 0
207+
public var projectQuotaInum: UInt32 = 0
208+
public var checksumSeed: UInt32 = 0
209+
public var wtimeHigh: UInt8 = 0
210+
public var mtimeHigh: UInt8 = 0
211+
public var mkfsTimeHigh: UInt8 = 0
212+
public var lastcheckHigh: UInt8 = 0
213+
public var firstErrorTimeHigh: UInt8 = 0
214+
public var lastErrorTimeHigh: UInt8 = 0
215+
public var pad: (UInt8, UInt8) = (0, 0)
216+
public var reserved:
217217
(
218218
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
219219
UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32, UInt32,
@@ -241,7 +241,7 @@ extension EXT4 {
241241
0, 0, 0, 0, 0, 0, 0, 0,
242242
0, 0, 0, 0, 0, 0, 0, 0
243243
)
244-
var checksum: UInt32 = 0
244+
public var checksum: UInt32 = 0
245245
}
246246

247247
struct CompatFeature {
@@ -436,6 +436,7 @@ extension EXT4 {
436436
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
437437
0, 0, 0, 0, 0, 0
438438
)
439+
439440
public static func Mode(_ mode: FileModeFlag, _ perm: UInt16) -> UInt16 {
440441
mode.rawValue | perm
441442
}
File renamed without changes.

0 commit comments

Comments
 (0)