forked from len0rd/rockbox
Make sansapatcher check and report permission denied errors.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17461 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
b9ae6664b3
commit
850c4f98ba
3 changed files with 42 additions and 23 deletions
|
|
@ -25,6 +25,7 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
#if defined(linux) || defined (__linux)
|
#if defined(linux) || defined (__linux)
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
|
@ -74,7 +75,8 @@ int sansa_open(struct sansa_t* sansa, int silent)
|
||||||
sansa->dh=open(sansa->diskname,O_RDONLY);
|
sansa->dh=open(sansa->diskname,O_RDONLY);
|
||||||
if (sansa->dh < 0) {
|
if (sansa->dh < 0) {
|
||||||
if (!silent) perror(sansa->diskname);
|
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) {
|
if(ioctl(sansa->dh,SANSA_SECTORSIZE_IOCTL,&sansa->sector_size) < 0) {
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,10 @@ int sansa_open(struct sansa_t* sansa, int silent)
|
||||||
|
|
||||||
if (sansa->dh == INVALID_HANDLE_VALUE) {
|
if (sansa->dh == INVALID_HANDLE_VALUE) {
|
||||||
if (!silent) print_error(" Error opening disk: ");
|
if (!silent) print_error(" Error opening disk: ");
|
||||||
return -1;
|
if(GetLastError() == ERROR_ACCESS_DENIED)
|
||||||
|
return -2;
|
||||||
|
else
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!lock_volume(sansa->dh)) {
|
if (!lock_volume(sansa->dh)) {
|
||||||
|
|
|
||||||
|
|
@ -490,49 +490,63 @@ int sansa_scan(struct sansa_t* sansa)
|
||||||
int i;
|
int i;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
char last_disk[4096];
|
char last_disk[4096];
|
||||||
|
int denied = 0;
|
||||||
|
int result;
|
||||||
|
|
||||||
printf("[INFO] Scanning disk devices...\n");
|
printf("[INFO] Scanning disk devices...\n");
|
||||||
|
|
||||||
for (i = 0; i <= 25 ; i++) {
|
for (i = 0; i <= 25 ; i++) {
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
sprintf(sansa->diskname,"\\\\.\\PhysicalDrive%d",i);
|
sprintf(sansa->diskname,"\\\\.\\PhysicalDrive%d",i);
|
||||||
#elif defined(linux) || defined (__linux)
|
#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__) \
|
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \
|
||||||
|| defined(__bsdi__) || defined(__DragonFly__)
|
|| defined(__bsdi__) || defined(__DragonFly__)
|
||||||
sprintf(sansa->diskname,"/dev/da%d",i);
|
sprintf(sansa->diskname,"/dev/da%d",i);
|
||||||
#elif defined(__APPLE__) && defined(__MACH__)
|
#elif defined(__APPLE__) && defined(__MACH__)
|
||||||
sprintf(sansa->diskname,"/dev/disk%d",i);
|
sprintf(sansa->diskname,"/dev/disk%d",i);
|
||||||
#else
|
#else
|
||||||
#error No disk paths defined for this platform
|
#error No disk paths defined for this platform
|
||||||
#endif
|
#endif
|
||||||
if (sansa_open(sansa, 1) < 0) {
|
if ((result = sansa_open(sansa, 1)) < 0) {
|
||||||
continue;
|
if(result == -2) {
|
||||||
}
|
denied++;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (sansa_read_partinfo(sansa,1) < 0) {
|
if (sansa_read_partinfo(sansa,1) < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_sansa(sansa) < 0) {
|
if (is_sansa(sansa) < 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __WIN32__
|
#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
|
#else
|
||||||
printf("[INFO] %s found - %s\n",sansa->targetname, sansa->diskname);
|
printf("[INFO] %s found - %s\n",sansa->targetname, sansa->diskname);
|
||||||
#endif
|
#endif
|
||||||
n++;
|
n++;
|
||||||
strcpy(last_disk,sansa->diskname);
|
strcpy(last_disk,sansa->diskname);
|
||||||
sansa_close(sansa);
|
sansa_close(sansa);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n==1) {
|
if (n==1) {
|
||||||
/* Remember the disk name */
|
/* Remember the disk name */
|
||||||
strcpy(sansa->diskname,last_disk);
|
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
|
/* Prepare original firmware for writing to the firmware partition by decrypting
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue