コード例 #1
0
ファイル: dskform.c プロジェクト: damieng/johnelliot
int main(int argc, char **argv)
{
	char *outtyp;
	char *outcomp;
	int forcehead;
	int stdret;
	dsk_format_t format;

	if (argc < 2) return help(argc, argv);
        if (find_arg("--help",    argc, argv) > 0) return help(argc, argv);
	stdret = standard_args(argc, argv); if (!stdret) return 0;
        ignore_arg("-itype", 2, &argc, argv);
        ignore_arg("-iside", 2, &argc, argv);
        ignore_arg("-icomp", 2, &argc, argv);
        ignore_arg("-otype", 2, &argc, argv);
        ignore_arg("-oside", 2, &argc, argv);
        ignore_arg("-ocomp", 2, &argc, argv);
        outtyp    = check_type("-type", &argc, argv); if (!outtyp) outtyp = "dsk";
        outcomp   = check_type("-comp", &argc, argv); 
        forcehead = check_forcehead("-side", &argc, argv);
	format    = check_format("-format", &argc, argv);
        retries   = check_retry("-retry", &argc, argv);
	if (format == -1) format = FMT_180K;
	args_complete(&argc, argv);

	return do_format(argv[1], outtyp, outcomp, forcehead, format);
}
コード例 #2
0
ファイル: mmc.c プロジェクト: Hashcode/u-boot
int load_ptbl(void)
{
	static unsigned char data[512];
	static struct efi_entry entry[4];
	int n,m,r;
	r = mmc_read(1, 1, data, 512);
	if (r != 1) {
		printf("error reading partition table\n");
		return -1;
	}
	if (memcmp(data, "EFI PART", 8)) {
		printf("efi partition table not found\n");
		printf("===============================\n");
		printf("            format             \n");
		printf("===============================\n");
		do_format();
		return -1;
	}
	for (n = 0; n < (128/4); n++) {
		r = mmc_read(1, 1 + n, (void*) entry, 512);
		if (r != 1) {
			printf("partition read failed\n");
			return 1;
		}
		for (m = 0; m < 4; m ++)
			import_efi_partition(entry + m);
	}
	return 0;
}
コード例 #3
0
ファイル: plugin.c プロジェクト: easonoutlook/code-format
bool on_key_binding(int key_id)
{
  if (!fmt_is_supported_ft(NULL))
    return true;
  switch (key_id)
  {
    case FORMAT_KEY_REGION:
      do_format(NULL, false, false);
      break;
    case FORMAT_KEY_DOCUMENT:
      do_format(NULL, true, false);
      break;
    case FORMAT_KEY_SESSION:
      do_format_session();
      break;
    default:
      return false;
  }
  return true;
}
コード例 #4
0
ファイル: filesys.c プロジェクト: derenrich/pintos-awesome
/*! Initializes the file system module.
    If FORMAT is true, reformats the file system. */
void filesys_init(bool format) {
    fs_device = block_get_role(BLOCK_FILESYS);
    if (fs_device == NULL)
        PANIC("No file system device found, can't initialize file system.");

    inode_init();
    free_map_init();

    if (format) 
        do_format();

    free_map_open();
}
コード例 #5
0
ファイル: fastboot.c プロジェクト: suriyanr/u-boot-odroid-c1
int board_fbt_oem(const char *cmdbuf)
{
	if (!strncmp("format", cmdbuf, 6)) {
                if (do_format() < 0) {
#if 0
                        strcpy(priv->response,
                                        "FAILFailed to format the partition");
#endif
                }
                return 0;
        }

        return -1;
}
コード例 #6
0
ファイル: filesys.c プロジェクト: argillander/TDDB68
/* Initializes the file system module.
   If FORMAT is true, reformats the file system. */
void
filesys_init (bool format) 
{
  filesys_disk = disk_get (0, 1);
  if (filesys_disk == NULL)
    PANIC ("hd0:1 (hdb) not present, file system initialization failed");

  inode_init ();
  free_map_init ();

  if (format) 
    do_format ();

  free_map_open ();
}
コード例 #7
0
ファイル: plugin.c プロジェクト: easonoutlook/code-format
static gboolean on_editor_notify(G_GNUC_UNUSED GObject *obj,
                                 G_GNUC_UNUSED GeanyEditor *editor,
                                 SCNotification *notif,
                                 G_GNUC_UNUSED gpointer user_data)
{
  if (fmt_prefs_get_auto_format() && fmt_is_supported_ft(editor->document) &&
      notif->nmhdr.code == SCN_CHARADDED)
  {
    if (strchr(fmt_prefs_get_trigger(), notif->ch) != NULL)
      do_format(NULL, true, true); // FIXME: is it better to use region/line
                                   // for
                                   // auto-format?
  }
  return false;
}
コード例 #8
0
ファイル: error_handling.hpp プロジェクト: Niko-r/geofeatures
inline T raise_overflow_error(
           const char* function,
           const char* message,
           const T& val,
           const  ::geofeatures_boost::math::policies::overflow_error< ::geofeatures_boost::math::policies::user_error>&)
{
   std::string fmsg("Error in function ");
#ifndef BOOST_NO_RTTI
   fmsg += (geofeatures_boost::format(function) % geofeatures_boost::math::policies::detail::name_of<T>()).str();
#else
   fmsg += function;
#endif
   int prec = 2 + (geofeatures_boost::math::policies::digits<T, geofeatures_boost::math::policies::policy<> >() * 30103UL) / 100000UL;
   std::string msg = do_format(geofeatures_boost::format(message), geofeatures_boost::io::group(std::setprecision(prec), val));
   return user_overflow_error(fmsg.c_str(), msg.c_str(), std::numeric_limits<T>::infinity());
}
コード例 #9
0
ファイル: plugin.c プロジェクト: easonoutlook/code-format
static void do_format_session(void)
{
#ifndef G_OS_WIN32
  for (size_t i = 0; i < documents_array->len; i++)
  {
    GeanyDocument *doc = documents_array->pdata[i];
#else // On Windows/Mingw the linker says undefined ref.
      // to documents_array, so you use the goofy macro loop thing.
  guint i;
  foreach_document(i)
  {
    GeanyDocument *doc = documents[i];
#endif
    if (fmt_is_supported_ft(doc))
        do_format(doc, true, false);
  }
}
コード例 #10
0
ファイル: error_handling.hpp プロジェクト: aashish24/PDAL
void raise_error(const char* function, const char* message, const T& val)
{
  if(function == 0)
     function = "Unknown function operating on type %1%";
  if(message == 0)
     message = "Cause unknown: error caused by bad argument with value %1%";

  std::string msg("Error in function ");
  msg += (pdalboost::format(function) % typeid(T).name()).str();
  msg += ": ";
  msg += message;

  int prec = 2 + (pdalboost::math::policies::digits<T, pdalboost::math::policies::policy<> >() * 30103UL) / 100000UL;
  msg = do_format(pdalboost::format(msg), pdalboost::io::group(std::setprecision(prec), val));

  E e(msg);
  pdalboost::throw_exception(e);
}
コード例 #11
0
ファイル: dtool.c プロジェクト: archeart/MiniOS
int main(int argv, char* args[]){

	disk = open("/dev/fd0",O_RDWR);
	if (argv > 1){
		if (strcmp(format, args[1]) == 0)
			do_format();
		else if (strcmp(mkdir, args[1]) == 0){
			if (argv > 2)
				do_mkdir(args[2]);
			else 
				printf("Usage: mkdir dir\n");
		}
		else if (strcmp(chdir, args[1]) == 0){
			if (argv > 2)
				do_chdir(args[2]);
			else 
				printf("Usage: chdir dir\n");
		}
		else if (strcmp(copy, args[1]) == 0) {
			do_copy(args[2], args[3], args[4]);
		}
		else if (strcmp(dir, args[1]) == 0)
			do_dir(args[2]);
		else if (strcmp("info", args[1]) == 0){
			info(args[2]);
			}
		else if (strcmp("freeblock", args[1]) == 0)
			free_block();
		else if (strcmp("checkblock", args[1]) == 0)
			check_block(args[2]);



		else
			printf("Unknown dtool command.\n");



	}


	return 0;
}
コード例 #12
0
/* Initializes the file system module.
   If FORMAT is true, reformats the file system. */
void
filesys_init (bool format) 
{
  fs_device = block_get_role (BLOCK_FILESYS);
  if (fs_device == NULL)
    PANIC ("No file system device found, can't initialize file system.");

  inode_init ();
  // XXX Lock Initialize
  lock = (struct lock *)malloc(sizeof(struct lock));
  lock_init(lock);
  // XXX
  free_map_init ();

  if (format) 
    do_format ();

  free_map_open ();
}
コード例 #13
0
ファイル: filesys.c プロジェクト: liyu1390/CS162_group
/* Initializes the file system module.
   If FORMAT is true, reformats the file system. */
void
filesys_init (bool format) 
{
  fs_device = block_get_role (BLOCK_FILESYS);
  if (fs_device == NULL)
    PANIC ("No file system device found, can't initialize file system.");

  lock_init(&globalCacheLock);
  cache_init((struct cache_elem **) &cache);
  clock_hand = CACHE_SIZE - 1;

  inode_init ();
  free_map_init ();

  if (format) 
    do_format ();

  free_map_open ();
}
コード例 #14
0
ファイル: filesys.c プロジェクト: rahulabc/jawpintos
/* Initializes the file system module.
   If FORMAT is true, reformats the file system. */
void
filesys_init (bool format)
{
    fs_device = block_get_role (BLOCK_FILESYS);
    if (fs_device == NULL)
        PANIC ("No file system device found, can't initialize file system.");

    inode_init ();
    free_map_init ();
    cache_init ();

    if (format)
        do_format ();

    free_map_open ();

    /* Couldn't add to thread_init because we need inode_init completed
       before we can get access to root directory */
    thread_current ()->cwd_sector = ROOT_DIR_SECTOR;
}
コード例 #15
0
ファイル: filesys.c プロジェクト: kcm1700/ChoPintOS
/* Initializes the file system module.
   If FORMAT is true, reformats the file system. */
void
filesys_init (bool format)
{
  fs_device = block_get_role (BLOCK_FILESYS);

  if (fs_device == NULL)
    PANIC ("No file system device found, can't initialize file system.");

  fs_cache = cache_create (fs_device, MAX_CACHE_SIZE);
  if (fs_cache == NULL)
    PANIC ("Cannot create cache for file system");

  inode_init ();
  free_map_init ();

  if (format)
    do_format ();

  free_map_open ();
}
コード例 #16
0
ファイル: gpt.c プロジェクト: HenningSchroeder/gpt
main(int argc, char **argv)
{
	int fd, i, n;
	struct stat s;
	unsigned long total_sectors;

	printf("\n Open file: %s\n", argv[1]);

	if (!strcmp(argv[1], "/dev/sda")) {
		printf("\n Damn risky: is this your hard-disk %s\n", argv[1]);
		return -1;
	}

	fd = open(argv[1], O_RDWR);
	if (fd < 0)
		goto fail;

	memset(&s, 0, sizeof (s));
	if (fstat(fd, &s))
		goto fail;

	//printf(" st_size=%lld, st_blksize=%lu, st_blocks=%lu\n",
	//		s.st_size,
	//		s.st_blksize,
	//		s.st_blocks);


	//write GPT table
	if (argc == 3 && !strcmp(argv[2], "-w")) {
		do_format(fd);
		print_ptable(fd);
		return 0;
	} else {
		print_ptable(fd);
		return 0;
	}

fail:
	printf("\n bad file [%s]\n", argv[1]);
	return -1;
}
コード例 #17
0
ファイル: filesys.c プロジェクト: rohan4/pintosFall
/* Initializes the file system module.
   If FORMAT is true, reformats the file system. */
void
filesys_init (bool format) 
{
  fs_device = block_get_role (BLOCK_FILESYS);
  if (fs_device == NULL)
    PANIC ("No file system device found, can't initialize file system.");

  filesys_lock_list = malloc(sizeof(filesys_lock_list) * block_size(fs_device));
    int i;
    for(i=0; i < block_size(fs_device); ++i) {
      lock_init(filesys_lock_list + i);
    }

    inode_init();
    free_map_init();

    if (format) 
        do_format();

  free_map_open ();
}
コード例 #18
0
ファイル: error_handling.hpp プロジェクト: Niko-r/geofeatures
void raise_error(const char* function, const char* message, const T& val)
{
  if(function == 0)
     function = "Unknown function operating on type %1%";
  if(message == 0)
     message = "Cause unknown: error caused by bad argument with value %1%";

  std::string msg("Error in function ");
#ifndef BOOST_NO_RTTI
  msg += (geofeatures_boost::format(function) % geofeatures_boost::math::policies::detail::name_of<T>()).str();
#else
  msg += function;
#endif
  msg += ": ";
  msg += message;

  int prec = 2 + (geofeatures_boost::math::policies::digits<T, geofeatures_boost::math::policies::policy<> >() * 30103UL) / 100000UL;
  msg = do_format(geofeatures_boost::format(msg), geofeatures_boost::io::group(std::setprecision(prec), val));

  E e(msg);
  geofeatures_boost::throw_exception(e);
}
コード例 #19
0
ファイル: ft_printf.c プロジェクト: Atokatli/libft
int			ft_printf(const char *format, ...)
{
	va_list		ap;
	const char	*str;
	int			len;

	len = 0;
	va_start(ap, format);
	str = format;
	while (*str)
	{
		if (*str == '%')
		{
			len += print_part(format, str);
			str = str + 1;
			len += do_format(&str, ap);
			format = str + 1;
		}
		str++;
	}
	len += pf_putstr(format);
	va_end(ap);
	return (len);
}
コード例 #20
0
ファイル: estream-printf.c プロジェクト: aestetix/gnupg
/* The versatile printf formatting routine.  It expects a callback
   function OUTFNC and an opaque argument OUTFNCARG used for actual
   output of the formatted stuff.  FORMAT is the format specification
   and VAARGS a variable argumemt list matching the arguments of
   FORMAT.  */
int
estream_format (estream_printf_out_t outfnc,
                void *outfncarg,
                const char *format, va_list vaargs)
{
  /* Buffer to hold the argspecs and a pointer to it.*/
  struct argspec_s argspecs_buffer[DEFAULT_MAX_ARGSPECS];
  argspec_t argspecs = argspecs_buffer;
  size_t argspecs_len;  /* Number of specifications in ARGSPECS.  */

  /* Buffer to hold the description for the values.  */
  struct valueitem_s valuetable_buffer[DEFAULT_MAX_VALUES];
  valueitem_t valuetable = valuetable_buffer;

  int rc;     /* Return code. */
  size_t argidx; /* Used to index the argspecs array.  */
  size_t validx; /* Used to index the valuetable.  */
  int max_pos;/* Highest argument position.  */

  size_t nbytes = 0; /* Keep track of the number of bytes passed to
                        the output function.  */

  int myerrno = errno; /* Save the errno for use with "%m". */


  /* Parse the arguments to come up with descriptive list.  We can't
     do this on the fly because we need to support positional
     arguments. */
  rc = parse_format (format, &argspecs, DIM(argspecs_buffer), &argspecs_len);
  if (rc)
    goto leave;

  /* Check that all ARG_POS fields are set.  */
  for (argidx=0,max_pos=0; argidx < argspecs_len; argidx++)
    {
      if (argspecs[argidx].arg_pos != -1
          && argspecs[argidx].arg_pos > max_pos)
        max_pos = argspecs[argidx].arg_pos;
      if (argspecs[argidx].width_pos > max_pos)
        max_pos = argspecs[argidx].width_pos;
      if (argspecs[argidx].precision_pos > max_pos)
        max_pos = argspecs[argidx].precision_pos;
    }
  if (!max_pos)
    {
      /* Fill in all the positions.  */
      for (argidx=0; argidx < argspecs_len; argidx++)
        {
          if (argspecs[argidx].width == STAR_FIELD_VALUE)
            argspecs[argidx].width_pos = ++max_pos;
          if (argspecs[argidx].precision == STAR_FIELD_VALUE)
            argspecs[argidx].precision_pos = ++max_pos;
          if (argspecs[argidx].arg_pos != -1 )
            argspecs[argidx].arg_pos = ++max_pos;
        }
    }
  else
    {
      /* Check that they are all filled.   More test are done later.  */
      for (argidx=0; argidx < argspecs_len; argidx++)
        {
          if (!argspecs[argidx].arg_pos
              || (argspecs[argidx].width == STAR_FIELD_VALUE
                  && !argspecs[argidx].width_pos)
              || (argspecs[argidx].precision == STAR_FIELD_VALUE
                  && !argspecs[argidx].precision_pos))
            goto leave_einval;
        }
    }
  /* Check that there is no overflow in max_pos and that it has a
     reasonable length.  There may never be more elements than the
     number of characters in FORMAT.  */
  if (max_pos < 0 || max_pos >= strlen (format))
    goto leave_einval;

#ifdef DEBUG
    dump_argspecs (argspecs, argspecs_len);
#endif

  /* Allocate a table to hold the values.  If it is small enough we
     use a stack allocated buffer.  */
  if (max_pos > DIM(valuetable_buffer))
    {
      valuetable = calloc (max_pos, sizeof *valuetable);
      if (!valuetable)
        goto leave_error;
    }
  else
    {
      for (validx=0; validx < DIM(valuetable_buffer); validx++)
        valuetable[validx].vt = VALTYPE_UNSUPPORTED;
    }
  for (argidx=0; argidx < argspecs_len; argidx++)
    {
      if (argspecs[argidx].arg_pos != - 1)
        {
          validx = argspecs[argidx].arg_pos - 1;
          if (valuetable[validx].vt)
            goto leave_einval; /* Already defined. */
          valuetable[validx].vt = argspecs[argidx].vt;
        }
      if (argspecs[argidx].width == STAR_FIELD_VALUE)
        {
          validx = argspecs[argidx].width_pos - 1;
          if (valuetable[validx].vt)
            goto leave_einval; /* Already defined.  */
          valuetable[validx].vt = VALTYPE_INT;
        }
      if (argspecs[argidx].precision == STAR_FIELD_VALUE)
        {
          validx = argspecs[argidx].precision_pos - 1;
          if (valuetable[validx].vt)
            goto leave_einval; /* Already defined.  */
          valuetable[validx].vt = VALTYPE_INT;
        }
    }

  /* Read all the arguments.  This will error out for unsupported
     types and for not given positional arguments. */
  rc = read_values (valuetable, max_pos, vaargs);
  if (rc)
    goto leave_einval;

/*   for (validx=0; validx < max_pos; validx++) */
/*     fprintf (stderr, "%2d: vt=%d\n", validx, valuetable[validx].vt); */

  /* Everything has been collected, go ahead with the formatting.  */
  rc = do_format (outfnc, outfncarg, format,
                  argspecs, argspecs_len, valuetable, myerrno, &nbytes);

  goto leave;

 leave_einval:
  errno = EINVAL;
 leave_error:
  rc = -1;
 leave:
  if (valuetable != valuetable_buffer)
    free (valuetable);
  if (argspecs != argspecs_buffer)
    free (argspecs);
  return rc;
}
コード例 #21
0
int update_binary_tool_main(int argc, char *argv[])
{
    int opt;

    static const char *short_options = "h";

    static struct option long_options[] = {
        {"help", no_argument, 0, 'h'},
        {0, 0, 0, 0}
    };

    int long_index = 0;

    while ((opt = getopt_long(argc, argv, short_options,
                              long_options, &long_index)) != -1) {
        switch (opt) {
        case 'h':
            update_binary_tool_usage(stdout);
            return EXIT_SUCCESS;

        default:
            update_binary_tool_usage(stderr);
            return EXIT_FAILURE;
        }
    }

    if (argc - optind != 2) {
        update_binary_tool_usage(stderr);
        return EXIT_FAILURE;
    }

    // Log to stderr, so the output is ordered correctly in /tmp/recovery.log
    log::log_set_logger(std::make_shared<log::StdioLogger>(stderr, false));

    const char *action = argv[optind];
    const char *mountpoint = argv[optind + 1];

    bool is_valid_action = strcmp(action, ACTION_MOUNT) == 0
            || strcmp(action, ACTION_UNMOUNT) == 0
            || strcmp(action, ACTION_FORMAT) == 0;
    bool is_valid_mountpoint = strcmp(mountpoint, SYSTEM) == 0
            || strcmp(mountpoint, CACHE) == 0
            || strcmp(mountpoint, DATA) == 0;

    if (!is_valid_action || !is_valid_mountpoint) {
        update_binary_tool_usage(stderr);
        return EXIT_FAILURE;
    }

    if (access("/.chroot", F_OK) < 0) {
        fprintf(stderr, "update-binary-tool must be run inside the chroot\n");
        return EXIT_FAILURE;
    }

    bool ret = false;

    if (strcmp(action, ACTION_MOUNT) == 0) {
        ret = do_mount(mountpoint);
    } else if (strcmp(action, ACTION_UNMOUNT) == 0) {
        ret = do_unmount(mountpoint);
    } else if (strcmp(action, ACTION_FORMAT) == 0) {
        ret = do_format(mountpoint);
    }

    return ret ? EXIT_SUCCESS : EXIT_FAILURE;
}
コード例 #22
0
static int trans_command_rec(SP_term_ref t1, SP_stream *stream, struct event_stream_data *p)
{
#define buffer no_access_to_buffer_here
  spio_t_error_code code = SPIO_E_ERROR;
  SP_term_ref t2 = SP_new_term_ref();
  SP_atom name;
  SP_pred_ref pred;
  int i;
  char const *s;
  char c1, c2;

  switch (SP_term_type(t1))
    {
    case SP_TYPE_ATOM:
      if (SP_get_atom(t1, &name)
          && name == local.atm_nil)
        {
          goto success;
        }
      s = SP_string_from_atom(name);
      goto atomic;

    case SP_TYPE_INTEGER:
    case SP_TYPE_FLOAT:
      SP_get_number_codes(t1, &s);
  atomic:
      {
        code = SP_put_encoded_string(stream, s, SPIO_OPTION_NONE);
        if (SPIO_FAILED(code))
          {
            goto failure;
          }
        else
          {
            goto success;
          }
      }
      
    case SP_TYPE_COMPOUND:
      SP_get_functor(t1, &name, &i);
      if (name==local.atm_period && i==2)
	for (;;)
	  {
	    SP_get_list(t1, t2, t1);
	    if (!trans_command_rec(t2, stream, p))
	      goto failure;
	    if (SP_is_list(t1))
	      {
                PUT_BUFFER_CHAR(p, stream, ' ');
		continue;
	      }
	    else
	      if (SP_is_atom(t1) && SP_get_atom(t1, &name) && name==local.atm_nil)
		goto success;
	      else
		goto list_error;
	  }
/* Ignore compiler warnings here! */
      else if (((name==local.atm_dq && (c1='"', c2='"', 1)) ||
		(name==local.atm_sqb && (c1='[', c2=']', 1)) ||
		(name==local.atm_br && (c1='{', c2='}', 1)) ||
		(name==local.atm_min && (c1='-', c2=' ', 1))) &&
	       i==1)
	{
          PUT_BUFFER_CHAR(p, stream, c1);
	  SP_get_arg(1, t1, t2);
	  if (!trans_command_rec(t2, stream, p))
	    goto failure;
          PUT_BUFFER_CHAR(p, stream, c2);
	  /* p->buffer[p->index] = '\0'; */
	  goto success;
	}
      else if (name==local.atm_dot && i==1) {
	SP_get_arg(1, t1, t1);

	if (SP_is_atom(t1))	/* the root path, "." */
          PUT_BUFFER_CHAR(p, stream, '.');
	else while (SP_is_list(t1)) { /* .first.second.third ... */
	  SP_get_list(t1, t2, t1);
          PUT_BUFFER_CHAR(p, stream, '.');
	  if (!trans_command_rec(t2, stream, p))
	    goto failure;
	}
	/* p->buffer[p->index] = '\0'; */
	goto success;
      }
      else if (i == 1
               && (    (name==local.atm_write           && ( pred = local.write_pred, 1))
                    || (name==local.atm_writeq          && ( pred = local.writeq_pred, 1))
                    || (name==local.atm_write_canonical && ( pred = local.write_canonical_pred, 1)) ) )
	{
	  SP_get_arg(1, t1, t1);
          if (write_term(pred, t1, stream))
            goto success;
          else
            goto failure;
        }
      else if (name==local.atm_format && i==2)
	{
	  SP_get_arg(2, t1, t2);
	  SP_get_arg(1, t1, t1);
          if (do_format(t1, t2, stream))
            {
              goto success;
            }
          else
            {
              goto failure;
            }
	}
      else if ((name == local.atm_chars || name==local.atm_codes) && i==1)
	{
	  SP_get_arg(1, t1, t1);
	  if (!SP_get_list_codes(t1, &s)) /* [PM] May 2000 used to ignore errors */
            {
              goto list_error;  /* Misleading error message */
            }
	  goto atomic;
	}
      else if (name==local.atm_list && i==1)
        {
	  SP_get_arg(1, t1, t1);
          if (trans_command_list(t1, stream, p))
            goto success;
          else
            goto failure;
        }
      else
        {
          SAVE_ERROR(DOMAIN_ERROR, "tcl_command_spec", t1, 2);
        }
	    
    case SP_TYPE_VARIABLE:
  instantiation_error:
      SAVE_ERROR(INSTANTIATION_ERROR, "", t1, 2);
    }
  SP_ASSERT(0);                 /* not reached */

 success:
  SP_ASSERT(p->index < p->size);
  /* p->buffer[p->index] = '\0'; */
  return 1;

list_error:
  if (SP_is_variable(t1))
    goto instantiation_error;
  else
    SAVE_ERROR(DOMAIN_ERROR+DOMAIN_LIST, "", t1, 2);
failure:
error:
  return 0;

#undef buffer
}
コード例 #23
0
ファイル: deskmain.c プロジェクト: kelihlodversson/emutos
static WORD do_filemenu(WORD item)
{
    WORD done;
    WORD curr;
    WNODE *pw;

    done = FALSE;
    pw = win_ontop();

    curr = win_isel(G.g_screen, G.g_croot, 0);
    switch(item)
    {
    case OPENITEM:
        if (curr)
            done = do_open(curr);
        break;
    case SHOWITEM:
        if (curr)
            do_info(curr);
        break;
    case NFOLITEM:
        if (pw)
            fun_mkdir(pw);
        break;
    case CLOSITEM:
        if (pw)
            fun_close(pw, CLOSE_FOLDER);
        break;
    case CLSWITEM:
        if (pw)
            fun_close(pw, CLOSE_WINDOW);
        break;
    case DELTITEM:
        if (curr)
            fun_del(curr);
        break;
    case FORMITEM:
        if (curr)
            done = do_format(curr);
        break;

#if WITH_CLI != 0
    case CLIITEM:                         /* Start EmuCON */
        G.g_tail[0] = G.g_tail[1] = 0;
        strcpy(G.g_cmd, "EMUCON");
        done = pro_run(FALSE, 1, -1, -1);
        break;
#endif

#if CONF_WITH_SHUTDOWN
    case QUITITEM:
        enable_ceh = FALSE; /* avoid possibility of useless form_alert()s */
        display_free_stack();
        pro_exit(G.g_cmd, G.g_tail);
        done = TRUE;
        break;
#endif
    }

    return done;
}
コード例 #24
0
ファイル: format.c プロジェクト: yumingfei/libguestfs
int
main (int argc, char *argv[])
{
  /* Set global program name that is not polluted with libtool artifacts.  */
  set_program_name (argv[0]);

  setlocale (LC_ALL, "");
  bindtextdomain (PACKAGE, LOCALEBASEDIR);
  textdomain (PACKAGE);

  enum { HELP_OPTION = CHAR_MAX + 1 };

  static const char *options = "a:c:d:qvVx";
  static const struct option long_options[] = {
    { "add", 1, 0, 'a' },
    { "filesystem", 1, 0, 0 },
    { "format", 2, 0, 0 },
    { "help", 0, 0, HELP_OPTION },
    { "lvm", 2, 0, 0 },
    { "partition", 2, 0, 0 },
    { "verbose", 0, 0, 'v' },
    { "version", 0, 0, 'V' },
    { "wipe", 0, 0, 0 },
    { 0, 0, 0, 0 }
  };
  struct drv *drvs = NULL;
  struct drv *drv;
  const char *format = NULL;
  int c;
  int option_index;
  int retry, retries;

  g = guestfs_create ();
  if (g == NULL) {
    fprintf (stderr, _("guestfs_create: failed to create handle\n"));
    exit (EXIT_FAILURE);
  }

  argv[0] = bad_cast (program_name);

  for (;;) {
    c = getopt_long (argc, argv, options, long_options, &option_index);
    if (c == -1) break;

    switch (c) {
    case 0:			/* options which are long only */
      if (STREQ (long_options[option_index].name, "format")) {
        if (!optarg || STREQ (optarg, ""))
          format = NULL;
        else
          format = optarg;
      } else if (STREQ (long_options[option_index].name, "filesystem")) {
        if (STREQ (optarg, "none"))
          filesystem = NULL;
        else if (optarg[0] == '-') { /* eg: --filesystem --lvm */
          fprintf (stderr, _("%s: no filesystem was specified\n"),
                   program_name);
          exit (EXIT_FAILURE);
        } else
          filesystem = optarg;
      } else if (STREQ (long_options[option_index].name, "lvm")) {
        if (vg || lv) {
          fprintf (stderr,
                   _("%s: --lvm option cannot be given multiple times\n"),
                   program_name);
          exit (EXIT_FAILURE);
        }
        if (optarg == NULL) {
          vg = strdup ("VG");
          lv = strdup ("LV");
          if (!vg || !lv) { perror ("strdup"); exit (EXIT_FAILURE); }
        }
        else if (STREQ (optarg, "none"))
          vg = lv = NULL;
        else
          parse_vg_lv (optarg);
      } else if (STREQ (long_options[option_index].name, "partition")) {
        if (optarg == NULL)
          partition = "DEFAULT";
        else if (STREQ (optarg, "none"))
          partition = NULL;
        else
          partition = optarg;
      } else if (STREQ (long_options[option_index].name, "wipe")) {
        wipe = 1;
      } else {
        fprintf (stderr, _("%s: unknown long option: %s (%d)\n"),
                 program_name, long_options[option_index].name, option_index);
        exit (EXIT_FAILURE);
      }
      break;

    case 'a':
      OPTION_a;
      break;

    case 'v':
      OPTION_v;
      break;

    case 'V':
      OPTION_V;
      break;

    case 'x':
      OPTION_x;
      break;

    case HELP_OPTION:
      usage (EXIT_SUCCESS);

    default:
      usage (EXIT_FAILURE);
    }
  }

  /* These are really constants, but they have to be variables for the
   * options parsing code.  Assert here that they have known-good
   * values.
   */
  assert (read_only == 0);
  assert (inspector == 0);
  assert (live == 0);

  /* Must be no extra arguments on the command line. */
  if (optind != argc)
    usage (EXIT_FAILURE);

  /* The user didn't specify any drives to format. */
  if (drvs == NULL)
    usage (EXIT_FAILURE);

  /* Because the libguestfs kernel can get stuck rereading the
   * partition table after things have been erased, we sometimes need
   * to completely restart the guest.  Hence this complex retry logic.
   */
  for (retries = 0; retries <= 1; ++retries) {
    /* Add domains/drives from the command line (for a single guest). */
    add_drives (drvs, 'a');

    if (guestfs_launch (g) == -1)
      exit (EXIT_FAILURE);

    /* Test if the wipefs API is available. */
    have_wipefs = feature_available (g, "wipefs");

    /* Perform the format. */
    retry = do_format ();
    if (!retry)
      break;

    if (retries == 0) {
      /* We're going to silently retry, after reopening the connection. */
      guestfs_h *g2;

      g2 = guestfs_create ();
      guestfs_set_verbose (g2, guestfs_get_verbose (g));
      guestfs_set_trace (g2, guestfs_get_trace (g));

      if (guestfs_shutdown (g) == -1)
        exit (EXIT_FAILURE);
      guestfs_close (g);
      g = g2;
    }
    else {
      /* Failed. */
      fprintf (stderr,
               _("%s: failed to rescan the disks after two attempts.  This\n"
                 "may mean there is some sort of partition table or disk\n"
                 "data which we are unable to remove.  If you think this\n"
                 "is a bug, please file a bug at http://libguestfs.org/\n"),
               program_name);
      exit (EXIT_FAILURE);
    }
  }

  /* Free up data structures. */
  free_drives (drvs);

  if (guestfs_shutdown (g) == -1)
    exit (EXIT_FAILURE);
  guestfs_close (g);

  exit (EXIT_SUCCESS);
}
コード例 #25
0
ファイル: hformat.c プロジェクト: OS2World/UTIL-DISK-HFSutils
/*
 * NAME:	hformat->main()
 * DESCRIPTION:	implement hformat command
 */
int hformat_main(int argc, char *argv[])
{
    const char *vname, *path;
    hfsvol *vol;
    hfsvolent ent;
    int nparts, partno, options = 0, result = 0;

    vname = "Untitled";

    while (1)
    {
        int opt;

        opt = getopt(argc, argv, "fl:");
        if (opt == EOF)
            break;

        switch (opt)
        {
        case '?':
            return usage();

        case 'f':
            options |= O_FORCE;
            break;

        case 'l':
            vname = optarg;
            break;
        }
    }

    if (argc - optind < 1 || argc - optind > 2)
        return usage();

    path = argv[optind];

    nparts = hfs_nparts(path);

    if (argc - optind == 2)
    {
        partno = atoi(argv[optind + 1]);

        if (nparts != -1 && partno == 0)
        {
            if (options & O_FORCE)
            {
                fprintf(stderr,
                        "%s: warning: erasing partition information\n", argv0);
            }
            else
            {
                fprintf(stderr, "%s: medium is partitioned; "
                        "select partition > 0 or use -f\n", argv0);
                return 1;
            }
        }
    }
    else
    {
        if (nparts > 1)
        {
            fprintf(stderr,
                    "%s: must specify partition number (%d available)\n",
                    argv0, nparts);
            return 1;
        }
        else if (nparts == -1)
            partno = 0;
        else
            partno = 1;
    }

    vol = do_format(path, partno, vname);
    if (vol == 0)
    {
        hfsutil_perror(path);
        return 1;
    }

    hfs_vstat(vol, &ent);
    hfsutil_pinfo(&ent);

    if (hcwd_mounted(ent.name, ent.crdate, path, partno) == -1)
    {
        perror("Failed to record mount");
        result = 1;
    }

    hfsutil_unmount(vol, &result);

    return result;
}
コード例 #26
0
ファイル: plugin.c プロジェクト: easonoutlook/code-format
static void on_document_before_save(GObject *obj, GeanyDocument *doc,
                                    gpointer user_data)
{
  if (fmt_prefs_get_format_on_save() && fmt_is_supported_ft(doc))
    do_format(doc, true, false);
}
コード例 #27
0
ファイル: mmc.c プロジェクト: CMNookTablet/acclaim_cyanoboot
int fastboot_oem(const char *cmd)
{
	if (!strcmp(cmd,"format"))
		return do_format();
	return -1;
}
コード例 #28
0
ファイル: jsonlint.c プロジェクト: kraj/eglinfo
int main(int argc, char **argv)
{
    int format = 0, verify = 0, use_tree = 0, benchmarks = 0;
    int ret = 0, i;
    json_config config;
    char *output = "-";

    memset(&config, 0, sizeof(json_config));
    config.max_nesting = 0;
    config.max_data = 0;
    config.allow_c_comments = 1;
    config.allow_yaml_comments = 1;

    while (1) {
        int option_index;
        struct option long_options[] = {
            { "no-comments", 0, 0, 0 },
            { "no-yaml-comments", 0, 0, 0 },
            { "no-c-comments", 0, 0, 0 },
            { "format", 0, 0, 0 },
            { "verify", 0, 0, 0 },
            { "benchmark", 1, 0, 0 },
            { "help", 0, 0, 0 },
            { "max-nesting", 1, 0, 0 },
            { "max-data", 1, 0, 0 },
            { "indent-string", 1, 0, 0 },
            { "tree", 0, 0, 0 },
            { 0 },
        };
        int c = getopt_long(argc, argv, "o:", long_options, &option_index);
        if (c == -1)
            break;
        switch (c) {
        case 0: {
            const char *name = long_options[option_index].name;
            if (strcmp(name, "help") == 0)
                usage(argv[0]);
            else if (strcmp(name, "no-c-comments") == 0)
                config.allow_c_comments = 0;
            else if (strcmp(name, "no-yaml-comments") == 0)
                config.allow_yaml_comments = 0;
            else if (strcmp(name, "no-comments") == 0)
                config.allow_c_comments = config.allow_yaml_comments = 0;
            else if (strcmp(name, "format") == 0)
                format = 1;
            else if (strcmp(name, "verify") == 0)
                verify = 1;
            else if (strcmp(name, "max-nesting") == 0)
                config.max_nesting = atoi(optarg);
            else if (strcmp(name, "benchmark") == 0)
                benchmarks = atoi(optarg);
            else if (strcmp(name, "max-data") == 0)
                config.max_data = atoi(optarg);
            else if (strcmp(name, "indent-string") == 0)
                indent_string = strdup(optarg);
            else if (strcmp(name, "tree") == 0)
                use_tree = 1;
            break;
        }
        case 'o':
            output = strdup(optarg);
            break;
        default:
            break;
        }
    }
    if (config.max_nesting < 0)
        config.max_nesting = 0;
    if (!output)
        output = "-";
    if (optind >= argc)
        usage(argv[0]);

    if (benchmarks > 0) {
        for (i = 0; i < benchmarks; i++) {
            if (use_tree) {
                json_val_t *root_structure;
                ret = do_tree(&config, argv[optind], &root_structure);
            } else {
                ret = do_verify(&config, argv[optind]);
            }
            if (ret)
                exit(ret);
        }
        exit(0);
    }

    for (i = optind; i < argc; i++) {
        if (use_tree) {
            json_val_t *root_structure;
            ret = do_tree(&config, argv[i], &root_structure);
            if (ret)
                exit(ret);
            if (!verify)
                print_tree(root_structure, output);
        } else {
            if (format)
                ret = do_format(&config, argv[i], output);
            else if (verify)
                ret = do_verify(&config, argv[i]);
            else
                ret = do_parse(&config, argv[i]);
        }
        if (ret)
            exit(ret);
    }
    return ret;
}
コード例 #29
0
int update_binary_tool_main(int argc, char *argv[])
{
    int opt;

    static struct option long_options[] = {
        {"help", no_argument, 0, 'h'},
        {0, 0, 0, 0}
    };

    int long_index = 0;

    while ((opt = getopt_long(argc, argv, "h", long_options, &long_index)) != -1) {
        switch (opt) {
        case 'h':
            update_binary_tool_usage(0);
            return EXIT_SUCCESS;

        default:
            update_binary_tool_usage(1);
            return EXIT_FAILURE;
        }
    }

    if (argc - optind != 2) {
        update_binary_tool_usage(1);
        return EXIT_FAILURE;
    }

    // Log to stderr, so the output is ordered correctly in /tmp/recovery.log
    util::log_set_logger(std::make_shared<util::StdioLogger>(stderr));

    std::string action = argv[optind];
    std::string mountpoint = argv[optind + 1];

    if (action != ACTION_MOUNT
            && action != ACTION_UNMOUNT
            && action != ACTION_FORMAT) {
        update_binary_tool_usage(1);
        return EXIT_FAILURE;
    }

    if (mountpoint != SYSTEM
            && mountpoint != CACHE
            && mountpoint != DATA) {
        update_binary_tool_usage(1);
        return EXIT_FAILURE;
    }

    if (access("/.chroot", F_OK) < 0) {
        fprintf(stderr, "update-binary-tool must be run inside the chroot\n");
        return EXIT_FAILURE;
    }

    bool ret = false;

    if (action == ACTION_MOUNT) {
        ret = do_mount(mountpoint);
    } else if (action == ACTION_UNMOUNT) {
        ret = do_unmount(mountpoint);
    } else if (action == ACTION_FORMAT) {
        ret = do_format(mountpoint);
    }

    return ret ? EXIT_SUCCESS : EXIT_FAILURE;
}
コード例 #30
0
ファイル: burncd.c プロジェクト: edgar-pek/PerspicuOS
int
main(int argc, char **argv)
{
	int arg, addr, ch, fd;
	int dao = 0, eject = 0, fixate = 0, list = 0, multi = 0, preemp = 0;
	int nogap = 0, speed = 4 * 177, test_write = 0, force = 0;
	int block_size = 0, block_type = 0, cdopen = 0, dvdrw = 0;
	const char *dev, *env_speed;

	if (feature_present("ata_cam")) {
		errx(1, "\nATA_CAM option is enabled in kernel.\n"
		    "Install the sysutils/cdrtools port and use cdrecord instead.\n\n"
		    "Please refer to:\n"
		    "http://www.freebsd.org/doc/handbook/creating-cds.html#CDRECORD");
	}

	if ((dev = getenv("CDROM")) == NULL)
		dev = "/dev/acd0";

	env_speed = getenv("BURNCD_SPEED");

	while ((ch = getopt(argc, argv, "def:Flmnpqs:tv")) != -1) {
		switch (ch) {
		case 'd':
			dao = 1;
			break;

		case 'e':
			eject = 1;
			break;

		case 'f':
			dev = optarg;
			break;

		case 'F':
			force = 1;
			break;

		case 'l':
			list = 1;
			break;

		case 'm':
			multi = 1;
			break;

		case 'n':
			nogap = 1;
			break;

		case 'p':
			preemp = 1;
			break;

		case 'q':
			quiet = 1;
			break;

		case 's':
			env_speed = optarg;
			break;

		case 't':
			test_write = 1;
			break;

		case 'v':
			verbose = 1;
			break;

		default:
			usage();
		}
	}
	argc -= optind;
	argv += optind;

	if (env_speed == NULL)
		;
	else if (strcasecmp("max", env_speed) == 0)
		speed = CDR_MAX_SPEED;
	else
		speed = atoi(env_speed) * 177;
	if (speed <= 0)
		errx(EX_USAGE, "Invalid speed: %s", env_speed);

	if (argc == 0)
		usage();

	if ((fd = open(dev, O_RDWR, 0)) < 0)
		err(EX_NOINPUT, "open(%s)", dev);

	if (ioctl(fd, CDRIOCGETBLOCKSIZE, &saved_block_size) < 0)
		err(EX_IOERR, "ioctl(CDRIOCGETBLOCKSIZE)");

	if (ioctl(fd, CDRIOCWRITESPEED, &speed) < 0)
		err(EX_IOERR, "ioctl(CDRIOCWRITESPEED)");

	global_fd_for_cleanup = fd;
	err_set_exit(cleanup);
	signal(SIGHUP, cleanup_signal);
	signal(SIGINT, cleanup_signal);
	signal(SIGTERM, cleanup_signal);

	for (arg = 0; arg < argc; arg++) {
		if (!strcasecmp(argv[arg], "fixate")) {
			fixate = 1;
			continue;
		}
		if (!strcasecmp(argv[arg], "eject")) {
			eject = 1;
			break;
		}
		if (!strcasecmp(argv[arg], "msinfo")) {
			struct ioc_read_toc_single_entry entry;
			struct ioc_toc_header header;

			if (ioctl(fd, CDIOREADTOCHEADER, &header) < 0)
				err(EX_IOERR, "ioctl(CDIOREADTOCHEADER)");
			bzero(&entry, sizeof(struct ioc_read_toc_single_entry));
			entry.address_format = CD_LBA_FORMAT;
			entry.track = header.ending_track;
			if (ioctl(fd, CDIOREADTOCENTRY, &entry) < 0)
				err(EX_IOERR, "ioctl(CDIOREADTOCENTRY)");
			if (ioctl(fd, CDRIOCNEXTWRITEABLEADDR, &addr) < 0)
				err(EX_IOERR, "ioctl(CDRIOCNEXTWRITEABLEADDR)");
			fprintf(stdout, "%d,%d\n",
				ntohl(entry.entry.addr.lba), addr);

			break;
		}
		if ((!strcasecmp(argv[arg], "erase") ||
		     !strcasecmp(argv[arg], "blank")) && !test_write) {
			int blank, pct, last = 0;

			if (!strcasecmp(argv[arg], "erase"))
				blank = CDR_B_ALL;
			else
				blank = CDR_B_MIN;
			if (!quiet)
				fprintf(stderr, "%sing CD, please wait..\r",
					blank == CDR_B_ALL ? "eras" : "blank");

			if (ioctl(fd, CDRIOCBLANK, &blank) < 0)
				err(EX_IOERR, "ioctl(CDRIOCBLANK)");
			while (1) {
				sleep(1);
				if (ioctl(fd, CDRIOCGETPROGRESS, &pct) == -1)
					err(EX_IOERR,"ioctl(CDRIOGETPROGRESS)");
				if (pct > 0 && !quiet)
					fprintf(stderr,
						"%sing CD - %d %% done     \r",
						blank == CDR_B_ALL ?
						"eras" : "blank", pct);
				if (pct == 100 || (pct == 0 && last > 90))
					break;
				last = pct;
			}
			if (!quiet)
				printf("\n");
			continue;
		}
		if (!strcasecmp(argv[arg], "format") && !test_write) {
			if (arg + 1 < argc &&
				(!strcasecmp(argv[arg + 1], "dvd+rw") ||
				!strcasecmp(argv[arg + 1], "dvd-rw")))
				do_format(fd, force, argv[arg + 1]);
			else
				errx(EX_NOINPUT, "format media type invalid");
			arg++;
			continue;
		}
		if (!strcasecmp(argv[arg], "audio") || !strcasecmp(argv[arg], "raw")) {
			block_type = CDR_DB_RAW;
			block_size = 2352;
			continue;
		}
		if (!strcasecmp(argv[arg], "data") || !strcasecmp(argv[arg], "mode1")) {
			block_type = CDR_DB_ROM_MODE1;
			block_size = 2048;
			continue;
		}
		if (!strcasecmp(argv[arg], "mode2")) {
			block_type = CDR_DB_ROM_MODE2;
			block_size = 2336;
			continue;
		}
		if (!strcasecmp(argv[arg], "xamode1")) {
			block_type = CDR_DB_XA_MODE1;
			block_size = 2048;
			continue;
		}
		if (!strcasecmp(argv[arg], "xamode2")) {
			block_type = CDR_DB_XA_MODE2_F2;
			block_size = 2324;
			continue;
		}
		if (!strcasecmp(argv[arg], "vcd")) {
			block_type = CDR_DB_XA_MODE2_F2;
			block_size = 2352;
			dao = 1;
			nogap = 1;
			continue;
		}
		if (!strcasecmp(argv[arg], "dvdrw")) {
			block_type = CDR_DB_ROM_MODE1;
			block_size = 2048;
			dvdrw = 1;
			continue;
		}

		if (!block_size)
			errx(EX_NOINPUT, "no data format selected");
		if (list) {
			char file_buf[MAXPATHLEN + 1], *eol;
			FILE *fp;

			if ((fp = fopen(argv[arg], "r")) == NULL)
				err(EX_NOINPUT, "fopen(%s)", argv[arg]);

			while (fgets(file_buf, sizeof(file_buf), fp) != NULL) {
				if (*file_buf == '#' || *file_buf == '\n')
					continue;
				if ((eol = strchr(file_buf, '\n')))
					*eol = '\0';
				add_track(file_buf, block_size, block_type, nogap);
			}
			if (feof(fp))
				fclose(fp);
			else
				err(EX_IOERR, "fgets(%s)", file_buf);
		}
		else
			add_track(argv[arg], block_size, block_type, nogap);
	}
	if (notracks) {
		if (dvdrw && notracks > 1)
			errx(EX_USAGE, "DVD's only have 1 track");
		if (ioctl(fd, CDIOCSTART, 0) < 0)
			err(EX_IOERR, "ioctl(CDIOCSTART)");
		if (!cdopen) {
			if (ioctl(fd, CDRIOCINITWRITER, &test_write) < 0)
				err(EX_IOERR, "ioctl(CDRIOCINITWRITER)");
			cdopen = 1;
		}
		if (dao)
			do_DAO(fd, test_write, multi);
		else
			do_TAO(fd, test_write, preemp, dvdrw);
	}
	if (!test_write && fixate && !dao && !dvdrw) {
		if (!quiet)
			fprintf(stderr, "fixating CD, please wait..\n");
		if (ioctl(fd, CDRIOCFIXATE, &multi) < 0)
			err(EX_IOERR, "ioctl(CDRIOCFIXATE)");
	}

	if (ioctl(fd, CDRIOCSETBLOCKSIZE, &saved_block_size) < 0) {
		err_set_exit(NULL);
		err(EX_IOERR, "ioctl(CDRIOCSETBLOCKSIZE)");
	}

	if (eject)
		if (ioctl(fd, CDIOCEJECT) < 0)
			err(EX_IOERR, "ioctl(CDIOCEJECT)");

	signal(SIGHUP, SIG_DFL);
	signal(SIGINT, SIG_DFL);
	signal(SIGTERM, SIG_DFL);
	close(fd);
	exit(EX_OK);
}