Skip to content

Commit

Permalink
Add exit1
Browse files Browse the repository at this point in the history
  • Loading branch information
blp1526 committed Jan 29, 2019
1 parent 815e37b commit 5f84a14
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 19 additions & 1 deletion _samples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,38 @@ package main

import (
"fmt"
"os"

"github.com/blp1526/go-udevinfo/blk"
)

func exit1(err error) {
fmt.Fprintf(os.Stderr, "ERR: %v\n", err)
os.Exit(1)
}

func main() {
mountpoint := "/"
fmt.Printf("## mountpoint\n%s\n\n", mountpoint)

devPath, _ := blk.GetDevPath("/")
devPath, err := blk.GetDevPath(mountpoint)
if err != nil {
exit1(err)
}

fmt.Printf("## devPath\n%s\n\n", devPath)

majorMinor, _ := blk.GetMajorMinor(devPath)
if err != nil {
exit1(err)
}

fmt.Printf("## majorMinor\n%s\n\n", majorMinor)

udevData, _ := blk.GetUdevData(majorMinor)
if err != nil {
exit1(err)
}

fmt.Printf("## udevData\n%s\n", udevData)
}
7 changes: 6 additions & 1 deletion blk/blk.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ func GetDevPath(mountpoint string) (string, error) {
for _, line := range lines {
fields := strings.Fields(line)
if fields[1] == mountpoint {
return fields[0], nil
devPath, err := filepath.EvalSymlinks(fields[0])
if err != nil {
return "", err
}

return devPath, nil
}
}

Expand Down

0 comments on commit 5f84a14

Please sign in to comment.