summaryrefslogtreecommitdiff
path: root/rbutil/ipodpatcher/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/ipodpatcher/main.c')
-rw-r--r--rbutil/ipodpatcher/main.c50
1 files changed, 47 insertions, 3 deletions
diff --git a/rbutil/ipodpatcher/main.c b/rbutil/ipodpatcher/main.c
index 88ac3a60e1..1dcb916240 100644
--- a/rbutil/ipodpatcher/main.c
+++ b/rbutil/ipodpatcher/main.c
@@ -50,6 +50,7 @@ enum {
50 READ_PARTITION, 50 READ_PARTITION,
51 WRITE_PARTITION, 51 WRITE_PARTITION,
52 FORMAT_PARTITION, 52 FORMAT_PARTITION,
53 DUMP_XML,
53 CONVERT_TO_FAT32 54 CONVERT_TO_FAT32
54}; 55};
55 56
@@ -93,6 +94,7 @@ void print_usage(void)
93 fprintf(stderr," -c, --convert\n"); 94 fprintf(stderr," -c, --convert\n");
94 fprintf(stderr," --read-aupd filename.bin\n"); 95 fprintf(stderr," --read-aupd filename.bin\n");
95 fprintf(stderr," --write-aupd filename.bin\n"); 96 fprintf(stderr," --write-aupd filename.bin\n");
97 fprintf(stderr," -x --dump-xml filename.xml\n");
96 fprintf(stderr,"\n"); 98 fprintf(stderr,"\n");
97 99
98#ifdef __WIN32__ 100#ifdef __WIN32__
@@ -315,6 +317,13 @@ int main(int argc, char* argv[])
315 if (i == argc) { print_usage(); return 1; } 317 if (i == argc) { print_usage(); return 1; }
316 filename=argv[i]; 318 filename=argv[i];
317 i++; 319 i++;
320 } else if ((strcmp(argv[i],"-x")==0) ||
321 (strcmp(argv[i],"--dump-xml")==0)) {
322 action = DUMP_XML;
323 i++;
324 if (i == argc) { print_usage(); return 1; }
325 filename=argv[i];
326 i++;
318 } else if ((strcmp(argv[i],"-c")==0) || 327 } else if ((strcmp(argv[i],"-c")==0) ||
319 (strcmp(argv[i],"--convert")==0)) { 328 (strcmp(argv[i],"--convert")==0)) {
320 action = CONVERT_TO_FAT32; 329 action = CONVERT_TO_FAT32;
@@ -361,8 +370,26 @@ int main(int argc, char* argv[])
361 return -1; 370 return -1;
362 } 371 }
363 372
364 printf("[INFO] Ipod model: %s (\"%s\")\n",ipod.modelstr, 373#ifdef __WIN32__
365 ipod.macpod ? "macpod" : "winpod"); 374 /* Windows requires the ipod in R/W mode for SCSI Inquiry */
375 if (ipod_reopen_rw(&ipod) < 0) {
376 return 5;
377 }
378#endif
379
380
381 /* Read the XML info, and if successful, look for the ramsize
382 (only available for some models - set to 0 if not known) */
383
384 ipod.ramsize = 0;
385
386 if (ipod_get_xmlinfo(&ipod) == 0) {
387 ipod_get_ramsize(&ipod);
388 }
389
390 printf("[INFO] Ipod model: %s ",ipod.modelstr);
391 if (ipod.ramsize > 0) { printf("(%dMB RAM) ",ipod.ramsize); }
392 printf("(\"%s\")\n",ipod.macpod ? "macpod" : "winpod");
366 393
367 if (ipod.ipod_directory[0].vers == 0x10000) { 394 if (ipod.ipod_directory[0].vers == 0x10000) {
368 fprintf(stderr,"[ERR] *** ipodpatcher does not support the 2nd Generation Nano! ***\n"); 395 fprintf(stderr,"[ERR] *** ipodpatcher does not support the 2nd Generation Nano! ***\n");
@@ -476,6 +503,24 @@ int main(int argc, char* argv[])
476 } else { 503 } else {
477 fprintf(stderr,"[ERR] --write-aupd failed.\n"); 504 fprintf(stderr,"[ERR] --write-aupd failed.\n");
478 } 505 }
506 } else if (action==DUMP_XML) {
507 if (ipod.xmlinfo == NULL) {
508 fprintf(stderr,"[ERR] No XML to write\n");
509 return 1;
510 }
511
512 outfile = open(filename,O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,S_IREAD|S_IWRITE);
513 if (outfile < 0) {
514 perror(filename);
515 return 4;
516 }
517
518 if (write(outfile, ipod.xmlinfo, ipod.xmlinfo_len) < 0) {
519 fprintf(stderr,"[ERR] --dump-xml failed.\n");
520 } else {
521 fprintf(stderr,"[INFO] XML info written to %s.\n",filename);
522 }
523 close(outfile);
479 } else if (action==READ_PARTITION) { 524 } else if (action==READ_PARTITION) {
480 outfile = open(filename,O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,S_IREAD|S_IWRITE); 525 outfile = open(filename,O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,S_IREAD|S_IWRITE);
481 if (outfile < 0) { 526 if (outfile < 0) {
@@ -571,6 +616,5 @@ int main(int argc, char* argv[])
571 } 616 }
572#endif 617#endif
573 618
574
575 return 0; 619 return 0;
576} 620}