Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logical partitions renumbering #2118

Merged
merged 1 commit into from
Nov 26, 2024
Merged

Conversation

ogayot
Copy link
Member

@ogayot ogayot commented Nov 22, 2024

When deleting a partition, we used to renumber the logical partitions. There was two problems associated with this:

  1. The new partition numbers start at N+1 where N is the partition number of the partition deleted. However, there is no guarantee that N+1 corresponds to a valid logical partition number. For instance, if we remove partition 1 (on DOS partition table), then we would start renumbering logical partitions with number 2, 3, 4, ... Instead, we should start at 5 (which is the smallest partition number for a logical partition). To address this issue, we only renumber after removing a logical partition.
    2. The renumbering also applied to partitions to preserve. This can break existing systems so let's make sure we stop renumbering if we run into a partition to preserve.

NOTE: I must admit that the reasoning for doing this renumbering (and only doing it for logical partitions) is not clear to me.

The renumber_logical_partition function does not do the right thing if
called after removing a primary partition. As it is today, the
implementation does not ensure that the new partition numbers are in the
range of logical partition numbers.

As a consequence, if we remove partition 1 from a MSDOS partition
table, the logical partitions will be renumbered 2, 3, 4, ... which are
not in the 5+ range. The new numbers might also conflict with primary
partition 2, 3, and 4 if they exist.

Fixed by invoking the function only after removing a logical partition.

Signed-off-by: Olivier Gayot <[email protected]>
@ogayot ogayot requested a review from dbungert November 22, 2024 15:51
@ogayot
Copy link
Member Author

ogayot commented Nov 22, 2024

@ogayot to check if leaving a "gap" between logical partitions numbers is acceptable.

@mwhudson
Copy link
Collaborator

2. The renumbering also applied to partitions to preserve. This can break existing systems so let's make sure we stop renumbering if we run into a partition to preserve.

We can't though, this is just how logical partitions work -- logical partitions are basically a linked list and are numbered as you walk along the list so if you delete one, the partitions after that in the list get renumbered. At least that's my understanding -- I might be wrong! But that's why things are the way they are, for better or worse.

@ogayot
Copy link
Member Author

ogayot commented Nov 25, 2024

  1. The renumbering also applied to partitions to preserve. This can break existing systems so let's make sure we stop renumbering if we run into a partition to preserve.

We can't though, this is just how logical partitions work -- logical partitions are basically a linked list and are numbered as you walk along the list so if you delete one, the partitions after that in the list get renumbered. At least that's my understanding -- I might be wrong! But that's why things are the way they are, for better or worse.

Unfortunately, that is my understanding as well after reading more about the topic. Thanks for pointing this out. I'll drop my second patch.

@ogayot
Copy link
Member Author

ogayot commented Nov 25, 2024

@ogayot to check if leaving a "gap" between logical partitions numbers is acceptable.

An actual gap (e.g., having partition 6 with no partition 5) is not a thing for logical partitions because of how numbering works. And while it seems theoretically possible to have partition N+1 before N in terms of physical location ; many partitioning tools expect the opposite.

@ogayot ogayot requested a review from mwhudson November 25, 2024 15:33
Copy link
Collaborator

@dbungert dbungert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@ogayot ogayot merged commit 17b7296 into canonical:main Nov 26, 2024
10 checks passed
@ogayot ogayot deleted the logical-renumber branch November 26, 2024 08:55
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