Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Golang major minor device numbers
package main
import (
"flag"
"fmt"
"syscall"
// #include <sys/sysmacros.h>
"C"
)
var statfile = flag.String("s", "/dev/sda", "default file/device to stat")
// from: https://github.com/d3zd3z/gosure/blob/master/src/linuxdir/linuxdir.go
// Extract major and minor numbers.
// This is a strange linux-modern-libc non-macro version.
func Major(dev uint64) uint64 {
return uint64(C.gnu_dev_major((C.ulonglong)(dev)))
}
func Minor(dev uint64) uint64 {
return uint64(C.gnu_dev_minor((C.ulonglong)(dev)))
}
func main() {
flag.Parse()
// stat := syscall.Statfs_t{}
stat := syscall.Stat_t{}
err := syscall.Stat(*statfile, &stat)
if err != nil {
fmt.Println("Error", err)
}
fmt.Println(stat)
fmt.Println(Major(stat.Rdev), Minor(stat.Rdev))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.