diff --git a/src/cd-read.c b/src/cd-read.c index 3c7a7485..834a2699 100644 --- a/src/cd-read.c +++ b/src/cd-read.c @@ -1,5 +1,5 @@ /* - $Id: cd-read.c,v 1.5 2003/09/21 04:21:39 rocky Exp $ + $Id: cd-read.c,v 1.6 2003/09/21 18:43:36 rocky Exp $ Copyright (C) 2003 Rocky Bernstein @@ -54,7 +54,6 @@ typedef struct { char name[30]; read_mode_t read_mode; - lsn_t start_lsn; } subopt_entry_t; @@ -83,6 +82,8 @@ struct arguments int print_iso9660; source_image_t source_image; lsn_t start_lsn; + lsn_t end_lsn; + int num_sectors; } opts; static void @@ -175,6 +176,14 @@ parse_options (int argc, const char *argv[]) POPT_ARG_INT, &opts.start_lsn, 0, "Set LBA to start reading from"}, + {"end", 'e', + POPT_ARG_INT, &opts.end_lsn, 0, + "Set LBA to end reading from"}, + + {"number", 'n', + POPT_ARG_INT, &opts.num_sectors, 0, + "Set number of sectors to read"}, + {"bin-file", 'b', POPT_ARG_STRING|POPT_ARGFLAG_OPTIONAL, &source_name, OP_SOURCE_BIN, "set \"bin\" CD-ROM disk image file as source", "FILE"}, @@ -198,6 +207,9 @@ parse_options (int argc, const char *argv[]) }; poptContext optCon = poptGetContext (NULL, argc, argv, optionsTable, 0); + program_name = strrchr(argv[0],'/'); + program_name = program_name ? program_name+1 : strdup(argv[0]); + while ((opt = poptGetNextOpt (optCon)) != -1) switch (opt) { @@ -252,12 +264,6 @@ parse_options (int argc, const char *argv[]) exit (EXIT_FAILURE); } - if (poptGetArgs (optCon) != NULL) - { - fprintf (stderr, "error - no arguments expected! - try --help\n"); - exit (EXIT_FAILURE); - } - { const char *remaining_arg = poptGetArg(optCon); if ( remaining_arg != NULL) { @@ -270,6 +276,8 @@ parse_options (int argc, const char *argv[]) if (opts.source_image == OP_SOURCE_DEVICE) source_name = fillout_device_name(remaining_arg); + else + source_name = strdup(remaining_arg); if ( (poptGetArgs(optCon)) != NULL) { fprintf (stderr, @@ -288,13 +296,31 @@ parse_options (int argc, const char *argv[]) exit(10); } - if (opts.start_lsn == CDIO_INVALID_LSN) { - fprintf(stderr, - "%s: Need to give a starting LBA\n", - program_name); - exit(11); + /* Check consistency between start_lsn, end_lsn and num_sectors. */ + if (opts.end_lsn == CDIO_INVALID_LSN) { + if (0 == opts.num_sectors) { + opts.num_sectors = 1; + } + opts.end_lsn = opts.start_lsn + opts.num_sectors - 1; + } else { + /* We were given an end lsn. */ + if (opts.end_lsn < opts.start_lsn) { + fprintf(stderr, + "%s: end LSN (%d) needs to be less than start LSN (%d)\n", + program_name, opts.start_lsn, opts.end_lsn); + exit(12); + } + if (opts.num_sectors != opts.end_lsn - opts.start_lsn + 1) + if (opts.num_sectors != 0) { + fprintf(stderr, + "%s: inconsistency between start LSN (%d), end (%d), " + "and count (%d)\n", + program_name, opts.start_lsn, opts.end_lsn, opts.num_sectors); + exit(13); + } + opts.num_sectors = opts.end_lsn - opts.start_lsn + 1; } - + return true; } @@ -315,6 +341,19 @@ log_handler (cdio_log_level_t level, const char message[]) } +static void +init(void) +{ + opts.debug_level = 0; + opts.start_lsn = 0; + opts.end_lsn = CDIO_INVALID_LSN; + opts.num_sectors = 0; + opts.read_mode = READ_MODE_UNINIT; + opts.source_image = IMAGE_UNKNOWN; + + gl_default_cdio_log_handler = cdio_log_set_handler (log_handler); +} + int main(int argc, const char *argv[]) { @@ -322,15 +361,7 @@ main(int argc, const char *argv[]) unsigned int blocklen=CDIO_CD_FRAMESIZE_RAW; CdIo *cdio=NULL; - program_name = strrchr(argv[0],'/'); - program_name = program_name ? program_name+1 : strdup(argv[0]); - - opts.debug_level = 0; - opts.start_lsn = CDIO_INVALID_LSN; - opts.read_mode = READ_MODE_UNINIT; - opts.source_image = IMAGE_UNKNOWN; - - gl_default_cdio_log_handler = cdio_log_set_handler (log_handler); + init(); /* Parse our arguments; every option seen by `parse_opt' will be reflected in `arguments'. */ @@ -377,29 +408,36 @@ main(int argc, const char *argv[]) break; } - switch (opts.read_mode) { - case READ_AUDIO: - cdio_read_audio_sector(cdio, &buffer, opts.start_lsn); - break; - case READ_M1F1: - cdio_read_mode1_sector(cdio, &buffer, opts.start_lsn, false); - blocklen=CDIO_CD_FRAMESIZE; - break; - case READ_M1F2: - cdio_read_mode1_sector(cdio, &buffer, opts.start_lsn, true); - break; - case READ_M2F1: - cdio_read_mode2_sector(cdio, &buffer, opts.start_lsn, false); - break; - case READ_M2F2: - cdio_read_mode2_sector(cdio, &buffer, opts.start_lsn, true); - break; - case READ_MODE_UNINIT: - err_exit("%s: Reading mode not set\n", program_name); - break; + + for ( ; opts.start_lsn <= opts.end_lsn; opts.start_lsn++ ) { + switch (opts.read_mode) { + case READ_AUDIO: + cdio_read_audio_sector(cdio, &buffer, opts.start_lsn); + break; + case READ_M1F1: + cdio_read_mode1_sector(cdio, &buffer, opts.start_lsn, false); + blocklen=CDIO_CD_FRAMESIZE; + break; + case READ_M1F2: + cdio_read_mode1_sector(cdio, &buffer, opts.start_lsn, true); + blocklen=M2RAW_SECTOR_SIZE; + break; + case READ_M2F1: + cdio_read_mode2_sector(cdio, &buffer, opts.start_lsn, false); + blocklen=CDIO_CD_FRAMESIZE; + break; + case READ_M2F2: + blocklen=M2F2_SECTOR_SIZE; + cdio_read_mode2_sector(cdio, &buffer, opts.start_lsn, true); + break; + case READ_MODE_UNINIT: + err_exit("%s: Reading mode not set\n", program_name); + break; + } + + hexdump(buffer, blocklen); } - hexdump(buffer, blocklen); cdio_destroy(cdio); return 0; } diff --git a/test/check_cd_read.sh b/test/check_cd_read.sh index 922e4a98..f462c323 100755 --- a/test/check_cd_read.sh +++ b/test/check_cd_read.sh @@ -1,5 +1,5 @@ #!/bin/sh -#$Id: check_cd_read.sh,v 1.4 2003/09/21 03:35:40 rocky Exp $ +#$Id: check_cd_read.sh,v 1.5 2003/09/21 18:43:36 rocky Exp $ # # Copyright (C) 2003 Rocky Bernstein # @@ -40,7 +40,7 @@ check_result $RC "cd-read CUE test $testnum" fname=isofs-m1 testnum=MODE1 -test_cd_read "-i ${srcdir}/${fname}.cue --mode m1f1 -s 26" \ +test_cd_read "-i ${srcdir}/${fname}.cue --mode m1f1 -s 26 -n 2" \ ${fname}-read.dump ${srcdir}/${fname}-read.right RC=$? check_result $RC "cd-read CUE test $testnum" diff --git a/test/isofs-m1-read.right b/test/isofs-m1-read.right index 7d14446b..96c50a7b 100644 --- a/test/isofs-m1-read.right +++ b/test/isofs-m1-read.right @@ -127,3 +127,132 @@ 0x07e0: 7920 7468 6520 736f 6674 7761 7265 2e0a y the software.. 0x07f0: 0a20 2041 6c73 6f2c 2066 6f72 2065 6163 . Also, for eac +0x0000: 6820 6175 7468 6f72 2773 2070 726f 7465 h author's prote +0x0010: 6374 696f 6e20 616e 6420 6f75 7273 2c20 ction and ours, +0x0020: 7765 2077 616e 7420 746f 206d 616b 6520 we want to make +0x0030: 6365 7274 6169 6e0a 7468 6174 2065 7665 certain.that eve +0x0040: 7279 6f6e 6520 756e 6465 7273 7461 6e64 ryone understand +0x0050: 7320 7468 6174 2074 6865 7265 2069 7320 s that there is +0x0060: 6e6f 2077 6172 7261 6e74 7920 666f 7220 no warranty for +0x0070: 7468 6973 2066 7265 650a 736f 6674 7761 this free.softwa +0x0080: 7265 2e20 2049 6620 7468 6520 736f 6674 re. If the soft +0x0090: 7761 7265 2069 7320 6d6f 6469 6669 6564 ware is modified +0x00a0: 2062 7920 736f 6d65 6f6e 6520 656c 7365 by someone else +0x00b0: 2061 6e64 2070 6173 7365 6420 6f6e 2c20 and passed on, +0x00c0: 7765 0a77 616e 7420 6974 7320 7265 6369 we.want its reci +0x00d0: 7069 656e 7473 2074 6f20 6b6e 6f77 2074 pients to know t +0x00e0: 6861 7420 7768 6174 2074 6865 7920 6861 hat what they ha +0x00f0: 7665 2069 7320 6e6f 7420 7468 6520 6f72 ve is not the or +0x0100: 6967 696e 616c 2c20 736f 0a74 6861 7420 iginal, so.that +0x0110: 616e 7920 7072 6f62 6c65 6d73 2069 6e74 any problems int +0x0120: 726f 6475 6365 6420 6279 206f 7468 6572 roduced by other +0x0130: 7320 7769 6c6c 206e 6f74 2072 6566 6c65 s will not refle +0x0140: 6374 206f 6e20 7468 6520 6f72 6967 696e ct on the origin +0x0150: 616c 0a61 7574 686f 7273 2720 7265 7075 al.authors' repu +0x0160: 7461 7469 6f6e 732e 0a0a 2020 4669 6e61 tations... Fina +0x0170: 6c6c 792c 2061 6e79 2066 7265 6520 7072 lly, any free pr +0x0180: 6f67 7261 6d20 6973 2074 6872 6561 7465 ogram is threate +0x0190: 6e65 6420 636f 6e73 7461 6e74 6c79 2062 ned constantly b +0x01a0: 7920 736f 6674 7761 7265 0a70 6174 656e y software.paten +0x01b0: 7473 2e20 2057 6520 7769 7368 2074 6f20 ts. We wish to +0x01c0: 6176 6f69 6420 7468 6520 6461 6e67 6572 avoid the danger +0x01d0: 2074 6861 7420 7265 6469 7374 7269 6275 that redistribu +0x01e0: 746f 7273 206f 6620 6120 6672 6565 0a70 tors of a free.p +0x01f0: 726f 6772 616d 2077 696c 6c20 696e 6469 rogram will indi +0x0200: 7669 6475 616c 6c79 206f 6274 6169 6e20 vidually obtain +0x0210: 7061 7465 6e74 206c 6963 656e 7365 732c patent licenses, +0x0220: 2069 6e20 6566 6665 6374 206d 616b 696e in effect makin +0x0230: 6720 7468 650a 7072 6f67 7261 6d20 7072 g the.program pr +0x0240: 6f70 7269 6574 6172 792e 2020 546f 2070 oprietary. To p +0x0250: 7265 7665 6e74 2074 6869 732c 2077 6520 revent this, we +0x0260: 6861 7665 206d 6164 6520 6974 2063 6c65 have made it cle +0x0270: 6172 2074 6861 7420 616e 790a 7061 7465 ar that any.pate +0x0280: 6e74 206d 7573 7420 6265 206c 6963 656e nt must be licen +0x0290: 7365 6420 666f 7220 6576 6572 796f 6e65 sed for everyone +0x02a0: 2773 2066 7265 6520 7573 6520 6f72 206e 's free use or n +0x02b0: 6f74 206c 6963 656e 7365 6420 6174 2061 ot licensed at a +0x02c0: 6c6c 2e0a 0a20 2054 6865 2070 7265 6369 ll... The preci +0x02d0: 7365 2074 6572 6d73 2061 6e64 2063 6f6e se terms and con +0x02e0: 6469 7469 6f6e 7320 666f 7220 636f 7079 ditions for copy +0x02f0: 696e 672c 2064 6973 7472 6962 7574 696f ing, distributio +0x0300: 6e20 616e 640a 6d6f 6469 6669 6361 7469 n and.modificati +0x0310: 6f6e 2066 6f6c 6c6f 772e 0a0c 0a09 0920 on follow...... +0x0320: 2020 2047 4e55 2047 454e 4552 414c 2050 GNU GENERAL P +0x0330: 5542 4c49 4320 4c49 4345 4e53 450a 2020 UBLIC LICENSE. +0x0340: 2054 4552 4d53 2041 4e44 2043 4f4e 4449 TERMS AND CONDI +0x0350: 5449 4f4e 5320 464f 5220 434f 5059 494e TIONS FOR COPYIN +0x0360: 472c 2044 4953 5452 4942 5554 494f 4e20 G, DISTRIBUTION +0x0370: 414e 4420 4d4f 4449 4649 4341 5449 4f4e AND MODIFICATION +0x0380: 0a0a 2020 302e 2054 6869 7320 4c69 6365 .. 0. This Lice +0x0390: 6e73 6520 6170 706c 6965 7320 746f 2061 nse applies to a +0x03a0: 6e79 2070 726f 6772 616d 206f 7220 6f74 ny program or ot +0x03b0: 6865 7220 776f 726b 2077 6869 6368 2063 her work which c +0x03c0: 6f6e 7461 696e 730a 6120 6e6f 7469 6365 ontains.a notice +0x03d0: 2070 6c61 6365 6420 6279 2074 6865 2063 placed by the c +0x03e0: 6f70 7972 6967 6874 2068 6f6c 6465 7220 opyright holder +0x03f0: 7361 7969 6e67 2069 7420 6d61 7920 6265 saying it may be +0x0400: 2064 6973 7472 6962 7574 6564 0a75 6e64 distributed.und +0x0410: 6572 2074 6865 2074 6572 6d73 206f 6620 er the terms of +0x0420: 7468 6973 2047 656e 6572 616c 2050 7562 this General Pub +0x0430: 6c69 6320 4c69 6365 6e73 652e 2020 5468 lic License. Th +0x0440: 6520 2250 726f 6772 616d 222c 2062 656c e "Program", bel +0x0450: 6f77 2c0a 7265 6665 7273 2074 6f20 616e ow,.refers to an +0x0460: 7920 7375 6368 2070 726f 6772 616d 206f y such program o +0x0470: 7220 776f 726b 2c20 616e 6420 6120 2277 r work, and a "w +0x0480: 6f72 6b20 6261 7365 6420 6f6e 2074 6865 ork based on the +0x0490: 2050 726f 6772 616d 220a 6d65 616e 7320 Program".means +0x04a0: 6569 7468 6572 2074 6865 2050 726f 6772 either the Progr +0x04b0: 616d 206f 7220 616e 7920 6465 7269 7661 am or any deriva +0x04c0: 7469 7665 2077 6f72 6b20 756e 6465 7220 tive work under +0x04d0: 636f 7079 7269 6768 7420 6c61 773a 0a74 copyright law:.t +0x04e0: 6861 7420 6973 2074 6f20 7361 792c 2061 hat is to say, a +0x04f0: 2077 6f72 6b20 636f 6e74 6169 6e69 6e67 work containing +0x0500: 2074 6865 2050 726f 6772 616d 206f 7220 the Program or +0x0510: 6120 706f 7274 696f 6e20 6f66 2069 742c a portion of it, +0x0520: 0a65 6974 6865 7220 7665 7262 6174 696d .either verbatim +0x0530: 206f 7220 7769 7468 206d 6f64 6966 6963 or with modific +0x0540: 6174 696f 6e73 2061 6e64 2f6f 7220 7472 ations and/or tr +0x0550: 616e 736c 6174 6564 2069 6e74 6f20 616e anslated into an +0x0560: 6f74 6865 720a 6c61 6e67 7561 6765 2e20 other.language. +0x0570: 2028 4865 7265 696e 6166 7465 722c 2074 (Hereinafter, t +0x0580: 7261 6e73 6c61 7469 6f6e 2069 7320 696e ranslation is in +0x0590: 636c 7564 6564 2077 6974 686f 7574 206c cluded without l +0x05a0: 696d 6974 6174 696f 6e20 696e 0a74 6865 imitation in.the +0x05b0: 2074 6572 6d20 226d 6f64 6966 6963 6174 term "modificat +0x05c0: 696f 6e22 2e29 2020 4561 6368 206c 6963 ion".) Each lic +0x05d0: 656e 7365 6520 6973 2061 6464 7265 7373 ensee is address +0x05e0: 6564 2061 7320 2279 6f75 222e 0a0a 4163 ed as "you"...Ac +0x05f0: 7469 7669 7469 6573 206f 7468 6572 2074 tivities other t +0x0600: 6861 6e20 636f 7079 696e 672c 2064 6973 han copying, dis +0x0610: 7472 6962 7574 696f 6e20 616e 6420 6d6f tribution and mo +0x0620: 6469 6669 6361 7469 6f6e 2061 7265 206e dification are n +0x0630: 6f74 0a63 6f76 6572 6564 2062 7920 7468 ot.covered by th +0x0640: 6973 204c 6963 656e 7365 3b20 7468 6579 is License; they +0x0650: 2061 7265 206f 7574 7369 6465 2069 7473 are outside its +0x0660: 2073 636f 7065 2e20 2054 6865 2061 6374 scope. The act +0x0670: 206f 660a 7275 6e6e 696e 6720 7468 6520 of.running the +0x0680: 5072 6f67 7261 6d20 6973 206e 6f74 2072 Program is not r +0x0690: 6573 7472 6963 7465 642c 2061 6e64 2074 estricted, and t +0x06a0: 6865 206f 7574 7075 7420 6672 6f6d 2074 he output from t +0x06b0: 6865 2050 726f 6772 616d 0a69 7320 636f he Program.is co +0x06c0: 7665 7265 6420 6f6e 6c79 2069 6620 6974 vered only if it +0x06d0: 7320 636f 6e74 656e 7473 2063 6f6e 7374 s contents const +0x06e0: 6974 7574 6520 6120 776f 726b 2062 6173 itute a work bas +0x06f0: 6564 206f 6e20 7468 650a 5072 6f67 7261 ed on the.Progra +0x0700: 6d20 2869 6e64 6570 656e 6465 6e74 206f m (independent o +0x0710: 6620 6861 7669 6e67 2062 6565 6e20 6d61 f having been ma +0x0720: 6465 2062 7920 7275 6e6e 696e 6720 7468 de by running th +0x0730: 6520 5072 6f67 7261 6d29 2e0a 5768 6574 e Program)..Whet +0x0740: 6865 7220 7468 6174 2069 7320 7472 7565 her that is true +0x0750: 2064 6570 656e 6473 206f 6e20 7768 6174 depends on what +0x0760: 2074 6865 2050 726f 6772 616d 2064 6f65 the Program doe +0x0770: 732e 0a0a 2020 312e 2059 6f75 206d 6179 s... 1. You may +0x0780: 2063 6f70 7920 616e 6420 6469 7374 7269 copy and distri +0x0790: 6275 7465 2076 6572 6261 7469 6d20 636f bute verbatim co +0x07a0: 7069 6573 206f 6620 7468 6520 5072 6f67 pies of the Prog +0x07b0: 7261 6d27 730a 736f 7572 6365 2063 6f64 ram's.source cod +0x07c0: 6520 6173 2079 6f75 2072 6563 6569 7665 e as you receive +0x07d0: 2069 742c 2069 6e20 616e 7920 6d65 6469 it, in any medi +0x07e0: 756d 2c20 7072 6f76 6964 6564 2074 6861 um, provided tha +0x07f0: 7420 796f 750a 636f 6e73 7069 6375 6f75 t you.conspicuou +