diff options
| author | Ron Yorston <rmy@pobox.com> | 2024-08-02 08:41:25 +0100 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2024-08-02 08:41:25 +0100 |
| commit | dab0de7dbe833a44b3e4c20fcd0044f2d878d10d (patch) | |
| tree | 9246be4dadafaf4853940120eada8865e804fe5c | |
| parent | dde99c5ae2511f8509dae85ce33b22d554ce157c (diff) | |
| download | busybox-w32-dab0de7dbe833a44b3e4c20fcd0044f2d878d10d.tar.gz busybox-w32-dab0de7dbe833a44b3e4c20fcd0044f2d878d10d.tar.bz2 busybox-w32-dab0de7dbe833a44b3e4c20fcd0044f2d878d10d.zip | |
dd: add support for writing to physical drives
A common use of 'dd' is to copy boot images to removable media.
This didn't work on Windows because opening a physical drive
failed with the default flags used by 'dd'.
If the output file is a physical drive remove incompatible flags.
Writing to a physical drive requires elevated privileges and the
drive must be offline.
Adds 80 bytes.
(GitHub issue #435)
| -rw-r--r-- | coreutils/dd.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index a9ef68fbc..e6b88acf5 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
| @@ -333,6 +333,17 @@ static void *alloc_buf(size_t size) | |||
| 333 | return xmalloc(size); | 333 | return xmalloc(size); |
| 334 | } | 334 | } |
| 335 | 335 | ||
| 336 | #if ENABLE_PLATFORM_MINGW32 | ||
| 337 | // Does 'path' refer to a physical drive in the win32 device namespace? | ||
| 338 | static int is_drive_path(const char *path) | ||
| 339 | { | ||
| 340 | char *s = auto_string(strdup(path)); | ||
| 341 | |||
| 342 | bs_to_slash(s); | ||
| 343 | return strncasecmp(s, "//./PhysicalDrive", 17) == 0; | ||
| 344 | } | ||
| 345 | #endif | ||
| 346 | |||
| 336 | int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 347 | int dd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 337 | int dd_main(int argc UNUSED_PARAM, char **argv) | 348 | int dd_main(int argc UNUSED_PARAM, char **argv) |
| 338 | { | 349 | { |
| @@ -558,6 +569,12 @@ int dd_main(int argc UNUSED_PARAM, char **argv) | |||
| 558 | # endif | 569 | # endif |
| 559 | } | 570 | } |
| 560 | #endif | 571 | #endif |
| 572 | #if ENABLE_PLATFORM_MINGW32 | ||
| 573 | if (is_drive_path(outfile)) { | ||
| 574 | // Turn off options not supported by Windows device files. | ||
| 575 | oflag &= ~(O_CREAT | O_TRUNC); | ||
| 576 | } | ||
| 577 | #endif | ||
| 561 | xmove_fd(xopen(outfile, oflag), ofd); | 578 | xmove_fd(xopen(outfile, oflag), ofd); |
| 562 | 579 | ||
| 563 | #if ENABLE_PLATFORM_MINGW32 | 580 | #if ENABLE_PLATFORM_MINGW32 |
