Skip to content

Commit

Permalink
Add sysfs spec
Browse files Browse the repository at this point in the history
  • Loading branch information
blp1526 committed Feb 21, 2019
1 parent 9317099 commit bbafc30
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
17 changes: 16 additions & 1 deletion _samples/blkinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@ package main

import (
"fmt"
"os"
"strings"

blkinfo "github.com/blp1526/go-blkinfo"
"gopkg.in/yaml.v2"
)

func main() {
bi, err := blkinfo.New("/dev/sda1")
args := os.Args
if len(args) != 2 {
desc := []string{
"USAGE:",
" go run _samples/blkinfo.go [device]",
"EXAMPLE:",
" go run _samples/blkinfo.go /dev/sda1",
}
fmt.Println(strings.Join(desc, "\n"))
os.Exit(0)
}

path := args[1]
bi, err := blkinfo.New(path)
if err != nil {
panic(err)
}
Expand Down
3 changes: 3 additions & 0 deletions blkinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ func mountpoint(mtab string, realPath string) (string, error) {
}

func majorMinor(realPath string) (string, error) {
// https://github.com/torvalds/linux/blob/d13937116f1e82bf508a6325111b322c30c85eb9/fs/block_dev.c#L1229-L1242
// /sys/block/dm-0/slaves/sda --> /sys/block/sda
// /sys/block/sda/holders/dm-0 --> /sys/block/dm-0
baseName := filepath.Base(realPath)
sysBlockPath := filepath.Join("/", "sys", "block")
fileInfos, err := ioutil.ReadDir(sysBlockPath)
Expand Down

0 comments on commit bbafc30

Please sign in to comment.