Disks: show eMMC firmware revision as text when it is text
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5.1
parent
232163ff4c
commit
01aeb226ea
@@ -7,6 +7,7 @@ package storage
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
@@ -223,15 +224,21 @@ func mmcHealth(s Smart) Smart {
|
|||||||
s.SelfTestNote = "not a feature of eMMC or SD"
|
s.SelfTestNote = "not a feature of eMMC or SD"
|
||||||
s.Serial = strings.TrimSpace(readStrFile(dir + "serial"))
|
s.Serial = strings.TrimSpace(readStrFile(dir + "serial"))
|
||||||
s.Firmware = strings.TrimSpace(readStrFile(dir + "fwrev"))
|
s.Firmware = strings.TrimSpace(readStrFile(dir + "fwrev"))
|
||||||
|
// fwrev is eight raw bytes in hex; vendors usually put ASCII in them ("0001")
|
||||||
|
if b, err := hex.DecodeString(strings.TrimPrefix(s.Firmware, "0x")); err == nil {
|
||||||
|
if t := strings.TrimRight(string(b), "\x00 "); t != "" && strings.IndexFunc(t, func(r rune) bool { return r < 0x20 || r > 0x7e }) < 0 {
|
||||||
|
s.Firmware = t
|
||||||
|
}
|
||||||
|
}
|
||||||
s.Model = strings.TrimSpace(readStrFile(dir + "name"))
|
s.Model = strings.TrimSpace(readStrFile(dir + "name"))
|
||||||
hex := func(v string) int { n, _ := strconv.ParseInt(strings.TrimPrefix(v, "0x"), 16, 32); return int(n) }
|
hx := func(v string) int { n, _ := strconv.ParseInt(strings.TrimPrefix(v, "0x"), 16, 32); return int(n) }
|
||||||
life := strings.Fields(readStrFile(dir + "life_time"))
|
life := strings.Fields(readStrFile(dir + "life_time"))
|
||||||
eol := strings.TrimSpace(readStrFile(dir + "pre_eol_info"))
|
eol := strings.TrimSpace(readStrFile(dir + "pre_eol_info"))
|
||||||
if len(life) != 2 || eol == "" {
|
if len(life) != 2 || eol == "" {
|
||||||
s.Error = "This card reports no health data (SD cards don't; eMMC 5.0 and later does)."
|
s.Error = "This card reports no health data (SD cards don't; eMMC 5.0 and later does)."
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
m := &MMCHealth{LifeA: hex(life[0]), LifeB: hex(life[1]), PreEOL: hex(eol)}
|
m := &MMCHealth{LifeA: hx(life[0]), LifeB: hx(life[1]), PreEOL: hx(eol)}
|
||||||
s.MMC = m
|
s.MMC = m
|
||||||
ok := m.PreEOL <= 1 && m.LifeA < 10 && m.LifeB < 10
|
ok := m.PreEOL <= 1 && m.LifeA < 10 && m.LifeB < 10
|
||||||
s.Passed = &ok
|
s.Passed = &ok
|
||||||
|
|||||||
Reference in New Issue
Block a user