英文:
Convert `ioctl` call in golang
问题
我正在尝试转换,或者至少理解这个 ioctl
调用:
#define NVME_URING_CMD_IO _IOWR('N', 0x80, struct nvme_uring_cmd)
在 Golang 中是否有 _IOWR
的等效方式?也许可以使用 unix
包吗?
英文:
I'm trying to convert, or at least understand this ioctl
call:
#define NVME_URING_CMD_IO _IOWR('N', 0x80, struct nvme_uring_cmd)
Is there an equivalent of _IOWR
in golang? maybe with the unix
package?
答案1
得分: 0
好的,我已经成功将其转换了,感谢评论中的帮助:
const (
IocNrBits = 8
IocTypeBits = 8
IocSizeBits = 14
IocNrShift = 0
IocRead uintptr = 2
IocWrite uintptr = 2
)
const (
IocTypeShift = IocNrShift + IocNrBits
IocSizeShift = IocTypeShift + IocTypeBits
IocDirshift = IocSizeShift + IocSizeBits
)
func IOC(dir, t, nr, size uintptr) uintptr {
return (dir << IocDirshift) |
(t << IocTypeShift) |
(nr << IocNrShift) |
(size << IocSizeShift)
}
func IOWR(t, nr, size uintptr) uintptr {
return IOC(IocRead|IocWrite, t, nr, size)
}
func NVME_URING_CMD_IO() uintptr {
return IOWR('N', 0x80, 32)
}
英文:
Ok, I managed to convert it, thanks to help in comments:
const (
IocNrBits = 8
IocTypeBits = 8
IocSizeBits = 14
IocNrShift = 0
IocRead uintptr = 2
IocWrite uintptr = 2
)
const (
IocTypeShift = IocNrShift + IocNrBits
IocSizeShift = IocTypeShift + IocTypeBits
IocDirshift = IocSizeShift + IocSizeBits
)
func IOC(dir, t, nr, size uintptr) uintptr {
return (dir << IocDirshift) |
(t << IocTypeShift) |
(nr << IocNrShift) |
(size << IocSizeShift)
}
func IOWR(t, nr, size uintptr) uintptr {
return IOC(IocRead|IocWrite, t, nr, size)
}
func NVME_URING_CMD_IO() uintptr {
return IOWR('N', 0x80, 32)
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论