int main(int argc, char **argv) { int ch; int layout = 0; /* handle command line options */ opt_list = 0; opt_verbose = 0; opt_skip = 0; while ((ch = getopt(argc, argv, "l:tsvVh?")) > 0) { switch (ch) { case 'l': if (optarg[0] < '0' || optarg[0] > '0' + max_layout || optarg[1] != '\0') usage(); layout = optarg[0] - '0'; break; case 't': opt_list = 1; break; case 'v': opt_verbose = 1; break; case 's': opt_skip = 1; break; case 'V': printf("V%s\n", VERSION); exit(0); break; case 'h': case '?': default: usage(); break; } } /* extract rest of command line parameters */ if ((argc - optind) < 1 || (argc - optind) > 2) usage(); if (strcmp(argv[optind], "-") == 0) { /* image file from stdin ? */ img_file = 0; } else { img_file = open(argv[optind], O_RDONLY); if (img_file < 0) prt_err(1, errno, "Open image file failed"); } if (layout == 0) { detect_chunk_size(); } else { chunk_size = possible_layouts[layout-1].chunk_size; spare_size = possible_layouts[layout-1].spare_size; } spare_data = data + chunk_size; // Skip first chunk if (opt_skip) lseek(img_file, chunk_size+spare_size, SEEK_SET); if ((argc - optind) == 2 && !opt_list) { if (mkdirpath(argv[optind+1]) < 0) prt_err(1, errno, "Can't mkdir %s", argv[optind+1]); if (chdir(argv[optind+1]) < 0) prt_err(1, errno, "Can't chdir to %s", argv[optind+1]); } umask(0); init_obj_list(); while (read_chunk()) { process_chunk(); } set_dirs_utime(); close(img_file); return 0; }
int main(int argc, char **argv) { int ch; char *ep; int opt_detect; int opt_bad; int opt_chunk; int opt_spare; /* handle command line options */ opt_detect = 0; opt_bad = 0; opt_chunk = 0; opt_spare = 0; opt_list = 0; opt_verbose = 0; while ((ch = getopt(argc, argv, "dbc:s:tvVh?")) > 0) { switch (ch) { case 'd': opt_detect = 1; break; case 'b': opt_bad = 1; break; case 'c': opt_chunk = strtol(optarg, &ep, 0); if (*ep != '\0' || opt_chunk < 0 || opt_chunk > (MAX_CHUNK_SIZE / 1024) ) usage(); break; case 's': opt_spare = strtol(optarg, &ep, 0); if (*ep != '\0' || opt_spare < 0 || opt_spare > MAX_SPARE_SIZE) usage(); break; case 't': opt_list = 1; break; case 'v': opt_verbose = 1; break; case 'V': printf("V%s\n", VERSION); exit(0); break; case 'h': case '?': default: usage(); break; } } /* extract rest of command line parameters */ if ((argc - optind) < 1 || (argc - optind) > 2) usage(); if (strcmp(argv[optind], "-") == 0) { /* image file from stdin ? */ img_file = 0; } else { img_file = open(argv[optind], O_RDONLY); if (img_file < 0) prt_err(1, errno, "Open image file failed"); } if (opt_detect) { detect_flash_layout(1, 0); return 0; } if (opt_chunk == 0 || opt_spare == 0) { detect_flash_layout(0, 1); if (opt_verbose) prt_err(0, 0, "Header check OK, chunk size = %dK, spare size = %d, %sbad block info.", chunk_size/1024, spare_size, spare_off ? "" : "no "); } else { chunk_size = opt_chunk * 1024; spare_size = opt_spare; spare_off = opt_bad ? 2 : 0; } spare_data = data + chunk_size; if ((argc - optind) == 2 && !opt_list) { if (mkdirpath(argv[optind+1], 0755) < 0) prt_err(1, errno, "Can't mkdir %s", argv[optind+1]); if (chdir(argv[optind+1]) < 0) prt_err(1, errno, "Can't chdir to %s", argv[optind+1]); } umask(0); init_obj_list(); saved_chunk.objectId = 0; while (read_chunk()) { process_chunk(); } set_dirs_utime(); close(img_file); if (warn_chown) #ifdef __CYGWIN__ prt_err(0, 0, "Warning: Can't restore owner/group attribute (limitation of Cygwin/Windows)"); #else prt_err(0, 0, "Warning: Can't restore owner/group attribute, run unyaffs as root"); #endif return 0; }