Skip to content

Clean up block device detection logic #3175

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
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kjkent
Copy link

@kjkent kjkent commented Mar 22, 2025

From #3174 (comment):

  • Having nested if statements in wait_and_create_part() corrupts the intended logic. If the first condition (for $vPART1) passes but the second (for $vPART2) fails, the else doesn't trigger, leading to missed waits, and then a missed sanity check at the end that allows execution to continue
  • Using ls | grep -q '^b' to check for block devices (again in wait_and_create_part()) is fragile: it's not uncommon for ls to be aliased or options set that may prevent 'b' from reliably being the first letter of the output for a valid block device. Also, the partitions are being checked for presence, then immediately checked again, and if they don't enumerate the second time then mknod is being called which could cause further device re-enumeration
  • The quick succession of having the partitions be altered and checked, sequentially and inconsistently due to the first point, is causing a race condition that allows execution to continue when it shouldn't.

I edited the code to use partprobe (provided by parted, which the project already depends on) to inform the kernel of any device changes, slowed the loop down and removed the mknod code, and it worked great afterwards.

Interestingly, as happened in my case, if the device already had a exfat partition 1, from an old ventoy installation or prior use, that old fs signature can persist through the formatting process leading to weird effect. I was experiencing #1133, on GPT and MBR, but after changing this logic, Windows 11 installation now works fine.

In the end I elected to not remove the mknod code as I figured that there may be a legitimate case where it's needed. However, in this PR I edit it to only be called if the partition fs nodes are not found after repeated kernel refreshing, and, after it runs, the device partitions are re-checked before continuing. If this succeeds then the process continues to mkexfatfs, and, if not, the user is advised to try re-inserting the USB or retrying with other ports/hardware.

I hope this PR is okay? It's my first to the project and I hope it's helpful in some way.

Closes #3174 and #3256

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.

[issue]: Logic in partition creation formatting leads to race condition
1 participant