获取未挂载卷的 BLKID(块标识符)在 Go 语言中的方法。

huangapple go评论75阅读模式
英文:

Get BLKID of an unmounted volume in go

问题

我正在尝试找出是否有一种方法可以通过一些原生的Golang库获取未挂载卷的blkid详细信息。我特别关注卷的fstype。

英文:

I am trying to find out if there is a way to get details of blkid of an unmounted volume, through some native golang library. I am particularly interested in fstype of the volume

答案1

得分: 4

我不认为有一个原生的库——我找不到一个。

我认为你有三个选择:

  1. 使用blkid实用程序进行外壳调用。
  2. 编写一个cgo接口来调用libblkid
  3. 浏览libblkid的源代码,并在Go中重新实现它。

第一种方法非常简单。第二种方法较为困难。第三种方法可能很容易,具体取决于你想要使用blkid的哪个功能。使用strace blkid args命令并观察它执行多少系统调用来获取你想要的结果,以此来了解。

我可能会选择第一种方法,因为我认为blkid是Linux的核心工具之一,你应该能够保证它的存在。

英文:

I don't think there is a native library - I couldn't find one.

I think you've got 3 choices

  1. Shell out to the blkid utility
  2. Write a cgo interface to libblkid
  3. Trawl through the libblkid source and re-implement it in go

1 is very easy. 2 is harder. 3 might be easy depending on exactly which feature of blkid you want. strace blkid args and seem how many system calls it does to get the result you want to get an idea.

I'd probably go with 1. as blkid is one of the core linux tools which you are guaranteed to have I think.

huangapple
  • 本文由 发表于 2015年3月29日 09:46:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/29324739.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定