feat(storage): 新增只读 SMART 辅助服务与寿命通电详情
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
import Foundation
|
||||
|
||||
nonisolated enum DiskHealthReport {
|
||||
static func parse(_ data: Data) -> DiskHealthMetrics? {
|
||||
guard let root = try? PropertyListSerialization.propertyList(from: data, format: nil) as? [String: Any],
|
||||
let smart = root["SMARTDeviceSpecificKeysMayVaryNotGuaranteed"] as? [String: Any] else { return nil }
|
||||
// Multiple physical stores cannot be represented as one device's lifetime.
|
||||
if let stores = root["APFSPhysicalStores"] as? [Any], stores.count != 1 { return nil }
|
||||
func integer(_ key: String) -> UInt64? {
|
||||
guard let value = smart[key] as? NSNumber,
|
||||
CFGetTypeID(value) != CFBooleanGetTypeID() else { return nil }
|
||||
return UInt64(value.stringValue)
|
||||
}
|
||||
let used = integer("PERCENTAGE_USED").flatMap { $0 <= 255 ? $0 : nil }
|
||||
let remaining = used.map { Double(100 - min(100, $0)) / 100 }
|
||||
let hours = integer("POWER_ON_HOURS_1") == 0 ? integer("POWER_ON_HOURS_0") : nil
|
||||
guard remaining != nil || hours != nil else { return nil }
|
||||
return DiskHealthMetrics(remainingLife: remaining, powerOnHours: hours)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user