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/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(linux) || defined (__linux)
|
||||
#include <sys/mount.h>
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -79,6 +79,9 @@ int sansa_open(struct sansa_t* sansa, int silent)
|
|||
|
||||
if (sansa->dh == INVALID_HANDLE_VALUE) {
|
||||
if (!silent) print_error(" Error opening disk: ");
|
||||
if(GetLastError() == ERROR_ACCESS_DENIED)
|
||||
return -2;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -490,6 +490,8 @@ 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");
|
||||
|
||||
|
|
@ -504,9 +506,12 @@ int sansa_scan(struct sansa_t* sansa)
|
|||
#elif defined(__APPLE__) && defined(__MACH__)
|
||||
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) {
|
||||
if ((result = sansa_open(sansa, 1)) < 0) {
|
||||
if(result == -2) {
|
||||
denied++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -532,7 +537,16 @@ int sansa_scan(struct sansa_t* sansa)
|
|||
/* 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue