partition: add GPT and MBR selection policies - #423
Merged
deitch merged 1 commit intoAug 4, 2026
Conversation
Make GPTWithMBR the default while preserving the previous GPT-first behavior through GPTIgnoreMBR. Prefer conventional MBR tables over readable residual GPT metadata, while continuing to select GPT for protective and hybrid MBR layouts. Signed-off-by: wow20220809-lab <wow080924@gmail.com>
deitch
approved these changes
Aug 4, 2026
deitch
left a comment
Collaborator
There was a problem hiding this comment.
This is great, thank you.
Collaborator
|
Thanks, merged in. Who are you @wow20220809-lab ; and how do you use it? |
Contributor
Author
|
Thanks for merging it! I'm a cloud security engineer. Detecting security risks in cloud disks is an important part of our work, and go-diskfs helps us identify disk layouts and mount those disks for comprehensive security scanning. Thank you very much for creating and maintaining this project! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
partition.Readcurrently returns GPT as soon as GPT can be read. This canselect readable residual GPT metadata even when the disk contains a valid
conventional MBR.
This change introduces two explicit selection policies:
GPTWithMBR: prefers a valid conventional MBR while continuing to use GPTfor protective and hybrid MBR layouts. This is the new default.
GPTIgnoreMBR: preserves the previous GPT-first behavior.The existing
partition.Readsignature remains unchanged and delegates toReadWithPolicyusingGPTWithMBR.Behavior
A protective entry is recognized by type
0xEEwith starting LBA 1. Its sizeis intentionally not required to span the current disk, since a disk image may
have been copied to a larger device without updating the PMBR size.
Tests
Added coverage for:
GPTWithMBRbehaviorGPTIgnoreMBRValidation performed:
go test ./partition/... -count=1go test -race ./partition/... -count=1go vet ./...golangci-lint run ./partition/...Fixes #422