int cmd_boot(int argc, char *argv[]) { int ch, fd; while ((ch = getopt(argc, argv, "")) != -1) { switch(ch) { default: usage_boot(); } } if (argc == optind) usage_boot(); while (optind < argc) { fd = gpt_open(argv[optind++]); if (fd == -1) { warn("unable to open device '%s'", device_name); continue; } bootset(fd); gpt_close(fd); } return (0); }
int cmd_show(int argc, char *argv[]) { int ch, fd; while ((ch = getopt(argc, argv, "lu")) != -1) { switch(ch) { case 'l': show_label = 1; break; case 'u': show_uuid = 1; break; default: usage_show(); } } if (argc == optind) usage_show(); while (optind < argc) { fd = gpt_open(argv[optind++]); if (fd == -1) { warn("unable to open device '%s'", device_name); continue; } show(fd); gpt_close(fd); } return (0); }
int cmd_destroy(int argc, char *argv[]) { int ch; int flags = 0; gd_t gd; while ((ch = getopt(argc, argv, "r")) != -1) { switch(ch) { case 'r': recoverable = 1; break; default: usage_destroy(); } } if (argc == optind) usage_destroy(); while (optind < argc) { gd = gpt_open(argv[optind++], flags); if (gd == NULL) { continue; } destroy(gd); gpt_close(gd); } return (0); }
int cmd_recover(int argc, char *argv[]) { int ch, fd; while ((ch = getopt(argc, argv, "r")) != -1) { switch(ch) { case 'r': recoverable = 1; break; default: usage_recover(); } } if (argc == optind) usage_recover(); while (optind < argc) { fd = gpt_open(argv[optind++]); if (fd == -1) { warn("unable to open device '%s'", device_name); continue; } recover(fd); gpt_close(fd); } return (0); }
TSK_MM_INFO * tsk_mm_gpt_open(TSK_IMG_INFO * img_info, DADDR_T offset) { TSK_MM_INFO *mm; // clean up any errors that are lying around tsk_error_reset(); mm = (TSK_MM_INFO *) tsk_malloc(sizeof(*mm)); if (mm == NULL) return NULL; mm->img_info = img_info; mm->mmtype = TSK_MM_INFO_TYPE_GPT; mm->str_type = "GUID Partition Table"; /* If an offset was given, then use that too */ mm->offset = offset; /* inititialize settings */ mm->part_list = NULL; mm->first_part = mm->last_part = 0; mm->endian = 0; mm->dev_bsize = 512; mm->block_size = 512; /* Assign functions */ mm->part_walk = gpt_part_walk; mm->close = gpt_close; /* Load the partitions into the sorted list */ if (gpt_load_table(mm)) { gpt_close(mm); return NULL; } /* fill in the sorted list with the 'unknown' values */ if (tsk_mm_part_unused(mm)) { gpt_close(mm); return NULL; } return mm; }
TSK_VS_INFO * tsk_vs_gpt_open(TSK_IMG_INFO * img_info, TSK_DADDR_T offset) { TSK_VS_INFO *vs; // clean up any errors that are lying around tsk_error_reset(); vs = (TSK_VS_INFO *) tsk_malloc(sizeof(*vs)); if (vs == NULL) return NULL; vs->img_info = img_info; vs->vstype = TSK_VS_TYPE_GPT; vs->tag = TSK_VS_INFO_TAG; /* If an offset was given, then use that too */ vs->offset = offset; /* inititialize settings */ vs->part_list = NULL; vs->part_count = 0; vs->endian = 0; vs->block_size = img_info->sector_size; /* Assign functions */ vs->close = gpt_close; /* Load the partitions into the sorted list */ if (gpt_load_table(vs)) { int found = 0; if (tsk_verbose) tsk_fprintf(stderr, "gpt_open: Trying other sector sizes\n"); /* Before we give up, lets try some other sector sizes */ vs->block_size = 512; while (vs->block_size <= 8192) { if (tsk_verbose) tsk_fprintf(stderr, "gpt_open: Trying sector size: %d\n", vs->block_size); if (gpt_load_table(vs)) { vs->block_size *= 2; continue; } found = 1; break; } if (found == 0) { gpt_close(vs); return NULL; } } /* fill in the sorted list with the 'unknown' values */ if (tsk_vs_part_unused(vs)) { gpt_close(vs); return NULL; } return vs; }
int cmd_remove(int argc, char *argv[]) { char *p; int ch; int flags = 0; gd_t gd; /* Get the remove options */ while ((ch = getopt(argc, argv, "ab:i:s:t:")) != -1) { switch(ch) { case 'a': if (all > 0) usage_remove(); all = 1; break; case 'b': if (block > 0) usage_remove(); block = strtoll(optarg, &p, 10); if (*p != 0 || block < 1) usage_remove(); break; case 'i': if (entry > 0) usage_remove(); entry = strtol(optarg, &p, 10); if (*p != 0 || entry < 1) usage_remove(); break; case 's': if (size > 0) usage_remove(); size = strtoll(optarg, &p, 10); if (*p != 0 || size < 1) usage_remove(); break; case 't': if (!uuid_is_nil(&type, NULL)) usage_remove(); if (parse_uuid(optarg, &type) != 0) usage_remove(); break; default: usage_remove(); } } if (!all ^ (block > 0 || entry > 0 || size > 0 || !uuid_is_nil(&type, NULL))) usage_remove(); if (argc == optind) usage_remove(); while (optind < argc) { gd = gpt_open(argv[optind++], flags); if (gd == NULL) { continue; } rem(gd); gpt_close(gd); } return (0); }
int cmd_remove(int argc, char *argv[]) { char *p; int ch, fd; /* Get the remove options */ while ((ch = getopt(argc, argv, "ab:i:s:t:")) != -1) { switch(ch) { case 'a': if (all > 0) usage_remove(); all = 1; break; case 'b': if (block > 0) usage_remove(); block = strtoll(optarg, &p, 10); if (*p != 0 || block < 1) usage_remove(); break; case 'i': if (entry != NOENTRY) usage_remove(); entry = strtoul(optarg, &p, 10); if (*p != 0 || entry == NOENTRY) usage_remove(); break; case 's': if (size > 0) usage_remove(); size = strtoll(optarg, &p, 10); if (*p != 0 || size < 1) usage_remove(); break; case 't': if (!uuid_is_nil(&type, NULL)) usage_remove(); if (parse_uuid(optarg, &type) != 0) usage_remove(); break; default: usage_remove(); } } if (!all ^ (block > 0 || entry != NOENTRY || size > 0 || !uuid_is_nil(&type, NULL))) usage_remove(); if (argc == optind) usage_remove(); while (optind < argc) { fd = gpt_open(argv[optind++]); if (fd == -1) { warn("unable to open device '%s'", device_name); continue; } rem(fd); gpt_close(fd); } return (0); }
int cmd_add(int argc, char *argv[]) { char *p; int ch, fd; /* Get the migrate options */ while ((ch = getopt(argc, argv, "b:i:s:t:")) != -1) { switch(ch) { case 'b': if (block > 0) usage_add(); block = strtoll(optarg, &p, 10); if (*p != 0 || block < 1) usage_add(); break; case 'i': if (entry != NOENTRY) usage_add(); entry = strtoul(optarg, &p, 10); if (*p != 0 || entry == NOENTRY) usage_add(); break; case 's': if (size > 0) usage_add(); size = strtoll(optarg, &p, 10); if (*p != 0 || size < 1) usage_add(); break; case 't': if (!uuid_is_nil(&type, NULL)) usage_add(); if (parse_uuid(optarg, &type) != 0) usage_add(); break; default: usage_add(); } } if (argc == optind) usage_add(); /* Create DragonFly 64 bit label partitions by default. */ if (uuid_is_nil(&type, NULL)) { uint32_t status; uuid_name_lookup(&type, "DragonFly Label64", &status); if (status != uuid_s_ok) err(1, "unable to find uuid for 'DragonFly Label64'"); } while (optind < argc) { fd = gpt_open(argv[optind++]); if (fd == -1) { warn("unable to open device '%s'", device_name); continue; } add(fd); gpt_close(fd); } return (0); }
static int cmd_biosboot(gpt_t gpt, int argc, char *argv[]) { #ifdef DIOCGWEDGEINFO struct dkwedge_info dkw; #endif int ch; gpt_t ngpt = gpt; daddr_t start = 0; uint64_t size = 0; unsigned int entry = 0; uint8_t *label = NULL; char *bootpath = NULL; while ((ch = getopt(argc, argv, "c:i:L:")) != -1) { switch(ch) { case 'c': if (gpt_name_get(gpt, &bootpath) == -1) goto usage; break; case 'i': if (gpt_uint_get(gpt, &entry) == -1) goto usage; break; case 'L': if (gpt_name_get(gpt, &label) == -1) goto usage; break; default: goto usage; } } if (argc != optind) return usage(); #ifdef DIOCGWEDGEINFO if ((gpt->sb.st_mode & S_IFMT) != S_IFREG && ioctl(gpt->fd, DIOCGWEDGEINFO, &dkw) != -1) { if (entry > 0) /* wedges and indexes are mutually exclusive */ goto usage; start = dkw.dkw_offset; size = dkw.dkw_size; ngpt = gpt_open(dkw.dkw_parent, gpt->flags, gpt->verbose, gpt->mediasz, gpt->secsz); if (ngpt == NULL) goto cleanup; } #endif if (biosboot(ngpt, start, size, entry, label, bootpath) == -1) goto cleanup; if (ngpt != gpt) gpt_close(ngpt); return 0; usage: usage(); cleanup: if (ngpt != gpt) gpt_close(ngpt); free(bootpath); free(label); return -1; }