int remove_main (int argc, char **argv) { if (argc < 2) { return remove_usage (); } /*-------defaults for bloom filter building-------*/ int opt; float tole_rate = 0; char *ref = NULL, *list = NULL, *target_path = NULL, *source = NULL, *report_fmt = "json"; while ((opt = getopt (argc, argv, "l:t:r:o:q:f:h")) != -1) { switch (opt) { case 't': (optarg) && ((tole_rate = atof (optarg)), 1); break; case 'o': (optarg) && ((target_path = optarg), 1); break; case 'q': (optarg) && (source = optarg, 1); break; case 'r': (optarg) && (ref = optarg, 1); break; case 'l': (optarg) && ((list = optarg), 1); break; case 'f': // "json", "tsv" or none (optarg) && (report_fmt = optarg, 1); break; case 'h': return remove_usage (); default: printf ("Unknown option: -%c\n", (char) optopt); return remove_usage (); } } if (!target_path && !source) { fprintf (stderr, "\nPlease, at least specify a bloom filter (-r) and a query file (-q)\n"); exit (-1); } char *result = query(source, ref, tole_rate, 1.000, list, target_path, report_fmt, 'r'); printf("%s\n",result); return 1; }
static int remove_cmd(int argc, char *argv[]) { struct option opts[toc_entries_len + 2]; char outfile[FILENAME_MAX] = { 0 }; fip_toc_header_t toc_header; toc_entry_t *toc_entry; int fflag = 0; int i; if (argc < 2) remove_usage(); i = fill_common_opts(opts, no_argument); add_opt(opts, i, "force", no_argument, 'f'); add_opt(opts, ++i, "out", required_argument, 'o'); add_opt(opts, ++i, NULL, 0, 0); while (1) { int c, opt_index; c = getopt_long(argc, argv, "fo:", opts, &opt_index); if (c == -1) break; switch (c) { case OPT_TOC_ENTRY: toc_entry = &toc_entries[opt_index]; toc_entry->action = DO_REMOVE; break; case 'f': fflag = 1; break; case 'o': snprintf(outfile, sizeof(outfile), "%s", optarg); break; default: remove_usage(); } } argc -= optind; argv += optind; if (argc == 0) remove_usage(); if (outfile[0] != '\0' && access(outfile, F_OK) == 0 && !fflag) log_errx("File %s already exists, use --force to overwrite it", outfile); if (outfile[0] == '\0') snprintf(outfile, sizeof(outfile), "%s", argv[0]); parse_fip(argv[0], &toc_header); for (toc_entry = toc_entries; toc_entry->cmdline_name != NULL; toc_entry++) { image_t *image; if (toc_entry->action != DO_REMOVE) continue; image = lookup_image_from_uuid(&toc_entry->uuid); if (image != NULL) { if (verbose) log_dbgx("Removing %s.bin", toc_entry->cmdline_name); remove_image(image); } else { log_warnx("Requested image %s.bin is not in %s", toc_entry->cmdline_name, argv[0]); } } pack_images(outfile, toc_header.flags); free_images(); return 0; }
static int remove_cmd(int argc, char *argv[]) { struct option *opts = NULL; size_t nr_opts = 0; char outfile[PATH_MAX] = { 0 }; fip_toc_header_t toc_header; image_desc_t *desc; unsigned long align = 1; int fflag = 0; if (argc < 2) remove_usage(); opts = fill_common_opts(opts, &nr_opts, no_argument); opts = add_opt(opts, &nr_opts, "align", required_argument, OPT_ALIGN); opts = add_opt(opts, &nr_opts, "blob", required_argument, 'b'); opts = add_opt(opts, &nr_opts, "force", no_argument, 'f'); opts = add_opt(opts, &nr_opts, "out", required_argument, 'o'); opts = add_opt(opts, &nr_opts, NULL, 0, 0); while (1) { int c, opt_index = 0; c = getopt_long(argc, argv, "b:fo:", opts, &opt_index); if (c == -1) break; switch (c) { case OPT_TOC_ENTRY: { image_desc_t *desc; desc = lookup_image_desc_from_opt(opts[opt_index].name); set_image_desc_action(desc, DO_REMOVE, NULL); break; } case OPT_ALIGN: align = get_image_align(optarg); break; case 'b': { char name[_UUID_STR_LEN + 1], filename[PATH_MAX]; uuid_t uuid = { 0 }; image_desc_t *desc; parse_blob_opt(optarg, &uuid, filename, sizeof(filename)); if (memcmp(&uuid, &uuid_null, sizeof(uuid_t)) == 0) remove_usage(); desc = lookup_image_desc_from_uuid(&uuid); if (desc == NULL) { uuid_to_str(name, sizeof(name), &uuid); desc = new_image_desc(&uuid, name, "blob"); add_image_desc(desc); } set_image_desc_action(desc, DO_REMOVE, NULL); break; } case 'f': fflag = 1; break; case 'o': snprintf(outfile, sizeof(outfile), "%s", optarg); break; default: remove_usage(); } } argc -= optind; argv += optind; free(opts); if (argc == 0) remove_usage(); if (outfile[0] != '\0' && access(outfile, F_OK) == 0 && !fflag) log_errx("File %s already exists, use --force to overwrite it", outfile); if (outfile[0] == '\0') snprintf(outfile, sizeof(outfile), "%s", argv[0]); parse_fip(argv[0], &toc_header); for (desc = image_desc_head; desc != NULL; desc = desc->next) { if (desc->action != DO_REMOVE) continue; if (desc->image != NULL) { if (verbose) log_dbgx("Removing %s", desc->cmdline_name); free(desc->image); desc->image = NULL; } else { log_warnx("%s does not exist in %s", desc->cmdline_name, argv[0]); } } pack_images(outfile, toc_header.flags, align); return 0; }