treewide: port everything to blockdev
This gets rid of most ad-hoc block device code, using blockdev for
everything. It also gets rid of diskfs for everything but tests. This
enables Metropolis to be installed on non-512-byte block sizes.
Change-Id: I644b5b68bb7bed8106585df3179674789031687a
Reviewed-on: https://review.monogon.dev/c/monogon/+/1873
Tested-by: Jenkins CI
Reviewed-by: Serge Bazanski <serge@monogon.tech>
diff --git a/metropolis/pkg/gpt/linux_test.go b/metropolis/pkg/gpt/linux_test.go
index 19ac519..7f7f6de 100644
--- a/metropolis/pkg/gpt/linux_test.go
+++ b/metropolis/pkg/gpt/linux_test.go
@@ -5,7 +5,8 @@
"testing"
"github.com/google/uuid"
- "golang.org/x/sys/unix"
+
+ "source.monogon.dev/metropolis/pkg/blockdev"
)
var testUUID = uuid.MustParse("85c0b60f-caf9-40dd-86fa-f8797e26238d")
@@ -14,15 +15,13 @@
if os.Getenv("IN_KTEST") != "true" {
t.Skip("Not in ktest")
}
- ram0, err := os.OpenFile("/dev/ram0", os.O_RDWR, 0)
+ ram0, err := blockdev.Open("/dev/ram0")
if err != nil {
panic(err)
}
g := Table{
- ID: uuid.NewSHA1(testUUID, []byte("test")),
- BlockSize: 512,
- BlockCount: 2048,
- BootCode: []byte("just some test code"),
+ ID: uuid.NewSHA1(testUUID, []byte("test")),
+ BootCode: []byte("just some test code"),
Partitions: []*Partition{
nil,
// This emoji is very complex and exercises UTF16 surrogate encoding
@@ -31,13 +30,13 @@
nil,
{Name: "Test2", FirstBlock: 20, LastBlock: 49, Type: PartitionTypeEFISystem, ID: uuid.NewSHA1(testUUID, []byte("test2")), Attributes: 0},
},
+ b: ram0,
}
- if err := Write(ram0, &g); err != nil {
+ if err := g.Write(); err != nil {
t.Fatalf("Failed to write GPT: %v", err)
}
-
- if err := unix.IoctlSetInt(int(ram0.Fd()), unix.BLKRRPART, 0); err != nil {
- t.Fatalf("Failed to reread partition table: %v", err)
+ if err := ram0.RefreshPartitionTable(); err != nil {
+ t.Fatalf("Failed to refresh partition table: %v", err)
}
if _, err := os.Stat("/sys/block/ram0/ram0p2"); err != nil {
t.Errorf("Expected ram0p2 to exist, got %v", err)