status_t read_table_of_contents(int fd, scsi_toc_toc *toc, size_t length) { status_t status = read_table_of_contents(fd, 1, SCSI_TOC_FORMAT_TOC, (uint8*)toc, length); if (status < B_OK) return status; // make sure the values in the TOC make sense int32 lastTrack = toc->last_track + 1 - toc->first_track; size_t dataLength = B_BENDIAN_TO_HOST_INT16(toc->data_length) + 2; if (dataLength < sizeof(scsi_toc_toc) || lastTrack <= 0) return B_BAD_DATA; if (length > dataLength) length = dataLength; length -= sizeof(scsi_toc_general); if (lastTrack * sizeof(scsi_toc_track) > length) toc->last_track = length / sizeof(scsi_toc_track) + toc->first_track; dump_toc(toc); return B_OK; }
/* Work through command-line options */ static int parse_cmdline(int argc, char **argv, struct option *options, int *do_pack) { int c; int status = 0; int option_index = 0; entry_lookup_list_t *lookup_entry; int do_dump = 0; /* restart parse to process all options. starts at 1. */ optind = 1; while (1) { c = getopt_long(argc, argv, "", options, &option_index); if (c == -1) break; switch (c) { case OPT_TOC_ENTRY: if (optarg) { /* Does the option expect a filename. */ lookup_entry = &toc_entry_lookup_list[option_index]; if (lookup_entry->flags & FLAG_FILENAME) { status = add_file_info_entry(lookup_entry, optarg); if (status != 0) { printf("Failed to process %s\n", options[option_index].name); return status; } else { /* Update package */ *do_pack = 1; } } } break; case OPT_DUMP: do_dump = 1; continue; case OPT_HELP: print_usage(); exit(0); default: /* Unrecognised options are caught in get_filename() */ break; } } /* Do not dump toc if we have an error as it could hide the error */ if ((status == 0) && (do_dump)) { dump_toc(); } return status; }