package main
import (
"golang.org/x/sys/unix"
"log"
"os"
"syscall"
"unsafe"
)
func FatalError(err error) {
if err != nil {
log.Fatal(err)
}
}
func main() {
var hd unix.HDDriveID
fd, err := unix.Open(os.Args[1], os.O_RDONLY, 0660)
FatalError(err)
_, _, ErrOn := syscall.Syscall(syscall.SYS_IOCTL, uintptr(fd), unix.HDIO_GET_IDENTITY, uintptr(unsafe.Pointer(&hd)))
if unix.ErrnoName(ErrOn) != "" {
log.Fatal("Error: ", ErrOn)
}
var sn []byte
var model []byte
for _, char := range hd.Serial_no {
sn = append(sn, char)
}
for _, char := range hd.Model {
model = append(model, char)
}
log.Println(string(sn))
log.Println(string(model))
}
有疑问加站长微信联系(非本文作者)