-
-
Save jim3ma/3d0ec24c2ecc00db62612596f8ccd6a4 to your computer and use it in GitHub Desktop.
Golang major minor device numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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