mirror of
https://github.com/dennwc/btrfs
synced 2025-04-07 01:32:10 +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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dennwc/ioctl"
|
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/dennwc/ioctl"
|
||||||
)
|
)
|
||||||
|
|
||||||
const SuperMagic = 0x9123683E
|
const SuperMagic = 0x9123683E
|
||||||
@ -84,6 +85,28 @@ func (f *FS) Info() (out Info, err error) {
|
|||||||
return
|
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 {
|
type DevStats struct {
|
||||||
WriteErrs uint64
|
WriteErrs uint64
|
||||||
ReadErrs uint64
|
ReadErrs uint64
|
||||||
|
11
utils.go
11
utils.go
@ -1,13 +1,15 @@
|
|||||||
package btrfs
|
package btrfs
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dennwc/btrfs/mtab"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/dennwc/btrfs/mtab"
|
||||||
)
|
)
|
||||||
|
|
||||||
func isBtrfs(path string) (bool, error) {
|
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
|
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