Skip to content

lhl2617/go-mtd-abi

Repository files navigation

Go MTD ABI

Godoc License: MIT Linux

Golang implementation of helper functions for the ioctl calls in the Linux MTD ABI, kernel version v5.12.

Status

EXPERIMENTAL.

No warranties--use at your own risk!

Usage

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

Development Guide

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 ./...

Contributing

About

Go helper functions for the Linux MTD ABI

Resources

License

Stars

Watchers

Forks

Packages

No packages published