-
Notifications
You must be signed in to change notification settings - Fork 128
disk images: fix some corner-cases in MBR calculation #318
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
Open
nrclark
wants to merge
1
commit into
pengutronix:master
Choose a base branch
from
nrclark:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,15 +116,24 @@ static unsigned long long partition_end(const struct partition *part) | |
|
|
||
| static void lba_to_chs(unsigned int lba, unsigned char *chs) | ||
| { | ||
| const unsigned int hpc = 255; | ||
| const unsigned int spt = 63; | ||
| unsigned int s, c; | ||
|
|
||
| chs[0] = (lba / spt) % hpc; | ||
| c = (lba / (spt * hpc)); | ||
| s = (lba > 0) ? (lba % spt + 1) : 0; | ||
| chs[1] = ((c & 0x300) >> 2) | (s & 0xff); | ||
| chs[2] = (c & 0xff); | ||
| const unsigned int heads_per_cyl = 255; | ||
| const unsigned int sect_per_track = 63; | ||
|
|
||
| if (lba > (1024 * heads_per_cyl * sect_per_track - 1)) { | ||
| chs[0] = 0xFE; | ||
| chs[1] = 0xFF; | ||
| chs[2] = 0xFF; | ||
| return; | ||
| } | ||
|
|
||
| unsigned int cylinder = lba / (heads_per_cyl * sect_per_track); | ||
| unsigned int remainder = lba % (heads_per_cyl * sect_per_track); | ||
| unsigned int head = remainder / sect_per_track; | ||
| unsigned int sector = (remainder % sect_per_track) + 1; | ||
|
|
||
| chs[0] = head & 0xFF; | ||
| chs[1] = (sector & 0x3F) + ((cylinder & 0x300) >> 2); | ||
| chs[2] = cylinder & 0xFF; | ||
| } | ||
|
|
||
| static void hdimage_setup_chs(struct mbr_partition_entry *entry, | ||
|
|
@@ -185,7 +194,7 @@ static int hdimage_insert_mbr(struct image *image, struct list_head *partitions) | |
|
|
||
| entry->partition_type = 0xee; | ||
| entry->relative_sectors = 1; | ||
| entry->total_sectors = hd->gpt_location / 512 + GPT_SECTORS - 2; | ||
| entry->total_sectors = GPT_SECTORS; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. gpt_location is configurable. It doesn't have start at LBA2. We specifically use this on some i.MX SoCs where the |
||
|
|
||
| hdimage_setup_chs(entry, 0); | ||
| } | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be better readable if you moved the variable renaming to a separate patch so the actual changes in functionality are better visible