Exemple #1
0
int
fat_calc_sizes (PedSector size, PedSector align, FatType fat_type,
		PedSector root_dir_sectors,
		PedSector* out_cluster_sectors, FatCluster* out_cluster_count,
		PedSector* out_fat_size)
{
	PedSector	cluster_sectors;

	PED_ASSERT (out_cluster_sectors != NULL);
	PED_ASSERT (out_cluster_count != NULL);
	PED_ASSERT (out_fat_size != NULL);

	for (cluster_sectors = fat_recommend_min_cluster_size (fat_type, size);
	     cluster_sectors <= fat_max_cluster_size (fat_type);
	     cluster_sectors *= 2) {
		if (calc_sizes (size, align, fat_type, root_dir_sectors,
				cluster_sectors,
			        out_cluster_count, out_fat_size)) {
			*out_cluster_sectors = cluster_sectors;
			return 1;
		}
	}

	for (cluster_sectors = fat_recommend_min_cluster_size (fat_type, size);
	     cluster_sectors >= fat_min_cluster_size (fat_type);
	     cluster_sectors /= 2) {
		if (calc_sizes (size, align, fat_type, root_dir_sectors,
				cluster_sectors,
			        out_cluster_count, out_fat_size)) {
			*out_cluster_sectors = cluster_sectors;
			return 1;
		}
	}

	/* only make the cluster size really small (<4k) if a bigger one is
	 * isn't possible.  Windows never makes FS's like this, but it
	 * seems to work...  (do more tests!)
	 */
	for (cluster_sectors = 4; cluster_sectors > 0; cluster_sectors /= 2) {
		if (calc_sizes (size, align, fat_type, root_dir_sectors,
				cluster_sectors,
				out_cluster_count, out_fat_size)) {
			*out_cluster_sectors = cluster_sectors;
			return 1;
		}
	}

	return 0;
}
Exemple #2
0
/* Same as fat_calc_sizes, except it only attempts to match a particular
 * cluster size.  This is useful, because the FAT resizer can only shrink the
 * cluster size.
 */
int
fat_calc_resize_sizes (
	const PedGeometry* geom,
	PedSector align,
	FatType fat_type,
	PedSector root_dir_sectors,
	PedSector cluster_sectors,
	PedSector* out_cluster_sectors,
	FatCluster* out_cluster_count,
	PedSector* out_fat_size)
{
	PED_ASSERT (geom != NULL);
	PED_ASSERT (out_cluster_sectors != NULL);
	PED_ASSERT (out_cluster_count != NULL);
	PED_ASSERT (out_fat_size != NULL);

/* libparted can only reduce the cluster size at this point */
	for (*out_cluster_sectors = cluster_sectors;
	     *out_cluster_sectors >= fat_min_cluster_size (fat_type);
	     *out_cluster_sectors /= 2) {
		if (calc_sizes (geom->length, align, fat_type, root_dir_sectors,
				*out_cluster_sectors,
				out_cluster_count, out_fat_size))
			return 1;
	}
	return 0;
}
Exemple #3
0
static void
calc_sizes (const struct config_parser *parser, struct parser_sizes *szs)
{
  const struct config_parser **children = parser->children;
  
  szs->num_groups++;
  if (children)
    while (*children)
      {
	calc_sizes(*children++, szs);
	szs->num_child_inputs++;	
    }  
}
Exemple #4
0
static HRESULT start_installation(InstallEngine *This, DWORD operation, DWORD jobflags)
{
    HANDLE thread;
    HRESULT hr;

    This->thread.operation = operation;
    This->thread.jobflags  = jobflags;
    This->thread.downloaded_kb = 0;
    This->thread.download_start = 0;

    /* Windows sends the OnStartInstall event from a different thread,
     * but OnStartInstall already contains the required download and install size.
     * The only way to signal an error from the thread is to send an OnStopComponent /
     * OnStopInstall signal which can only occur after OnStartInstall. We need to
     * precompute the sizes here to be able inform the application about errors while
     * calculating the required sizes. */

    hr = ICifFile_EnumComponents(This->icif, &This->thread.enum_comp, 0, NULL);
    if (FAILED(hr)) return hr;

    hr = calc_sizes(This->thread.enum_comp, operation, &This->thread.download_size, &This->thread.install_size);
    if (FAILED(hr)) goto error;

    IInstallEngine2_AddRef(&This->IInstallEngine2_iface);

    thread = CreateThread(NULL, 0, thread_installation, This, 0, NULL);
    if (!thread)
    {
        IInstallEngine2_Release(&This->IInstallEngine2_iface);
        hr = E_FAIL;
        goto error;
    }

    CloseHandle(thread);
    return S_OK;

error:
    IEnumCifComponents_Release(This->thread.enum_comp);
    return hr;
}
/* For ARGP, increments the NUM_GROUPS field in SZS by the total
   number of argp structures descended from it, and the SHORT_LEN by
   the total number of short options. */
static void
calc_sizes (const struct argp *argp,  struct parser_sizes *szs)
{
  const struct argp_child *child = argp->children;
  const struct argp_option *opt = argp->options;

  if (opt || argp->parser)
    {
      /* This parser needs a group. */
      szs->num_groups++;
      if (opt)
	{
	  while (__option_is_short (opt++))
	    szs->short_len++;
	}
    }

  if (child)
    while (child->argp)
      {
	calc_sizes ((child++)->argp, szs);
	szs->num_child_inputs++;
      }
}
/* Initializes PARSER to parse ARGP in a manner described by FLAGS.  */
static error_t
parser_init(struct parser *parser, const struct argp *argp,
			int argc, char **argv, int flags, void *input)
{
  error_t err = 0;
  struct group *group;
  struct parser_sizes szs;

  parser->posixly_correct = getenv ("POSIXLY_CORRECT");

  if (flags & ARGP_IN_ORDER)
    parser->ordering = RETURN_IN_ORDER;
  else if (flags & ARGP_NO_ARGS)
    parser->ordering = REQUIRE_ORDER;
  else if (parser->posixly_correct)
    parser->ordering = REQUIRE_ORDER;
  else
    parser->ordering = PERMUTE;

  szs.short_len = 0;
  szs.num_groups = 0;
  szs.num_child_inputs = 0;

  if (argp)
    calc_sizes (argp, &szs);

  if (!(flags & ARGP_LONG_ONLY))
    /* We have no use for the short option array. */
    szs.short_len = 0;

  /* Lengths of the various bits of storage used by PARSER.  */
#define GLEN (szs.num_groups + 1) * sizeof (struct group)
#define CLEN (szs.num_child_inputs * sizeof (void *))
#define SLEN (szs.short_len + 1)
#define STORAGE(offset) ((void *) (((char *) parser->storage) + (offset)))

  parser->storage = malloc(GLEN + CLEN + SLEN);
  if (! parser->storage) {
	  return ENOMEM;
  }

  parser->groups = (struct group *)parser->storage;

  parser->child_inputs = (void **)STORAGE(GLEN);
  memset(parser->child_inputs, 0, (szs.num_child_inputs * sizeof(void *)));

  if (flags & ARGP_LONG_ONLY) {
	  parser->short_opts = (char *)STORAGE(GLEN + CLEN);
  } else {
	  parser->short_opts = NULL;
  }

  parser_convert (parser, argp);

  memset (&parser->state, 0, sizeof (struct argp_state));

  parser->state.root_argp = parser->argp;
  parser->state.argc = argc;
  parser->state.argv = argv;
  parser->state.flags = (unsigned)flags;
  parser->state.err_stream = stderr;
  parser->state.out_stream = stdout;
  parser->state.pstate = parser;

  parser->args_only = 0;
  parser->nextchar = NULL;
  parser->first_nonopt = parser->last_nonopt = 0;

  /* Call each parser for the first time, giving it a chance to propagate
     values to child parsers.  */
  if (parser->groups < parser->egroup)
    parser->groups->input = input;
  for (group = parser->groups;
       group < parser->egroup && (!err || err == EBADKEY);
       group++)
    {
      if (group->parent)
	/* If a child parser, get the initial input value from the parent. */
	group->input = group->parent->child_inputs[group->parent_index];

      if (!group->parser
	  && group->argp->children && group->argp->children->argp)
	/* For the special case where no parsing function is supplied for an
	   argp, propagate its input to its first child, if any (this just
	   makes very simple wrapper argps more convenient).  */
	group->child_inputs[0] = group->input;

      err = group_parse (group, &parser->state, ARGP_KEY_INIT, 0);
    }
  if (err == EBADKEY)
    err = 0;			/* Some parser didn't understand.  */

  if (err)
    return err;

  if (argv[0] && !(parser->state.flags & ARGP_PARSE_ARGV0))
    /* There's an argv[0]; use it for messages.  */
    {
      parser->state.name = __argp_basename(argv[0]);

      /* Don't parse it as an argument. */
      parser->state.next = 1;
    }
  else
    parser->state.name = __argp_short_program_name(NULL);

  return 0;
}
Exemple #7
0
static int
parser_init(struct parser_state *state,
	    const struct config_parser *parser,
	    void *input)
{
  struct parser_sizes szs;
  size_t group_alloc;
  size_t input_alloc;
  void **next_input_slot;
  struct group *group;
  
  /* Allocate and initialize group structures */
  init_sizes(&szs);
  calc_sizes(parser, &szs);

  group_alloc = sizeof(*state->groups) * szs.num_groups;
  input_alloc = sizeof(*state->child_inputs) * szs.num_child_inputs;
  state->storage = malloc(group_alloc + input_alloc);

  if (!state->storage)
    return ENOMEM;

  state->groups = state->storage;
  state->egroup = state->groups + szs.num_groups;

  if (szs.num_child_inputs > 0)
    {
      state->child_inputs = (void *) ((char *) state->storage + group_alloc);
      memset(state->child_inputs, 0, input_alloc);
    }
  else
    state->child_inputs = NULL;

  group = state->groups;
  next_input_slot = state->child_inputs;

  convert_options(parser, NULL, 0, &group, &next_input_slot);

  assert(group == state->egroup);
  assert(next_input_slot == state->child_inputs + szs.num_child_inputs);

  /* Call with CONFIG_KEY_INIT, for propagation of child inputs */
  state->groups[0].state.input = input;

  for (group = state->groups; group < state->egroup; group++)
    {
      int err;
      
      if (group->parent)
	group->state.input = group->parent->state.child_inputs[group->parent_index];

      err = group->parser->handler(CONFIG_PARSE_KEY_INIT, 0, NULL, &group->state);
      if (err && err != EINVAL)
	{
	  /* Abort initialization */
	  free(state->storage);
	  state->storage = NULL;
	  return err;
	}
    }

  return 0;
}