Esempio n. 1
0
// This is an internal helper function which assumes no NULL args are passed.
// It sets the given attribute values for a single entry at the given index.
static int SetEntryAttributes(struct drive *drive,
                              uint32_t index,
                              CgptAddParams *params) {
  if (params->set_raw) {
    SetRaw(drive, PRIMARY, index, params->raw_value);
  } else {
    if (params->set_successful)
      SetSuccessful(drive, PRIMARY, index, params->successful);
    if (params->set_tries)
      SetTries(drive, PRIMARY, index, params->tries);
    if (params->set_priority)
      SetPriority(drive, PRIMARY, index, params->priority);
  }

  // New partitions must specify type, begin, and size.
  if (IsUnused(drive, PRIMARY, index)) {
    if (!params->set_begin || !params->set_size || !params->set_type) {
      Error("-t, -b, and -s options are required for new partitions\n");
      return -1;
    }
    if (GuidIsZero(&params->type_guid)) {
      Error("New partitions must have a type other than \"unused\"\n");
      return -1;
    }
  }

  return 0;
}
Esempio n. 2
0
int CgptNext(CgptNextParams *params) {
  struct drive drive;
  GptEntry *entry;
  char tmp[64];
  int tries;
  next_index = -1;
  int gpt_retval;

  if (params == NULL)
    return CGPT_FAILED;

  if (params->drive_name) {
    do_search(params);
  } else {
    scan_real_devs(params);
  }

  if (strlen(next_file_name) < 0) {
    return CGPT_FAILED;
  }

  if (DriveOpen(next_file_name, &drive, 0, O_RDWR) == CGPT_OK) {
    if (GPT_SUCCESS != (gpt_retval = GptSanityCheck(&drive.gpt))) {
      Error("GptSanityCheck() returned %d: %s\n",
            gpt_retval, GptError(gpt_retval));
      return CGPT_FAILED;
    }

    // Decrement tries if we selected on that criteria
    tries = GetTries(&drive, PRIMARY, next_index);
    if (tries > 0) {
      tries--;
    }
    SetTries(&drive, PRIMARY, next_index, tries);

    // Print out the next disk to go!
    entry = GetEntry(&drive.gpt, ANY_VALID, next_index);
    GuidToStrLower(&entry->unique, tmp, sizeof(tmp));
    printf("%s\n", tmp);

    // Write it all out
    UpdateAllEntries(&drive);
    return DriveClose(&drive, 1);
  }

  return 1;
}