mirror of
https://github.com/dennwc/btrfs
synced 2025-03-11 06:48:27 +00:00
Add GetDevInfo exposing BTRFS_IOC_DEV_INFO (#3)
* Add GetDevInfo exposing BTRFS_IOC_DEV_INFO Co-authored-by: Marcus Cobden <leth@users.noreply.github.com>
This commit is contained in:
parent
90a0320aae
commit
b3db0b2ded
25
btrfs.go
25
btrfs.go
@ -2,12 +2,13 @@ package btrfs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/dennwc/ioctl"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/dennwc/ioctl"
|
||||
)
|
||||
|
||||
const SuperMagic = 0x9123683E
|
||||
@ -84,6 +85,28 @@ func (f *FS) Info() (out Info, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
type DevInfo struct {
|
||||
UUID UUID
|
||||
BytesUsed uint64
|
||||
TotalBytes uint64
|
||||
Path string
|
||||
}
|
||||
|
||||
func (f *FS) GetDevInfo(id uint64) (out DevInfo, err error) {
|
||||
var arg btrfs_ioctl_dev_info_args
|
||||
arg.devid = id
|
||||
|
||||
if err = ioctl.Do(f.f, _BTRFS_IOC_DEV_INFO, &arg); err != nil {
|
||||
return
|
||||
}
|
||||
out.UUID = arg.uuid
|
||||
out.BytesUsed = arg.bytes_used
|
||||
out.TotalBytes = arg.total_bytes
|
||||
out.Path = stringFromBytes(arg.path[:])
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type DevStats struct {
|
||||
WriteErrs uint64
|
||||
ReadErrs uint64
|
||||
|
11
utils.go
11
utils.go
@ -1,13 +1,15 @@
|
||||
package btrfs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"github.com/dennwc/btrfs/mtab"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/dennwc/btrfs/mtab"
|
||||
)
|
||||
|
||||
func isBtrfs(path string) (bool, error) {
|
||||
@ -95,3 +97,10 @@ func treeSearchRaw(mnt *os.File, key btrfs_ioctl_search_key) (out []searchResult
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func stringFromBytes(input []byte) string {
|
||||
if i := bytes.IndexByte(input, 0); i >= 0 {
|
||||
input = input[:i]
|
||||
}
|
||||
return string(input)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user