Golang implementation of helper functions for the ioctl
calls in the Linux MTD ABI, kernel version v5.12
.
EXPERIMENTAL.
No warranties--use at your own risk!
Opens a file pointing to an MTD device (/dev/mtd0
) and obtains MTD info using MEMGETINFO
.
package main
import (
"fmt"
"os"
mtdabi "github.com/lhl2617/go-mtd-abi"
"golang.org/x/sys/unix"
)
const mtdPath = "/dev/mtd0"
func main() {
mtdFile, err := os.OpenFile(mtdPath, os.O_RDWR, 0644)
check(err)
// ▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
var mtdInfo unix.MtdInfo
err = mtdabi.MemGetInfo(mtdFile.Fd(), &mtdInfo)
check(err)
// ▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
fmt.Printf("%#v\n", mtdInfo)
check(mtdFile.Close())
}
// check panics if the error is non-nil.
func check(err error) {
if err != nil {
panic(err)
}
}
See more usage examples in the test file (mtdabi_test.go
).
Please run tests in the Vagrant box given. You may spin up the Vagrant box and run tests as such:
# Set up and boot up the Vagrant box
vagrant up
# SSH into the box
vagrant ssh
# cd into the repo
cd /vagrant
# Run tests
sudo go test ./...
- File bugs and/or feature requests in the GitHub repository
- Pull requests are welcome in the GitHub repository
- Buy me a Coffee ☕️ via PayPal