Skip to content

support disks with no partitions#452

Open
jaypipes wants to merge 5 commits into
mainfrom
pr-308
Open

support disks with no partitions#452
jaypipes wants to merge 5 commits into
mainfrom
pr-308

Conversation

@jaypipes

@jaypipes jaypipes commented Mar 9, 2026

Copy link
Copy Markdown
Owner

If a disk has no partitions, common use cases for looping over partitions on the disk array created by Block.New() don't work as expected.
Now, underlying partition functions detect partitionless disks and treat a full-disk filesystem as a partition.

The Partition UUID is set to the empty string (since there isn't one), so this behavior can be detected.

Authored-by: Tai Groot tai@taigrr.com

Closes Issue: #256

taigrr added 4 commits May 27, 2022 12:57
Signed-off-by: Tai Groot <tai@taigrr.com>
Signed-off-by: Tai Groot <tai@taigrr.com>
Signed-off-by: Tai Groot <tai@taigrr.com>
Signed-off-by: Tai Groot <tai@taigrr.com>
Signed-off-by: Jay Pipes <jaypipes@gmail.com>
@jaypipes

jaypipes commented Mar 9, 2026

Copy link
Copy Markdown
Owner Author

@Itxaka @ffromani I've rebased @taigrr 's original PR and fixed the unit test failures. Please let me know if you approve of this PR. Thanks in advance! :)

@Itxaka

Itxaka commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

I think that the original had the same issue and this is, anything checking the len(disk.Partition) to identify the number of partitions will misbehave or get the wrong results once they upgrade to the version with this change. This also means that you cannot diff between a disk without partitions and a disk with a single partition?

Anyway, its good to me, but it should be mentioned in the release notes probably if we dont want people updating it and suddenly having a different behavior :D

@jaypipes

jaypipes commented Mar 9, 2026

Copy link
Copy Markdown
Owner Author

I think that the original had the same issue and this is, anything checking the len(disk.Partition) to identify the number of partitions will misbehave or get the wrong results once they upgrade to the version with this change. This also means that you cannot diff between a disk without partitions and a disk with a single partition?

Anyway, its good to me, but it should be mentioned in the release notes probably if we dont want people updating it and suddenly having a different behavior :D

@Itxaka ack. Perhaps a better solution would be to have a new, separate field on Disk called Mountpoints and add the no-partition filesystem as a Mountpoint instead of a Partition? Thoughts?

@Itxaka

Itxaka commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

I think that the original had the same issue and this is, anything checking the len(disk.Partition) to identify the number of partitions will misbehave or get the wrong results once they upgrade to the version with this change. This also means that you cannot diff between a disk without partitions and a disk with a single partition?
Anyway, its good to me, but it should be mentioned in the release notes probably if we dont want people updating it and suddenly having a different behavior :D

@Itxaka ack. Perhaps a better solution would be to have a new, separate field on Disk called Mountpoints and add the no-partition filesystem as a Mountpoint instead of a Partition? Thoughts?

I think that depends a lot on what do you want to show or interpret a disk with no partitions I guess. After all a disk with no partitions should return no partitions, but how do you show if the disk itself does have a filesystem on it? Do we expand the Disk struct to show a mountpoint+filesystem itself and fill that up? That feels more correct, but its a waster of resources as Im sure about 98% of disks out there are partitioned instead of with a fs on top. Does it make sense to create a whole new thing to represent that state or do we take the shortcut to show it as partition zero and call it day + a note int he release notes?

No idea to be honest :D

@taigrr

taigrr commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

it's certainly an odd situation but it was one i ran into regularly at my old job :)

kiosks running embedded / yocto linux often had no partitions on their external media drives

probably equally common to have A / B boot partitions as it is to have no partitions at all when you consider legacy media.

the reason for my fork was to enable live metric gathering and reporting over our data plane since the default looping patterns didn't work on those machines or their USB updater sticks

personally my recommendation would be to err towards semantically correct over efficiency but of course you may disagree. this is go we're talking about, we're not hitting 0 alloc metrics or anything as-is, an extra struct (or even struct pointer if you want) with an omitzero on it probably makes little difference

@taigrr taigrr mentioned this pull request Mar 17, 2026
@Itxaka

Itxaka commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Im ok any case, Ill check my code to see if I do the len(disk.Partitions) trick to check if the disk is empty before updating the the next ghw version LOL :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants