From 850c4f98baecf3d3c28e916927d15d3bbd0cd502 Mon Sep 17 00:00:00 2001 From: Dominik Riebeling Date: Sun, 11 May 2008 16:58:02 +0000 Subject: Make sansapatcher check and report permission denied errors. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17461 a1c6a512-1295-4272-9138-f99709370657 --- rbutil/sansapatcher/sansaio-posix.c | 4 ++- rbutil/sansapatcher/sansaio-win32.c | 5 +++- rbutil/sansapatcher/sansapatcher.c | 56 +++++++++++++++++++++++-------------- 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/rbutil/sansapatcher/sansaio-posix.c b/rbutil/sansapatcher/sansaio-posix.c index 22abc883d2..95677b6b35 100644 --- a/rbutil/sansapatcher/sansaio-posix.c +++ b/rbutil/sansapatcher/sansaio-posix.c @@ -25,6 +25,7 @@ #include #include #include +#include #if defined(linux) || defined (__linux) #include @@ -74,7 +75,8 @@ int sansa_open(struct sansa_t* sansa, int silent) sansa->dh=open(sansa->diskname,O_RDONLY); if (sansa->dh < 0) { if (!silent) perror(sansa->diskname); - return -1; + if(errno == EACCES) return -2; + else return -1; } if(ioctl(sansa->dh,SANSA_SECTORSIZE_IOCTL,&sansa->sector_size) < 0) { diff --git a/rbutil/sansapatcher/sansaio-win32.c b/rbutil/sansapatcher/sansaio-win32.c index 8c2c696c1a..15bf82be3c 100644 --- a/rbutil/sansapatcher/sansaio-win32.c +++ b/rbutil/sansapatcher/sansaio-win32.c @@ -79,7 +79,10 @@ int sansa_open(struct sansa_t* sansa, int silent) if (sansa->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(sansa->dh)) { diff --git a/rbutil/sansapatcher/sansapatcher.c b/rbutil/sansapatcher/sansapatcher.c index bc03108930..ee15a16ca9 100644 --- a/rbutil/sansapatcher/sansapatcher.c +++ b/rbutil/sansapatcher/sansapatcher.c @@ -490,49 +490,63 @@ int sansa_scan(struct sansa_t* sansa) int i; int n = 0; char last_disk[4096]; + int denied = 0; + int result; printf("[INFO] Scanning disk devices...\n"); for (i = 0; i <= 25 ; i++) { #ifdef __WIN32__ - sprintf(sansa->diskname,"\\\\.\\PhysicalDrive%d",i); + sprintf(sansa->diskname,"\\\\.\\PhysicalDrive%d",i); #elif defined(linux) || defined (__linux) - sprintf(sansa->diskname,"/dev/sd%c",'a'+i); + sprintf(sansa->diskname,"/dev/sd%c",'a'+i); #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \ - || defined(__bsdi__) || defined(__DragonFly__) - sprintf(sansa->diskname,"/dev/da%d",i); + || defined(__bsdi__) || defined(__DragonFly__) + sprintf(sansa->diskname,"/dev/da%d",i); #elif defined(__APPLE__) && defined(__MACH__) - sprintf(sansa->diskname,"/dev/disk%d",i); + sprintf(sansa->diskname,"/dev/disk%d",i); #else - #error No disk paths defined for this platform +#error No disk paths defined for this platform #endif - if (sansa_open(sansa, 1) < 0) { - continue; - } + if ((result = sansa_open(sansa, 1)) < 0) { + if(result == -2) { + denied++; + } + continue; + } - if (sansa_read_partinfo(sansa,1) < 0) { - continue; - } + if (sansa_read_partinfo(sansa,1) < 0) { + continue; + } - if (is_sansa(sansa) < 0) { - continue; - } + if (is_sansa(sansa) < 0) { + continue; + } #ifdef __WIN32__ - printf("[INFO] %s found - disk device %d\n",sansa->targetname, i); + printf("[INFO] %s found - disk device %d\n",sansa->targetname, i); #else - printf("[INFO] %s found - %s\n",sansa->targetname, sansa->diskname); + printf("[INFO] %s found - %s\n",sansa->targetname, sansa->diskname); #endif - n++; - strcpy(last_disk,sansa->diskname); - sansa_close(sansa); + n++; + strcpy(last_disk,sansa->diskname); + sansa_close(sansa); } if (n==1) { /* Remember the disk name */ strcpy(sansa->diskname,last_disk); } - return n; + else if (n == 0 && denied) { + printf("[ERR] FATAL: Permission denied on %d device(s) and no sansa 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; } /* Prepare original firmware for writing to the firmware partition by decrypting -- cgit v1.2.3