Skip to content

Instantly share code, notes, and snippets.

Created May 8, 2013 20:22
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/5543343 to your computer and use it in GitHub Desktop.
Save anonymous/5543343 to your computer and use it in GitHub Desktop.
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