예제 #1
0
void qmp_dump_skeys(const char *filename, Error **errp)
{
    S390SKeysState *ss = s390_get_skeys_device();
    S390SKeysClass *skeyclass = S390_SKEYS_GET_CLASS(ss);
    const uint64_t total_count = ram_size / TARGET_PAGE_SIZE;
    uint64_t handled_count = 0, cur_count;
    Error *lerr = NULL;
    vaddr cur_gfn = 0;
    uint8_t *buf;
    int ret;
    QEMUFile *f;

    /* Quick check to see if guest is using storage keys*/
    if (!skeyclass->skeys_enabled(ss)) {
        error_setg(errp, "This guest is not using storage keys - "
                         "nothing to dump");
        return;
    }

    f = qemu_fopen(filename, "wb");
    if (!f) {
        error_setg_file_open(errp, errno, filename);
        return;
    }

    buf = g_try_malloc(S390_SKEYS_BUFFER_SIZE);
    if (!buf) {
        error_setg(errp, "Could not allocate memory");
        goto out;
    }

    /* we'll only dump initial memory for now */
    while (handled_count < total_count) {
        /* Calculate how many keys to ask for & handle overflow case */
        cur_count = MIN(total_count - handled_count, S390_SKEYS_BUFFER_SIZE);

        ret = skeyclass->get_skeys(ss, cur_gfn, cur_count, buf);
        if (ret < 0) {
            error_setg(errp, "get_keys error %d", ret);
            goto out_free;
        }

        /* write keys to stream */
        write_keys(f, buf, cur_gfn, cur_count, &lerr);
        if (lerr) {
            goto out_free;
        }

        cur_gfn += cur_count;
        handled_count += cur_count;
    }

out_free:
    error_propagate(errp, lerr);
    g_free(buf);
out:
    qemu_fclose(f);
}
예제 #2
0
/* Write a single map (mode) to the output. */
static void write_map(FILE *output, map_t *mode, map_t *maps) {
  sequence_t *current, *last;

  /* Mode name is NULL when the map is created by extracting common parts of
     other maps. In that case the collected_from list is a linked list of map
     pointers from which it was created. */
  if (mode->name != NULL) {
    fprintf(output, "\t%s {\n", mode->name);
  } else {
    map_list_t *ptr;
    fprintf(output, "\t");
    for (ptr = mode->collected_from; ptr != NULL; ptr = ptr->next) {
      fprintf(output, "_%s", ptr->map->name);
    }
    fprintf(output, " {\n");
  }

  if (mode->esc_seq_enter) {
    fprintf(
        output, "\t\t_enter = \"%s\"\n",
        mode->esc_seq_enter_name ? mode->esc_seq_enter_name : get_print_seq(mode->esc_seq_enter));
  }

  if (mode->esc_seq_leave) {
    fprintf(
        output, "\t\t_leave = \"%s\"\n",
        mode->esc_seq_leave_name ? mode->esc_seq_leave_name : get_print_seq(mode->esc_seq_leave));
  }

  /* Locate all the maps which contain common pieces collected from this map.
     These have to be %include'd in this map. */
  for (; maps != NULL; maps = maps->next) {
    map_list_t *collected;
    for (collected = maps->collected_from; collected != NULL; collected = collected->next) {
      if (collected->map == mode) {
        fprintf(output, "\t\t%%_use = \"");
        for (collected = maps->collected_from; collected != NULL; collected = collected->next) {
          fprintf(output, "_%s", collected->map->name);
        }
        fprintf(output, "\"\n");
        break;
      }
    }
  }

  write_keys(mode->sequences);

  for (current = mode->sequences, last = NULL; current != NULL;
       last = current, current = current->next) {
    free(last);
  }

  fprintf(output, "\t}\n\n");
}
예제 #3
0
파일: personalize.c 프로젝트: kisom/hashlet
enum DEVICE_STATE personalize (int fd, enum DEVICE_STATE goal,
                               struct key_container *keys)
{
  enum DEVICE_STATE state = get_device_state (fd);

  if (state >= goal)
    return state;

  if (set_config_zone (fd) && lock_config_zone (fd, state))
    {
      state = STATE_INITIALIZED;
      assert (get_device_state (fd) == state);

      struct octet_buffer otp_zone;
      if (set_otp_zone (fd, &otp_zone))
        {
          struct octet_buffer data_zone;
          if (write_keys (fd, keys, &data_zone))
            {
              uint16_t crc = crc_data_otp_zone (data_zone, otp_zone);

              if (lock (fd, DATA_ZONE, crc))
                {
                  state = STATE_PERSONALIZED;
                  assert (get_device_state (fd) == state);
                }

              free_octet_buffer (data_zone);
            }

          free_octet_buffer (otp_zone);
        }
    }

  return state;

}
예제 #4
0
static void
grl_metadata_store_source_store_metadata (GrlSource *source,
                                          GrlSourceStoreMetadataSpec *sms)
{
  GRL_DEBUG ("grl_metadata_store_source_set_metadata");

  const gchar *media_id, *source_id;
  GError *error = NULL;
  GList *failed_keys = NULL;

  source_id = grl_media_get_source (sms->media);
  media_id = grl_media_get_id (sms->media);

  /* We need the source id */
  if (!source_id) {
    GRL_WARNING ("Failed to update metadata: source-id not available");
    error = g_error_new (GRL_CORE_ERROR,
                         GRL_CORE_ERROR_STORE_METADATA_FAILED,
                         _("Failed to update metadata: %s"),
                         _("\"source-id\" not available"));
    failed_keys = g_list_copy (sms->keys);
  } else {
    /* Special case for root categories */
    if (!media_id) {
      media_id = "";
    }

    failed_keys = write_keys (GRL_METADATA_STORE_SOURCE (source)->priv->db,
                              source_id, media_id, sms, &error);
  }

  sms->callback (sms->source, sms->media, failed_keys, sms->user_data, error);

  g_clear_error (&error);
  g_list_free (failed_keys);
}