Esempio n. 1
0
int cmd_list(int argc, char *argv[])
{
  storage_t storage;
  const char *elem;

  if (argc != 2)
  {
    int help_argc = 2;
    char *help_argv[] = { "help_err", "list", NULL };
    return cmd_help(help_argc, help_argv);
  }

  if ((storage = storage_new(argv[1], 0)) == NULL)
    errx(EXIT_FAILURE, "unable to open storage: %s", argv[1]);

  elem = storage_list(storage, "backups");
  while (elem != NULL)
  {
    printf("%s\n", elem);
    elem = storage_list(storage, NULL);
  }

  storage_delete(storage);

  return EXIT_SUCCESS;
}
Esempio n. 2
0
static void ata_init_ata_device(struct ata_device *ata_device)
{
	ata_device->storage_device = storage_new(STORAGE_TYPE_ATA, host_id, device_id, NULL, 512);
	ata_device->heads_per_cylinder = ATA_DEFAULT_HEADS;
	ata_device->sectors_per_track = ATA_DEFAULT_SECTORS;
	ata_device->packet_length = 12;
	device_id++;
}
Esempio n. 3
0
int cmd_purge(int argc, char *argv[])
{
  storage_t storage;
  strset_t backups;
  strset_t objects;
  const char *elem;
  struct mark_backup_args args;

  if (argc != 2)
  {
    int help_argc = 2;
    char *help_argv[] = { "help_err", "purge", NULL };
    return cmd_help_err(help_argc, help_argv);
  }

  if ((storage = storage_new(argv[1], false, true)) == NULL)
    logger(LOG_ERROR, "unable to open storage: %s", argv[1]);

  if (!storage_lock(storage, true, options_get()->force))
    logger(LOG_ERROR, "backup directory locked, use -f to force operation");

  backups = strset_new();
  objects = strset_new();

  /* Get the list of backups. */
  elem = storage_list(storage, "backups");
  while (elem != NULL)
  {
    strset_add(backups, elem);
    elem = storage_list(storage, NULL);
  }

  /* Get the list of objects. */
  elem = storage_list(storage, "objects");
  while (elem != NULL)
  {
    strset_add(objects, elem);
    elem = storage_list(storage, NULL);
  }

  /*
  ** For each backup, call mark_backup, which will mark all the objects of a
  ** backup as used (it will actually remove them from the `objects` strset.
  */
  args.objects = objects;
  args.storage = storage;
  strset_foreach(backups, mark_backup, &args);

  /* Delete every object remaining in the `objects` strset. */
  strset_foreach(objects, delete_object, (void *) storage);

  strset_delete(backups);
  strset_delete(objects);
  storage_unlock(storage);
  storage_delete(storage);

  return EXIT_SUCCESS;
}
Esempio n. 4
0
// Creates a new queue. Takes ownership of queue name, but not config.
queue *queue_new(bytestring *name, const queueconfig *config)
{
  queue *q = xmalloc(sizeof(queue));

  q->name    = name;
  q->storage = storage_new(config->storage_type, q);
  q->config  = config;

  return q;
}
Esempio n. 5
0
int cmd_restore(int argc, char *argv[])
{
    storage_t storage;
    FILE *backup;
    char *backup_name;
    char *download_path;
    char buf[4096];

    if (!(argc == 3 || (argc == 2 && options['i'])))
    {
        int help_argc = 2;
        char *help_argv[] = { "help_err", "restore", NULL };
        return cmd_help(help_argc, help_argv);
    }

    if ((storage = storage_new(argv[1], 0)) == NULL)
        errx(EXIT_FAILURE, "unable to open storage: %s", argv[1]);

    if (argc == 3)
    {
        backup_name = estrdup(argv[2]);
    }
    else
    {
        printf("Available backups:\n");
        if (cmd_list(argc, argv) == EXIT_FAILURE)
            return EXIT_FAILURE;
        backup_name = readline("Enter the backup name to restore: ");
        /* Cleanly exit if the user did not enter any backup to restore. */
        if (backup_name == NULL || strlen(backup_name) == 0)
            return EXIT_SUCCESS;
    }

    download_path = path_concat("backups", backup_name);
    free(backup_name);
    if ((backup = storage_retrieve_file(storage, download_path)) == NULL)
        errx(EXIT_FAILURE, "unable to retrieve the backup description file");
    free(download_path);

    while (fgets(buf, 4096, backup) != NULL)
        unhash_dispatch(storage, "", buf);

    if (ferror(backup))
        errx(EXIT_FAILURE, "unable to restore the backup");

    fclose(backup);
    storage_delete(storage);

    return EXIT_SUCCESS;
}
Esempio n. 6
0
int cmd_delete(int argc, char *argv[])
{
  storage_t storage;
  char *backup_name;
  char *unlink_path;

  if (!(argc == 3 || (argc == 2 && options_get()->interactive)))
  {
    int help_argc = 2;
    char *help_argv[] = { "help_err", "delete", NULL };
    return cmd_help_err(help_argc, help_argv);
  }

  if ((storage = storage_new(argv[1], false, false)) == NULL)
    logger(LOG_ERROR, "unable to open storage: %s", argv[1]);

  if (argc == 3)
  {
    backup_name = estrdup(argv[2]);
  }
  else
  {
    printf("Available backups:\n");
    if (cmd_list(argc, argv) == EXIT_FAILURE)
      return EXIT_FAILURE;
    backup_name = readline("Enter the backup name to delete: ");
    /* Cleanly exit if the user did not enter any backup to delete. */
    if (backup_name == NULL || strlen(backup_name) == 0)
      return EXIT_SUCCESS;
  }

  unlink_path = path_concat("backups", backup_name);
  free(backup_name);
  if (!storage_unlink(storage, unlink_path))
    logger(LOG_ERROR, "unable to delete the backup");
  free(unlink_path);

  storage_delete(storage);

  return EXIT_SUCCESS;
}
Esempio n. 7
0
struct i_fn_args *
i_fn_args_new(const char *os_root, const char *def_tmp_dir,
	      const char *def_cmds_file, int transport, const char *rendezvous)
{
	struct i_fn_args *a;
	char *filename;

	AURA_MALLOC(a, i_fn_args);

	a->c = NULL;
	a->os_root = aura_strdup(os_root);
	a->cfg_root = "";
	a->name = "";
	a->short_desc = "";
	a->long_desc = "";
	a->result = 0;
	a->log = NULL;
	a->s = NULL;
	a->tmp = NULL;
	a->temp_files = NULL;
	a->cmd_names = NULL;

	asprintf(&filename, "%sinstall.log", def_tmp_dir);
	a->log = fopen(filename, "w");
	free(filename);
	if (a->log == NULL) {
		i_fn_args_free(a);
		return(NULL);
	}

	i_log(a, "Installer started");
	i_log(a, "-----------------");

	i_log(a, "+ Creating DFUI connection on ``%s''\n", rendezvous);

	if ((a->c = dfui_connection_new(transport, rendezvous)) == NULL) {
		i_log(a, "! ERROR: Couldn't create connection on ``%s''\n", rendezvous);
		i_fn_args_free(a);
		return(NULL);
	}

	i_log(a, "+ Connecting on ``%s''\n", rendezvous);

	if (!dfui_be_start(a->c)) {
		i_log(a, "! ERROR: Couldn't connect to frontend on ``%s''\n", rendezvous);
		i_fn_args_free(a);
		return(NULL);
	}

	if ((a->s = storage_new()) == NULL) {
		i_log(a, "! ERROR: Couldn't create storage descriptor");
		i_fn_args_free(a);
		return(NULL);
	}

	a->tmp = def_tmp_dir;	/* XXX temporarily set to this */
	a->temp_files = aura_dict_new(23, AURA_DICT_HASH);
	a->cmd_names = config_vars_new();
	if (!config_vars_read(a, a->cmd_names, CONFIG_TYPE_SH, "%s",
		def_cmds_file)) {
		i_log(a, "! ERROR: Couldn't read cmdnames config file");
		i_fn_args_free(a);
		return(NULL);
	}

	a->tmp = cmd_name(a, "INSTALLER_TEMP");

	i_log(a, "+ Starting installer state machine");

	return(a);
}
Esempio n. 8
0
static int
storage_msghandler (int m, int c, struct msgbuf *buf, int bufcnt)
{
	if (m != MSG_BUF)
		return -1;
	if (c == STORAGE_MSG_NEW) {
		struct storage_msg_new *arg;
		struct storage_extend *extend;
		char *arg_extend;
		int extend_count, tmp, i;

		if (bufcnt != 1 && bufcnt != 2)
			return -1;
		if (buf[0].len != sizeof *arg)
			return -1;
		arg = buf[0].base;
		if (arg->guidp)
			arg->guidp = &arg->guidd;
		if (bufcnt == 2) {
			arg_extend = buf[1].base;
			for (extend_count = 0, tmp = 0; tmp < buf[1].len;
			     extend_count++) {
				tmp += strlen (&arg_extend[tmp]) + 1;
				tmp += strlen (&arg_extend[tmp]) + 1;
			}
			extend = alloc (sizeof *extend * (extend_count + 1));
			for (i = 0, tmp = 0; tmp < buf[1].len; i++) {
				extend[i].name = &arg_extend[tmp];
				tmp += strlen (&arg_extend[tmp]) + 1;
				extend[i].value = &arg_extend[tmp];
				tmp += strlen (&arg_extend[tmp]) + 1;
			}
			extend[i].name = NULL;
			extend[i].value = NULL;
		} else {
			extend = NULL;
		}
		arg->retval = storage_new (arg->type, arg->host_id,
					   arg->device_id, arg->guidp, extend);
		if (extend)
			free (extend);
		return 0;
	} else if (c == STORAGE_MSG_FREE) {
		struct storage_msg_free *arg;

		if (bufcnt != 1)
			return -1;
		if (buf[0].len != sizeof *arg)
			return -1;
		arg = buf[0].base;
		storage_free (arg->storage);
		return 0;
	} else if (c == STORAGE_MSG_HANDLE_SECTORS) {
		struct storage_msg_handle_sectors *arg;

		if (bufcnt != 3)
			return -1;
		if (buf[0].len != sizeof *arg)
			return -1;
		arg = buf[0].base;
		arg->retval = storage_handle_sectors (arg->storage,
						      &arg->access,
						      buf[1].base,
						      buf[2].base);
		return 0;
	} else {
		return -1;
	}
}
void createStorage() {
  storage_t* s = storage_new();
  CU_ASSERT_PTR_NOT_NULL_FATAL(s);
  storage_free(s);
}