Check for permission denied error when trying to access the player and inform the user that raw disc access permissions are required.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17351 a1c6a512-1295-4272-9138-f99709370657
diff --git a/rbutil/ipodpatcher/ipodio-posix.c b/rbutil/ipodpatcher/ipodio-posix.c
index 55f0187..c62e0c8 100644
--- a/rbutil/ipodpatcher/ipodio-posix.c
+++ b/rbutil/ipodpatcher/ipodio-posix.c
@@ -25,6 +25,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+#include <errno.h>
#include "ipodio.h"
@@ -105,7 +106,8 @@
ipod->dh=open(ipod->diskname,O_RDONLY);
if (ipod->dh < 0) {
if (!silent) perror(ipod->diskname);
- return -1;
+ if(errno == EACCES) return -2;
+ else return -1;
}
/* Read information about the disk */
diff --git a/rbutil/ipodpatcher/ipodio-win32.c b/rbutil/ipodpatcher/ipodio-win32.c
index 2f75153..985ec4e 100644
--- a/rbutil/ipodpatcher/ipodio-win32.c
+++ b/rbutil/ipodpatcher/ipodio-win32.c
@@ -78,7 +78,10 @@
if (ipod->dh == INVALID_HANDLE_VALUE) {
if (!silent) print_error(" Error opening disk: ");
- return -1;
+ if(GetLastError() == ERROR_ACCESS_DENIED)
+ return -2;
+ else
+ return -1;
}
if (!lock_volume(ipod->dh)) {
diff --git a/rbutil/ipodpatcher/ipodpatcher.c b/rbutil/ipodpatcher/ipodpatcher.c
index 08ba926..d9048f2 100644
--- a/rbutil/ipodpatcher/ipodpatcher.c
+++ b/rbutil/ipodpatcher/ipodpatcher.c
@@ -1260,12 +1260,16 @@
return 0;
}
+/* returns number of found ipods or -1 if no ipods found and permission
+ * for raw disc access was denied. */
int ipod_scan(struct ipod_t* ipod)
{
int i;
int n = 0;
int ipod_version;
char last_ipod[4096];
+ int denied = 0;
+ int result;
printf("[INFO] Scanning disk devices...\n");
@@ -1282,7 +1286,10 @@
#else
#error No disk paths defined for this platform
#endif
- if (ipod_open(ipod, 1) < 0) {
+ if ((result = ipod_open(ipod, 1)) < 0) {
+ if(result == -2) {
+ denied++;
+ }
continue;
}
@@ -1319,7 +1326,15 @@
/* Remember the disk name */
strcpy(ipod->diskname,last_ipod);
}
- return n;
+ else if(n == 0 && denied) {
+ printf("[ERR] FATAL: Permission denied on %d device(s) and no ipod detected.\n", denied);
+#ifdef __WIN32__
+ printf("[ERR] You need to run this program with administrator priviledges!\n");
+#else
+ printf("[ERR] You need permissions for raw disc access for this program to work!\n");
+#endif
+ }
+ return (n == 0 && denied) ? -1 : n;
}
static void put_int32le(uint32_t x, unsigned char* p)