cgpt/cgpt_find.c
// This returns true if a GPT partition matches the search criteria. If a match
// isn't found (or if the file doesn't contain a GPT), it returns false. The
// filename and partition number that matched is left in a global, since we
// could have multiple hits.
This returns true if a GPT partition matches the search criteria. If a match
isn't found (or if the file doesn't contain a GPT), it returns false. The
filename and partition number that matched is left in a global, since we
could have multiple hits.
This returns true if a GPT partition matches the search criteria . If a match isn ' t found ( or if the file doesn ' t contain a GPT ) it returns false . The filename and partition number that matched is left in a global since we could have multiple hits .
static int gpt_search(CgptFindParams *params, struct drive *drive,
                      const char *filename) {
  int i;
  GptEntry *entry;
  int retval = 0;
  char partlabel[GPT_PARTNAME_LEN];
  if (GPT_SUCCESS != GptValidityCheck(&drive->gpt)) {
    return 0;
  }
  for (i = 0; i < GetNumberOfEntries(drive); ++i) {
    entry = GetEntry(&drive->gpt, ANY_VALID, i);
    if (GuidIsZero(&entry->type))
      continue;
    int found = 0;
    if ((params->set_unique && GuidEqual(&params->unique_guid, &entry->unique))
        || (params->set_type && GuidEqual(&params->type_guid, &entry->type))) {
      found = 1;
    } else if (params->set_label) {
      if (CGPT_OK != UTF16ToUTF8(entry->name,
                                 sizeof(entry->name) / sizeof(entry->name[0]),
                                 (uint8_t *)partlabel, sizeof(partlabel))) {
        Error("The label cannot be converted from UTF16, so abort.\n");
        return 0;
      }
      if (!strncmp(params->label, partlabel, sizeof(partlabel)))
        found = 1;
    }
    if (found && match_content(params, drive, entry)) {
      params->hits++;
      retval++;
      showmatch(params, filename, i+1, entry);
      if (!params->match_partnum)
        params->match_partnum = i+1;
    }
  }
  return retval;
}
static int gpt_search ( CgptFindParams * params , struct drive * drive , const char * filename ) { int i ; GptEntry * entry ; int retval = 0 ; char partlabel [ GPT_PARTNAME_LEN ] ; if ( GPT_SUCCESS != GptValidityCheck ( & drive -> gpt ) ) { return 0 ; } for ( i = 0 ; i < GetNumberOfEntries ( drive ) ; ++ i ) { entry = GetEntry ( & drive -> gpt , ANY_VALID , i ) ; if ( GuidIsZero ( & entry -> type ) ) continue ; int found = 0 ; if ( ( params -> set_unique && GuidEqual ( & params -> unique_guid , & entry -> unique ) ) || ( params -> set_type && GuidEqual ( & params -> type_guid , & entry -> type ) ) ) { found = 1 ; } else if ( params -> set_label ) { if ( CGPT_OK != UTF16ToUTF8 ( entry -> name , sizeof ( entry -> name ) / sizeof ( entry -> name [ 0 ] ) , ( uint8_t * ) partlabel , sizeof ( partlabel ) ) ) { Error ( " \n " ) ; return 0 ; } if ( ! strncmp ( params -> label , partlabel , sizeof ( partlabel ) ) ) found = 1 ; } if ( found && match_content ( params , drive , entry ) ) { params -> hits ++ ; retval ++ ; showmatch ( params , filename , i + 1 , entry ) ; if ( ! params -> match_partnum ) params -> match_partnum = i + 1 ; } } return retval ; }
This returns true if a GPT partition matches the search criteria.
This returns true if a GPT partition matches the search criteria .