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_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_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); }
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); }
/* * THe main wrapper function for opening an image * * Offset is the byte offset to the start of the volume system */ MM_INFO * mm_open(IMG_INFO * img_info, DADDR_T offset, const char *type) { /* Autodetect mode * We need to try all of them in case there are multiple * installations * * * NOte that errors that are encountered during the testing process * will not be reported */ if (type == NULL) { MM_INFO *mm_info, *mm_set = NULL; char *set = NULL; if ((mm_info = dos_open(img_info, offset, 1)) != NULL) { set = "DOS"; mm_set = mm_info; } else { tsk_errno = 0; tsk_errstr[0] = '\0'; tsk_errstr2[0] = '\0'; } if ((mm_info = bsd_open(img_info, offset)) != NULL) { // if (set == NULL) { // In this case, BSD takes priority because BSD partitions start off with // the DOS magic value in the first sector with the boot code. set = "BSD"; mm_set = mm_info; /* } else { mm_set->close(mm_set); mm_info->close(mm_info); tsk_errno = TSK_ERR_MM_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "BSD or %s at %" PRIuDADDR, set, offset); tsk_errstr2[0] = '\0'; return NULL; } */ } else { tsk_errno = 0; tsk_errstr[0] = '\0'; tsk_errstr2[0] = '\0'; } if ((mm_info = gpt_open(img_info, offset)) != NULL) { if (set == NULL) { set = "GPT"; mm_set = mm_info; } else { mm_set->close(mm_set); mm_info->close(mm_info); tsk_errno = TSK_ERR_MM_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "GPT or %s at %" PRIuDADDR, set, offset); tsk_errstr2[0] = '\0'; return NULL; } } else { tsk_errno = 0; tsk_errstr[0] = '\0'; tsk_errstr2[0] = '\0'; } if ((mm_info = sun_open(img_info, offset)) != NULL) { if (set == NULL) { set = "Sun"; mm_set = mm_info; } else { mm_set->close(mm_set); mm_info->close(mm_info); tsk_errno = TSK_ERR_MM_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "Sun or %s at %" PRIuDADDR, set, offset); tsk_errstr2[0] = '\0'; return NULL; } } else { tsk_errno = 0; tsk_errstr[0] = '\0'; tsk_errstr2[0] = '\0'; } if ((mm_info = mac_open(img_info, offset)) != NULL) { if (set == NULL) { set = "Mac"; mm_set = mm_info; } else { mm_set->close(mm_set); mm_info->close(mm_info); tsk_errno = TSK_ERR_MM_UNKTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "Mac or %s at %" PRIuDADDR, set, offset); tsk_errstr2[0] = '\0'; return NULL; } } else { tsk_errno = 0; tsk_errstr[0] = '\0'; tsk_errstr2[0] = '\0'; } if (mm_set == NULL) { tsk_errno = TSK_ERR_MM_UNKTYPE; tsk_errstr[0] = '\0'; tsk_errstr2[0] = '\0'; return NULL; } return mm_set; } else { uint8_t mmtype; /* Transate the string into the number */ mmtype = mm_parse_type(type); switch (mmtype) { case MM_DOS: return dos_open(img_info, offset, 0); case MM_MAC: return mac_open(img_info, offset); case MM_BSD: return bsd_open(img_info, offset); case MM_SUN: return sun_open(img_info, offset); case MM_GPT: return gpt_open(img_info, offset); case MM_UNSUPP: default: tsk_errno = TSK_ERR_MM_UNSUPTYPE; snprintf(tsk_errstr, TSK_ERRSTR_L, "%s", type); tsk_errstr2[0] = '\0'; return NULL; } } }
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; }