protobuf file for block devices
This commit is contained in:
parent
bd5b16d875
commit
25c604aeee
|
@ -3,4 +3,5 @@ go.mod
|
||||||
go.sum
|
go.sum
|
||||||
fixup
|
fixup
|
||||||
*.so
|
*.so
|
||||||
|
*pb.go
|
||||||
/files/*
|
/files/*
|
||||||
|
|
10
Makefile
10
Makefile
|
@ -2,7 +2,7 @@ VERSION = $(shell git describe --tags)
|
||||||
GUIVERSION = $(shell git describe --tags)
|
GUIVERSION = $(shell git describe --tags)
|
||||||
BUILDTIME = $(shell date +%Y.%m.%d)
|
BUILDTIME = $(shell date +%Y.%m.%d)
|
||||||
|
|
||||||
all: verbose
|
all: block.pb.go verbose
|
||||||
# -fixup --gui-check-plugin ../../../toolkits/gocui/gocui.so
|
# -fixup --gui-check-plugin ../../../toolkits/gocui/gocui.so
|
||||||
fixup --gui gocui --gui-verbose --gui-file ../../toolkits/gocui/gocui.so
|
fixup --gui gocui --gui-verbose --gui-file ../../toolkits/gocui/gocui.so
|
||||||
|
|
||||||
|
@ -32,9 +32,17 @@ goimports:
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f go.*
|
rm -f go.*
|
||||||
|
rm -f *.pb.go
|
||||||
|
go-mod-clean purge
|
||||||
|
|
||||||
gpl:
|
gpl:
|
||||||
wit-test --witcom
|
wit-test --witcom
|
||||||
|
|
||||||
check-git-clean:
|
check-git-clean:
|
||||||
@git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1)
|
@git diff-index --quiet HEAD -- || (echo "Git repository is dirty, please commit your changes first"; exit 1)
|
||||||
|
|
||||||
|
block.pb.go: block.proto
|
||||||
|
autogenpb --proto block.proto
|
||||||
|
|
||||||
|
commit:
|
||||||
|
FORGE_URL="https://forge.grid.wit.com/" forge commit --all
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package main;
|
||||||
|
|
||||||
|
message Block {
|
||||||
|
string name = 1; // `autogenpb:sort` `autogenpb:unique`
|
||||||
|
uint32 major = 2;
|
||||||
|
uint32 minor = 3;
|
||||||
|
uint64 size_bytes = 4;
|
||||||
|
bool removable = 5;
|
||||||
|
bool read_only = 6;
|
||||||
|
string type = 7; // e.g., "disk", "part", "rom", "loop"
|
||||||
|
repeated string mountpoints = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Blocks { // `autogenpb:marshal` `autogenpb:mutex`
|
||||||
|
string uuid = 1; // `autogenpb:uuid:abe10848-cf2b-4440-b5a8-0aaa2ce50aad`
|
||||||
|
string version = 2; // `autogenpb:version:v0.0.1`
|
||||||
|
repeated Block Blocks = 3; // THIS MUST BE Block and then Blocks
|
||||||
|
}
|
11
doDrives.go
11
doDrives.go
|
@ -17,7 +17,11 @@ func doDrives() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range parts {
|
for _, p := range parts {
|
||||||
log.Printf("Device: /dev/%s\tSize: %d KiB\n", p.Name, p.Blocks)
|
log.Printf("RAW Device: /dev/%s\tSize: %d KiB\n", p.Name, p.Blocks)
|
||||||
|
devname := "/dev/" + p.Name
|
||||||
|
if blkpb := me.pb.FindByName(devname); blkpb != nil {
|
||||||
|
blkpb.SizeBytes = uint64(p.Blocks) * 1024
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
blockDir := "/sys/block"
|
blockDir := "/sys/block"
|
||||||
|
@ -44,11 +48,12 @@ func doDrives() {
|
||||||
used := false
|
used := false
|
||||||
for _, part := range partitions {
|
for _, part := range partitions {
|
||||||
partName := filepath.Base(part)
|
partName := filepath.Base(part)
|
||||||
|
partDev := "/dev/" + partName
|
||||||
if partName == dev {
|
if partName == dev {
|
||||||
|
log.Printf(" SKIP MAIN Partition: %s\n", partDev)
|
||||||
continue // skip the main device
|
continue // skip the main device
|
||||||
}
|
}
|
||||||
hasPartition = true
|
hasPartition = true
|
||||||
partDev := "/dev/" + partName
|
|
||||||
isMounted := mounts[partDev]
|
isMounted := mounts[partDev]
|
||||||
log.Printf(" Partition: %s [%v]\n", partDev, isMounted)
|
log.Printf(" Partition: %s [%v]\n", partDev, isMounted)
|
||||||
if isMounted {
|
if isMounted {
|
||||||
|
@ -61,7 +66,7 @@ func doDrives() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !used {
|
if !used {
|
||||||
log.Println(" → Drive appears to be unused.")
|
log.Println(" * Drive appears to be unused.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
58
doGui.go
58
doGui.go
|
@ -6,6 +6,7 @@ package main
|
||||||
// An app to submit patches for the 30 GO GUI repos
|
// An app to submit patches for the 30 GO GUI repos
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -13,16 +14,45 @@ import (
|
||||||
"go.wit.com/gui"
|
"go.wit.com/gui"
|
||||||
"go.wit.com/lib/gadgets"
|
"go.wit.com/lib/gadgets"
|
||||||
"go.wit.com/lib/gui/shell"
|
"go.wit.com/lib/gui/shell"
|
||||||
|
"go.wit.com/lib/protobuf/virtpb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func debug() {
|
func debug() {
|
||||||
for {
|
for {
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
log.Info("TODO: use this?")
|
log.Info("TODO: use this debug loop for something?")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// adds a new drive to the dropdown menu and protobuf
|
||||||
|
func addDrive(devname string, displayDesc string) *Block {
|
||||||
|
if blkpb := me.pb.FindByName(devname); blkpb != nil {
|
||||||
|
return blkpb
|
||||||
|
}
|
||||||
|
|
||||||
|
s := log.Sprintf("%-12s %-8s", devname, displayDesc)
|
||||||
|
log.Info(s)
|
||||||
|
me.dd.AddText(s)
|
||||||
|
|
||||||
|
blkpb := me.pb.InsertByName(devname)
|
||||||
|
return blkpb
|
||||||
|
}
|
||||||
|
|
||||||
|
func switchDrive(blk *Block) {
|
||||||
|
me.currentDev = blk
|
||||||
|
me.parted.SetText("Partition " + blk.Name)
|
||||||
|
|
||||||
|
log.Info("check if", me.currentDev.Name, "is in use")
|
||||||
|
result, err := shell.RunVerbose([]string{"parted", me.currentDev.Name, "print"})
|
||||||
|
log.Info("result =", result.Stdout, "err =", err)
|
||||||
|
out := strings.Join(result.Stdout, "\n")
|
||||||
|
if err != nil {
|
||||||
|
out += fmt.Sprintf("err = %v", err)
|
||||||
|
}
|
||||||
|
me.driveInfoBox.SetText(out)
|
||||||
|
}
|
||||||
|
|
||||||
func doGui() {
|
func doGui() {
|
||||||
me.myGui = gui.New()
|
me.myGui = gui.New()
|
||||||
me.myGui.InitEmbed(resources)
|
me.myGui.InitEmbed(resources)
|
||||||
|
@ -51,19 +81,21 @@ func drawWindow(win *gadgets.GenericWindow) {
|
||||||
if len(fields) < 1 {
|
if len(fields) < 1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
me.currentDev = fields[0]
|
if blkpb := me.pb.FindByName(fields[0]); blkpb != nil {
|
||||||
me.parted.SetText("Partition " + me.currentDev)
|
switchDrive(blkpb)
|
||||||
|
} else {
|
||||||
|
log.Info("couldn't find in protobuf:", fields)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
grid.NextRow()
|
grid.NextRow()
|
||||||
|
|
||||||
// a button to format or blank a drive
|
// a button to format or blank a drive
|
||||||
me.parted = grid.NewButton("select drive", func() {
|
me.parted = grid.NewButton("select drive", func() {
|
||||||
if me.currentDev == "" {
|
if me.currentDev == nil {
|
||||||
log.Info("You must select a drive first")
|
log.Info("You must select a drive first")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Info("check if", me.currentDev, "is in use")
|
log.Info("TODO: figure out if the drive is in use")
|
||||||
shell.RunVerbose([]string{"parted", me.currentDev, "print"})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
grid.NextRow()
|
grid.NextRow()
|
||||||
|
@ -72,6 +104,16 @@ func drawWindow(win *gadgets.GenericWindow) {
|
||||||
doDrives()
|
doDrives()
|
||||||
})
|
})
|
||||||
|
|
||||||
doDrives2()
|
grid.NewButton("show blkpb", func() {
|
||||||
|
for blk := range me.pb.IterAll() {
|
||||||
|
log.Printf("found %-12s %s\n", blk.Name, virtpb.HumanFormatBytes(int64(blk.SizeBytes)))
|
||||||
|
}
|
||||||
|
})
|
||||||
|
grid.NextRow()
|
||||||
|
|
||||||
|
grid = win.Middle.RawGrid()
|
||||||
|
me.driveInfoBox = grid.NewLabel("<drive info>")
|
||||||
|
|
||||||
|
doDrives2()
|
||||||
|
doDrives()
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,9 +43,7 @@ func doDrives2() {
|
||||||
for _, info := range devs {
|
for _, info := range devs {
|
||||||
devPath := "/dev/" + info.Name
|
devPath := "/dev/" + info.Name
|
||||||
if info.IsRaw {
|
if info.IsRaw {
|
||||||
s := log.Sprintf("%-12s -> %-8s (raw)", devPath, info.Type)
|
addDrive(devPath, log.Sprintf("-> %-8s (raw)", info.Type))
|
||||||
log.Info(s)
|
|
||||||
me.dd.AddText(s)
|
|
||||||
} else {
|
} else {
|
||||||
if info.Parent != "" {
|
if info.Parent != "" {
|
||||||
log.Printf("%-12s -> partition of /dev/%s\n", devPath, info.Parent)
|
log.Printf("%-12s -> partition of /dev/%s\n", devPath, info.Parent)
|
||||||
|
|
2
main.go
2
main.go
|
@ -49,6 +49,8 @@ func main() {
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
me.pb = NewBlocks()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if argv.Drives != nil {
|
if argv.Drives != nil {
|
||||||
doDrives()
|
doDrives()
|
||||||
|
|
12
structs.go
12
structs.go
|
@ -12,9 +12,11 @@ var me *autoType
|
||||||
|
|
||||||
// this app's variables
|
// this app's variables
|
||||||
type autoType struct {
|
type autoType struct {
|
||||||
pp *arg.Parser // go-arg preprocessor
|
pp *arg.Parser // go-arg preprocessor
|
||||||
myGui *gui.Node // the gui toolkit handle
|
myGui *gui.Node // the gui toolkit handle
|
||||||
dd *gui.Node // the drives dropdown list
|
dd *gui.Node // the drives dropdown list
|
||||||
parted *gui.Node // the current drive to run parted on
|
parted *gui.Node // the current drive to run parted on
|
||||||
currentDev string // the current dev entry to work on
|
currentDev *Block // the current dev entry to work on
|
||||||
|
pb *Blocks // the block dev protobuf
|
||||||
|
driveInfoBox *gui.Node // displays the drive info
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,7 +44,9 @@ func listenForBlockEvents() {
|
||||||
msg := parseUevent(buf[:n])
|
msg := parseUevent(buf[:n])
|
||||||
if msg["SUBSYSTEM"] == "block" && msg["ACTION"] == "add" {
|
if msg["SUBSYSTEM"] == "block" && msg["ACTION"] == "add" {
|
||||||
log.Printf("New block device added: %s\n", msg["DEVNAME"])
|
log.Printf("New block device added: %s\n", msg["DEVNAME"])
|
||||||
me.dd.AddText("/dev/" + msg["DEVNAME"] + " new")
|
devname := "/dev/" + msg["DEVNAME"]
|
||||||
|
me.dd.AddText(devname + " new")
|
||||||
|
me.pb.InsertByName(devname)
|
||||||
}
|
}
|
||||||
log.Printf("New syscall.NETLINK_KOBJECT_UEVENT: %v\n", msg)
|
log.Printf("New syscall.NETLINK_KOBJECT_UEVENT: %v\n", msg)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue