mobile logo

Golang: Determine a device major/minor number

posted on May 8, 2013 / IN golang / 0 Comments

While working on a monitoring agent for a service we will be introducing soon. I needed a way to determine the Major/Minor numbers for a device (e.g. /dev/mapper/datavg-srvlv).

It is actually much easier than I though. My first version as a gist.

But a much simpler solution exists, without using cgo.

stat := syscall.Stat_t{}
_ := syscall.Stat("/dev/sda", &stat)
fmt.Println("Major:",uint64(stat.Rdev/256), "Minor:",uint64(stat.Rdev%256))

By admin

No Comments

Please use the form to leave a comment

Leave a comment.