Commit 15a7d59
refactor(file): replace fdisk with gptman+mbrman (#154)
## Summary
Replace the fragile `fdisk`-based partition detection in
`get_partition_info()` with Rust-native `gptman` and `mbrman` crates.
**Changes:**
- Add `gptman` (GPT with CRC32 validation) and `mbrman` (MBR including
logical partitions) as dependencies
- Add `src/file/partition.rs` with `get_partition_data()` and `is_gpt()`
- Remove locale-sensitive `fdisk` shell invocation and regex parsing
- Remove `fdisk` from `package.metadata.deb` depends
- Change `PartitionInfo` fields from `String` to typed `u32`/`u64`
## Reason
The previous implementation spawned `fdisk -l` and parsed its text
output with regex — making it locale-sensitive, version-dependent, and
requiring `fdisk` as a runtime system dependency.
Additionally, a pre-existing bug was fixed: `PartitionInfo.end` held the
last sector (inclusive) from `fdisk` output and was passed directly as
`dd count=`, but `count` expects the number of sectors. For a partition
starting at sector 2048 and ending at 206847, this caused `dd` to copy
206847 sectors instead of the correct 204800.
**Fixed semantics:**
- GPT: `count = ending_lba - starting_lba + 1`
- MBR: `count = p.sectors` (already the sector count)
## Verification
- `cargo check` passes
- `cargo fmt -- --check` passes
- `cargo clippy -- -D warnings` passes
- Manually tested against GPT and MBR image files
---------
Signed-off-by: Harry Waschkeit <44188360+HarryWaschkeit@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>1 parent a672d94 commit 15a7d59
5 files changed
Lines changed: 195 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
| |||
85 | 87 | | |
86 | 88 | | |
87 | 89 | | |
88 | | - | |
| 90 | + | |
89 | 91 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | 3 | | |
5 | 4 | | |
6 | 5 | | |
| |||
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
25 | | - | |
26 | | - | |
27 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
28 | 27 | | |
29 | 28 | | |
30 | 29 | | |
| |||
184 | 183 | | |
185 | 184 | | |
186 | 185 | | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | 186 | | |
205 | 187 | | |
206 | 188 | | |
| |||
381 | 363 | | |
382 | 364 | | |
383 | 365 | | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
| 366 | + | |
391 | 367 | | |
392 | | - | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
393 | 372 | | |
394 | 373 | | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
416 | 386 | | |
417 | 387 | | |
418 | 388 | | |
419 | 389 | | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
428 | | - | |
429 | | - | |
| 390 | + | |
430 | 391 | | |
431 | | - | |
| 392 | + | |
| 393 | + | |
432 | 394 | | |
433 | 395 | | |
434 | | - | |
435 | | - | |
436 | | - | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
437 | 399 | | |
438 | 400 | | |
439 | 401 | | |
| |||
455 | 417 | | |
456 | 418 | | |
457 | 419 | | |
458 | | - | |
| 420 | + | |
459 | 421 | | |
460 | 422 | | |
461 | 423 | | |
| |||
476 | 438 | | |
477 | 439 | | |
478 | 440 | | |
479 | | - | |
| 441 | + | |
480 | 442 | | |
481 | 443 | | |
482 | 444 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
0 commit comments