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,6 +79,9 @@ 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: ");
|
||||||
|
if(GetLastError() == ERROR_ACCESS_DENIED)
|
||||||
|
return -2;
|
||||||
|
else
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -490,6 +490,8 @@ 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");
|
||||||
|
|
||||||
|
|
@ -506,7 +508,10 @@ int sansa_scan(struct sansa_t* sansa)
|
||||||
#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) {
|
||||||
|
if(result == -2) {
|
||||||
|
denied++;
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -532,7 +537,16 @@ int sansa_scan(struct sansa_t* sansa)
|
||||||
/* 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