登录
首页 >  Golang >  Go问答

Golang中执行Ioctl调用的转换方式

来源:stackoverflow

时间:2024-02-07 12:48:16 413浏览 收藏

最近发现不少小伙伴都对Golang很感兴趣,所以今天继续给大家介绍Golang相关的知识,本文《Golang中执行Ioctl调用的转换方式》主要内容涉及到等等知识点,希望能帮到你!当然如果阅读本文时存在不同想法,可以在评论中表达,但是请勿使用过激的措辞~

问题内容

我正在尝试转换,或者至少理解这个 ioctl 调用:

#define NVME_URING_CMD_IO   _IOWR('N', 0x80, struct nvme_uring_cmd)

golang 中有 _iowr 的等效项吗?也许与 unix 包一起使用?


正确答案


好的,我成功转换了它,感谢评论中的帮助:

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)
}

今天关于《Golang中执行Ioctl调用的转换方式》的内容就介绍到这里了,是不是学起来一目了然!想要了解更多关于的内容请关注golang学习网公众号!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>