diff options
author | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2022-04-14 22:22:22 +0200 |
---|---|---|
committer | Dominik Riebeling <Dominik.Riebeling@gmail.com> | 2022-04-14 22:22:46 +0200 |
commit | 8a6ceff3762784d99f57e2f7f20149f97b6d82c7 (patch) | |
tree | 0ca938d476fc296aa90603570a70a6fb17dc524d | |
parent | cc2f36492666be11da12890b35303a63e3aced87 (diff) | |
download | rockbox-8a6ceff376.tar.gz rockbox-8a6ceff376.zip |
rbutil: Fix sansapatcher bootloader install on Windows.
During bootloader installation sansapatcher disk access is accidentially
set up twice. This is not a problem except on Windows, which will abort
with a "permission denied" error.
This is basically the same problem as for ipodpatcher bootloader install.
Change-Id: I03220e17d0e00a15fff23c02aba7da93d4781964
-rw-r--r-- | utils/rbutilqt/base/bootloaderinstallipod.cpp | 5 | ||||
-rw-r--r-- | utils/rbutilqt/base/bootloaderinstallsansa.cpp | 40 | ||||
-rw-r--r-- | utils/sansapatcher/sansaio-posix.c | 1 | ||||
-rw-r--r-- | utils/sansapatcher/sansaio-win32.c | 1 |
4 files changed, 27 insertions, 20 deletions
diff --git a/utils/rbutilqt/base/bootloaderinstallipod.cpp b/utils/rbutilqt/base/bootloaderinstallipod.cpp index a809b813c0..1bddaea6d5 100644 --- a/utils/rbutilqt/base/bootloaderinstallipod.cpp +++ b/utils/rbutilqt/base/bootloaderinstallipod.cpp @@ -29,6 +29,11 @@ BootloaderInstallIpod::BootloaderInstallIpod(QObject *parent) : BootloaderInstallBase(parent) { ipod.sectorbuf = nullptr; +#if defined(Q_OS_WIN32) + ipod.dh = INVALID_HANDLE_VALUE; +#else + ipod.dh = -1; +#endif } diff --git a/utils/rbutilqt/base/bootloaderinstallsansa.cpp b/utils/rbutilqt/base/bootloaderinstallsansa.cpp index f6e345c7e2..b8e307cf2c 100644 --- a/utils/rbutilqt/base/bootloaderinstallsansa.cpp +++ b/utils/rbutilqt/base/bootloaderinstallsansa.cpp @@ -28,6 +28,11 @@ BootloaderInstallSansa::BootloaderInstallSansa(QObject *parent) : BootloaderInstallBase(parent) { sansa.sectorbuf = nullptr; +#if defined(Q_OS_WIN32) + sansa.dh = INVALID_HANDLE_VALUE; +#else + sansa.dh = -1; +#endif } @@ -51,21 +56,6 @@ bool BootloaderInstallSansa::install(void) emit done(true); } - emit logItem(tr("Searching for Sansa"), LOGINFO); - - int n = sansa_scan(&sansa); - if(n == -1) { - emit logItem(tr("Permission for disc access denied!\n" - "This is required to install the bootloader"), - LOGERROR); - emit done(true); - return false; - } - if(n == 0) { - emit logItem(tr("No Sansa detected!"), LOGERROR); - emit done(true); - return false; - } if(sansa.hasoldbootloader) { emit logItem(tr("OLD ROCKBOX INSTALLATION DETECTED, ABORTING.\n" "You must reinstall the original Sansa firmware before running\n" @@ -92,10 +82,6 @@ void BootloaderInstallSansa::installStage2(void) emit logItem(tr("Installing Rockbox bootloader"), LOGINFO); QCoreApplication::processEvents(); - if(!sansaInitialize(&sansa)) { - emit done(true); - return; - } if(sansa_reopen_rw(&sansa) < 0) { emit logItem(tr("Could not open Sansa in R/W mode"), LOGERROR); @@ -232,7 +218,21 @@ BootloaderInstallBase::BootloaderType BootloaderInstallSansa::installed(void) bool BootloaderInstallSansa::sansaInitialize(struct sansa_t *sansa) { - // initialize sector buffer. The sector buffer is part of the sansa_t + // if the ipod was already opened make sure to close it first. +#if defined(Q_OS_WIN32) + if(sansa->dh != INVALID_HANDLE_VALUE) +#else + if(sansa->dh >= 0) +#endif + { + sansa_close(sansa); + } + // save buffer pointer before cleaning up ipod_t structure + unsigned char* sb = sansa->sectorbuf; + memset(sansa, 0, sizeof(struct sansa_t)); + sansa->sectorbuf = sb; + + // initialize sector buffer. The sector buffer is part of the ipod_t // structure, so a second instance of this class will have its own buffer. if(sansa->sectorbuf == nullptr) { sansa_alloc_buffer(sansa, BUFFER_SIZE); diff --git a/utils/sansapatcher/sansaio-posix.c b/utils/sansapatcher/sansaio-posix.c index 44c4dcc95c..5625ec35a4 100644 --- a/utils/sansapatcher/sansaio-posix.c +++ b/utils/sansapatcher/sansaio-posix.c @@ -110,6 +110,7 @@ int sansa_reopen_rw(struct sansa_t* sansa) int sansa_close(struct sansa_t* sansa) { close(sansa->dh); + sansa->dh = -1; return 0; } diff --git a/utils/sansapatcher/sansaio-win32.c b/utils/sansapatcher/sansaio-win32.c index ee6a8cd93d..be250136f9 100644 --- a/utils/sansapatcher/sansaio-win32.c +++ b/utils/sansapatcher/sansaio-win32.c @@ -147,6 +147,7 @@ int sansa_close(struct sansa_t* sansa) { unlock_volume(sansa->dh); CloseHandle(sansa->dh); + sansa->dh = INVALID_HANDLE_VALUE; return 0; } |