Skip to content

Commit

Permalink
fix: correctly build paths for mmcblk devices
Browse files Browse the repository at this point in the history
Ex: `mmcblk0p1`.

Signed-off-by: Andrey Smirnov <[email protected]>
  • Loading branch information
smira authored and talos-bot committed Nov 20, 2020
1 parent 8076344 commit 2a1baad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions blockdevice/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func PartNo(partname string) (partno string, err error) {
switch p := partname; {
case strings.HasPrefix(p, "nvme"):
fallthrough
case strings.HasPrefix(p, "mmcblk"):
fallthrough
case strings.HasPrefix(p, "loop"):
idx := strings.LastIndex(partname, "p")

Expand Down Expand Up @@ -48,6 +50,8 @@ func DevnameFromPartname(partname string) (devname string, err error) {
switch p := partname; {
case strings.HasPrefix(p, "nvme"):
fallthrough
case strings.HasPrefix(p, "mmcblk"):
fallthrough
case strings.HasPrefix(p, "loop"):
return strings.TrimSuffix(p, "p"+partno), nil
case strings.HasPrefix(p, "sd"):
Expand All @@ -70,6 +74,8 @@ func PartName(d string, n int) string {
switch p := partname; {
case strings.HasPrefix(p, "nvme"):
fallthrough
case strings.HasPrefix(p, "mmcblk"):
fallthrough
case strings.HasPrefix(p, "loop"):
partname = fmt.Sprintf("%sp%d", p, n)
default:
Expand Down
15 changes: 15 additions & 0 deletions blockdevice/util/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ func Test_PartNo(t *testing.T) {
},
want: "4",
},
{
name: "mmcblk0p3",
args: args{
devname: "mmcblk0p3",
},
want: "3",
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -191,6 +198,14 @@ func Test_DevnameFromPartname(t *testing.T) {
},
want: "loop4",
},
{
name: "mmcblk0p3",
args: args{
devname: "mmcblk0p3",
partno: "3",
},
want: "mmcblk0",
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 2a1baad

Please sign in to comment.