Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Golang major minor device numbers
package main
import (
// #include <sys/sysmacros.h>
var statfile = flag.String("s", "/dev/sda", "default file/device to stat")
// from:
// 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() {
// stat := syscall.Statfs_t{}
stat := syscall.Stat_t{}
err := syscall.Stat(*statfile, &stat)
if err != nil {
fmt.Println("Error", err)
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.