diff options
Diffstat (limited to 'rbutil')
-rw-r--r-- | rbutil/sansapatcher/sansaio-posix.c | 4 | ||||
-rw-r--r-- | rbutil/sansapatcher/sansaio-win32.c | 5 | ||||
-rw-r--r-- | 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 @@ | |||
25 | #include <sys/types.h> | 25 | #include <sys/types.h> |
26 | #include <sys/stat.h> | 26 | #include <sys/stat.h> |
27 | #include <sys/ioctl.h> | 27 | #include <sys/ioctl.h> |
28 | #include <errno.h> | ||
28 | 29 | ||
29 | #if defined(linux) || defined (__linux) | 30 | #if defined(linux) || defined (__linux) |
30 | #include <sys/mount.h> | 31 | #include <sys/mount.h> |
@@ -74,7 +75,8 @@ int sansa_open(struct sansa_t* sansa, int silent) | |||
74 | sansa->dh=open(sansa->diskname,O_RDONLY); | 75 | sansa->dh=open(sansa->diskname,O_RDONLY); |
75 | if (sansa->dh < 0) { | 76 | if (sansa->dh < 0) { |
76 | if (!silent) perror(sansa->diskname); | 77 | if (!silent) perror(sansa->diskname); |
77 | return -1; | 78 | if(errno == EACCES) return -2; |
79 | else return -1; | ||
78 | } | 80 | } |
79 | 81 | ||
80 | if(ioctl(sansa->dh,SANSA_SECTORSIZE_IOCTL,&sansa->sector_size) < 0) { | 82 | 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) | |||
79 | 79 | ||
80 | if (sansa->dh == INVALID_HANDLE_VALUE) { | 80 | if (sansa->dh == INVALID_HANDLE_VALUE) { |
81 | if (!silent) print_error(" Error opening disk: "); | 81 | if (!silent) print_error(" Error opening disk: "); |
82 | return -1; | 82 | if(GetLastError() == ERROR_ACCESS_DENIED) |
83 | return -2; | ||
84 | else | ||
85 | return -1; | ||
83 | } | 86 | } |
84 | 87 | ||
85 | if (!lock_volume(sansa->dh)) { | 88 | 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) | |||
490 | int i; | 490 | int i; |
491 | int n = 0; | 491 | int n = 0; |
492 | char last_disk[4096]; | 492 | char last_disk[4096]; |
493 | int denied = 0; | ||
494 | int result; | ||
493 | 495 | ||
494 | printf("[INFO] Scanning disk devices...\n"); | 496 | printf("[INFO] Scanning disk devices...\n"); |
495 | 497 | ||
496 | for (i = 0; i <= 25 ; i++) { | 498 | for (i = 0; i <= 25 ; i++) { |
497 | #ifdef __WIN32__ | 499 | #ifdef __WIN32__ |
498 | sprintf(sansa->diskname,"\\\\.\\PhysicalDrive%d",i); | 500 | sprintf(sansa->diskname,"\\\\.\\PhysicalDrive%d",i); |
499 | #elif defined(linux) || defined (__linux) | 501 | #elif defined(linux) || defined (__linux) |
500 | sprintf(sansa->diskname,"/dev/sd%c",'a'+i); | 502 | sprintf(sansa->diskname,"/dev/sd%c",'a'+i); |
501 | #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \ | 503 | #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) \ |
502 | || defined(__bsdi__) || defined(__DragonFly__) | 504 | || defined(__bsdi__) || defined(__DragonFly__) |
503 | sprintf(sansa->diskname,"/dev/da%d",i); | 505 | sprintf(sansa->diskname,"/dev/da%d",i); |
504 | #elif defined(__APPLE__) && defined(__MACH__) | 506 | #elif defined(__APPLE__) && defined(__MACH__) |
505 | sprintf(sansa->diskname,"/dev/disk%d",i); | 507 | sprintf(sansa->diskname,"/dev/disk%d",i); |
506 | #else | 508 | #else |
507 | #error No disk paths defined for this platform | 509 | #error No disk paths defined for this platform |
508 | #endif | 510 | #endif |
509 | if (sansa_open(sansa, 1) < 0) { | 511 | if ((result = sansa_open(sansa, 1)) < 0) { |
510 | continue; | 512 | if(result == -2) { |
511 | } | 513 | denied++; |
514 | } | ||
515 | continue; | ||
516 | } | ||
512 | 517 | ||
513 | if (sansa_read_partinfo(sansa,1) < 0) { | 518 | if (sansa_read_partinfo(sansa,1) < 0) { |
514 | continue; | 519 | continue; |
515 | } | 520 | } |
516 | 521 | ||
517 | if (is_sansa(sansa) < 0) { | 522 | if (is_sansa(sansa) < 0) { |
518 | continue; | 523 | continue; |
519 | } | 524 | } |
520 | 525 | ||
521 | #ifdef __WIN32__ | 526 | #ifdef __WIN32__ |
522 | printf("[INFO] %s found - disk device %d\n",sansa->targetname, i); | 527 | printf("[INFO] %s found - disk device %d\n",sansa->targetname, i); |
523 | #else | 528 | #else |
524 | printf("[INFO] %s found - %s\n",sansa->targetname, sansa->diskname); | 529 | printf("[INFO] %s found - %s\n",sansa->targetname, sansa->diskname); |
525 | #endif | 530 | #endif |
526 | n++; | 531 | n++; |
527 | strcpy(last_disk,sansa->diskname); | 532 | strcpy(last_disk,sansa->diskname); |
528 | sansa_close(sansa); | 533 | sansa_close(sansa); |
529 | } | 534 | } |
530 | 535 | ||
531 | if (n==1) { | 536 | if (n==1) { |
532 | /* Remember the disk name */ | 537 | /* Remember the disk name */ |
533 | strcpy(sansa->diskname,last_disk); | 538 | strcpy(sansa->diskname,last_disk); |
534 | } | 539 | } |
535 | return n; | 540 | else if (n == 0 && denied) { |
541 | printf("[ERR] FATAL: Permission denied on %d device(s) and no sansa detected.\n", denied); | ||
542 | #ifdef __WIN32__ | ||
543 | printf("[ERR] You need to run this program with administrator priviledges!\n"); | ||
544 | #else | ||
545 | printf("[ERR] You need permissions for raw disc access for this program to work!\n"); | ||
546 | #endif | ||
547 | } | ||
548 | |||
549 | return (n == 0 && denied) ? -1 : n; | ||
536 | } | 550 | } |
537 | 551 | ||
538 | /* Prepare original firmware for writing to the firmware partition by decrypting | 552 | /* Prepare original firmware for writing to the firmware partition by decrypting |