Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion pkg/block/block_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ func diskWWN(paths *linuxpath.Paths, disk string) string {
// diskPartitions takes the name of a disk (note: *not* the path of the disk,
// but just the name. In other words, "sda", not "/dev/sda" and "nvme0n1" not
// "/dev/nvme0n1") and returns a slice of pointers to Partition structs
// representing the partitions in that disk
// representing the partitions in that disk. If a disk has no partitions,
// it returns information on the disk instead, but the Partition UUID is set
// to the empty string (since there isn't one.)
func diskPartitions(
ctx context.Context,
paths *linuxpath.Paths,
Expand Down Expand Up @@ -256,6 +258,23 @@ func diskPartitions(
}
out = append(out, p)
}
// this is a disk with no partitions on it.
// Consider the filesystem on the disk to be a partition.
if len(out) == 0 {
size := partitionSizeBytes(paths, disk, "")
mp, pt, ro := partitionInfo(paths, disk)
du := diskPartUUID(paths, disk, "")
p := &Partition{
Name: disk,
SizeBytes: size,
MountPoint: mp,
Type: pt,
IsReadOnly: ro,
UUID: du,
}
out = append(out, p)

}
return out
}

Expand Down
22 changes: 22 additions & 0 deletions pkg/block/block_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,28 @@
}
}

func TestDiskPartitionless(t *testing.T) {
if _, ok := os.LookupEnv("GHW_TESTING_SKIP_BLOCK"); ok {
t.Skip("Skipping block tests.")
}
baseDir, _ := ioutil.TempDir("", "test")

Check failure on line 201 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: ioutil

Check failure on line 201 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest (1.22)

undefined: ioutil

Check failure on line 201 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-2204 (1.23)

undefined: ioutil

Check failure on line 201 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest (1.23)

undefined: ioutil

Check failure on line 201 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-2204 (1.21)

undefined: ioutil

Check failure on line 201 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-2204 (1.22)

undefined: ioutil

Check failure on line 201 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest (1.24)

undefined: ioutil
defer os.RemoveAll(baseDir)
ctx := context.New()

Check failure on line 203 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: context.New

Check failure on line 203 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest (1.22)

undefined: context.New

Check failure on line 203 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-2204 (1.23)

undefined: context.New

Check failure on line 203 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest (1.23)

undefined: context.New

Check failure on line 203 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-2204 (1.21)

undefined: context.New

Check failure on line 203 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-2204 (1.22)

undefined: context.New

Check failure on line 203 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest (1.24)

undefined: context.New
ctx.Chroot = baseDir
paths := linuxpath.New(ctx)

_ = os.MkdirAll(paths.SysBlock, 0755)
_ = os.MkdirAll(paths.RunUdevData, 0755)

// Emulate a disk with no partitions
_ = os.Mkdir(filepath.Join(paths.SysBlock, "sda"), 0755)
_ = ioutil.WriteFile(filepath.Join(paths.SysBlock, "sda", "dev"), []byte("259:0\n"), 0644)

Check failure on line 212 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / lint

undefined: ioutil (typecheck)

Check failure on line 212 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest (1.22)

undefined: ioutil

Check failure on line 212 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-2204 (1.23)

undefined: ioutil

Check failure on line 212 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest (1.23)

undefined: ioutil

Check failure on line 212 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-2204 (1.21)

undefined: ioutil

Check failure on line 212 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-2204 (1.22)

undefined: ioutil

Check failure on line 212 in pkg/block/block_linux_test.go

View workflow job for this annotation

GitHub Actions / ubuntu-latest (1.24)

undefined: ioutil
partitions := diskPartitions(ctx, paths, "sda")
if len(partitions) == 0 {
t.Fatalf("Got no partitions but expected sda")
}
}

func TestDiskPartLabel(t *testing.T) {
if _, ok := os.LookupEnv("GHW_TESTING_SKIP_BLOCK"); ok {
t.Skip("Skipping block tests.")
Expand Down
Loading