Match the byte order in the EXT4 reader to how the EXT4 formatter writes data (#664)

Matches the byte order in the EXT4 reader to how the EXT4 formatter
writes data.
This commit is contained in:
Dmitry Kovba authored and GitHub committed 2026-04-09 13:55:27 -04:00
1 parent 8451a8427d
commit 74ac944790
4 files changed
+10 -10

No files matched your search

@@ -76,16 +76,16 @@ extension EXT4.XAttrEntry {
nameLength = bytes[0]
nameIndex = bytes[1]
let rawValue = Array(bytes[2...3])
valueOffset = UInt16(littleEndian: rawValue.withUnsafeBytes { $0.load(as: UInt16.self) })
valueOffset = rawValue.withUnsafeBytes { $0.loadLittleEndian(as: UInt16.self) }
let rawValueInum = Array(bytes[4...7])
valueInum = UInt32(littleEndian: rawValueInum.withUnsafeBytes { $0.load(as: UInt32.self) })
valueInum = rawValueInum.withUnsafeBytes { $0.loadLittleEndian(as: UInt32.self) }
let rawSize = Array(bytes[8...11])
valueSize = UInt32(littleEndian: rawSize.withUnsafeBytes { $0.load(as: UInt32.self) })
valueSize = rawSize.withUnsafeBytes { $0.loadLittleEndian(as: UInt32.self) }
let rawHash = Array(bytes[12...])
hash = UInt32(littleEndian: rawHash.withUnsafeBytes { $0.load(as: UInt32.self) })
hash = rawHash.withUnsafeBytes { $0.loadLittleEndian(as: UInt32.self) }
}
}
@@ -215,7 +215,7 @@ extension EXT4 {
// When depth is 0 the extent header is followed by extent leaves
for _ in 0..<header.entries {
let leaf = inodeBlock.subdata(in: offset..<offset + extentLeafSize).withUnsafeBytes {
$0.load(as: ExtentLeaf.self)
$0.loadLittleEndian(as: ExtentLeaf.self)
}
extents.append((leaf.startLow, leaf.startLow + UInt32(leaf.length)))
offset += extentLeafSize
@@ -224,7 +224,7 @@ extension EXT4 {
// When depth is 1 the extent header is followed by extent indices which point to leaves
for _ in 0..<header.entries {
let indexNode = inodeBlock.subdata(in: offset..<offset + extentIndexSize).withUnsafeBytes {
$0.load(as: ExtentIndex.self)
$0.loadLittleEndian(as: ExtentIndex.self)
}
try self.seek(block: indexNode.leafLow)
guard let block = try self.handle.read(upToCount: Int(self.blockSize)) else {
@@ -62,7 +62,7 @@ extension EXT4 {
var i = 0
while i + 3 < value.count {
let s = value[i..<i + 4]
let v = UInt32(littleEndian: s.withUnsafeBytes { $0.load(as: UInt32.self) })
let v = s.withUnsafeBytes { $0.loadLittleEndian(as: UInt32.self) }
hash = (hash << 16) ^ (hash >> 16) ^ v
i += 4
}
@@ -72,7 +72,7 @@ extension EXT4 {
for (i, byte) in value[last...].enumerated() {
buff[i] = byte
}
let v = UInt32(littleEndian: buff.withUnsafeBytes { $0.load(as: UInt32.self) })
let v = buff.withUnsafeBytes { $0.loadLittleEndian(as: UInt32.self) }
hash = (hash << 16) ^ (hash >> 16) ^ v
}
return hash
@@ -169,7 +169,7 @@ extension EXT4.EXT4Reader {
}
public static func readInlineExtendedAttributes(from buffer: [UInt8]) throws -> [EXT4.ExtendedAttribute] {
let header = UInt32(littleEndian: buffer[0..<4].withUnsafeBytes { $0.load(as: UInt32.self) })
let header = buffer[0..<4].withUnsafeBytes { $0.loadLittleEndian(as: UInt32.self) }
if header != EXT4.XAttrHeaderMagic {
throw EXT4.FileXattrsState.Error.missingXAttrHeader
}
@@ -182,7 +182,7 @@ extension EXT4.EXT4Reader {
}
public static func readBlockExtendedAttributes(from buffer: [UInt8]) throws -> [EXT4.ExtendedAttribute] {
let header = UInt32(littleEndian: buffer[0..<4].withUnsafeBytes { $0.load(as: UInt32.self) })
let header = buffer[0..<4].withUnsafeBytes { $0.loadLittleEndian(as: UInt32.self) }
if header != EXT4.XAttrHeaderMagic {
throw EXT4.FileXattrsState.Error.missingXAttrHeader
}