Exemple #1
0
int do_fat_fsload (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
{
	long size;
	unsigned long offset;
	unsigned long count;
	char buf [12];
	block_dev_desc_t *dev_desc=NULL;
	int dev=0;
	int part=1;
	char *ep;

	if (argc < 5) {
		out_err("%s", ERR_ARGS);
		printf ("usage: fatload <interface> <dev[:part]> <addr> <filename> [bytes]\n");
		return 1;
	}
	dev = (int)simple_strtoul (argv[2], &ep, 16);
	dev_desc=get_dev(argv[1],dev);
	if (dev_desc==NULL) {
		out_err("%s", ERR_NFOUND);
		puts ("\n** Invalid boot device **\n");
		return 1;
	}
	if (*ep) {
		if (*ep != ':') {
			out_err("%s", ERR_EINVAL);
			puts ("\n** Invalid boot device, use `dev[:part]' **\n");
			return 1;
		}
		part = (int)simple_strtoul(++ep, NULL, 16);
	}
	if (fat_register_device(dev_desc,part)!=0) {
		out_err("%s", ERR_OPER);
		printf ("\n** Unable to use %s %d:%d for fatload **\n",argv[1],dev,part);
		return 1;
	}
	offset = simple_strtoul (argv[3], NULL, 16);
	if (argc == 6)
		count = simple_strtoul (argv[5], NULL, 16);
	else
		count = 0;
	size = file_fat_read (argv[4], (unsigned char *) offset, count);

	if(size==-1) {
		out_err("%s", ERR_NFOUND);
		printf("\n** Unable to read \"%s\" from %s %d:%d **\n",argv[4],argv[1],dev,part);
		return 1;
	}

	printf ("\n%ld bytes read\n", size);

	sprintf(buf, "%lX", size);
	setenv("filesize", buf);

	out_res("0 \n");

	return 0;
}
static void
dialog_init(ClipMachine * ClipMachineMemory)
{
   if (!ClipMachineMemory->fullscreen)
   {
      static int dialog = 0;

      if (!dialog)
      {
	 int r = _clip_init_tty(ClipMachineMemory);

	 if (!r)
	    dialog = 1;
	 else
	 {
	    int l;

	    char msg[256];

	    snprintf(msg, sizeof(msg), "\nrequest to switch into DIALOG mode failed: %s\n", ClipMachineMemory->syserr);
	    l = strlen(msg);
	    out_log(ClipMachineMemory, msg, l, 0);
	    out_err(ClipMachineMemory, msg, l, 0);
	    exit(2);
	 }
      }
/*_clip_restore_tty(ClipMachineMemory);*/
   }
}
Exemple #3
0
void
_clip_fullscreen(ClipMachine * ClipMachineMemory)
{
   if (ClipMachineMemory->fullscreen)
      return;
   ClipMachineMemory->fullscreen = 1;
   _clip_init_tty(ClipMachineMemory);
   if (!ClipMachineMemory->screen)
   {
      char msg[256];

      int l;

      ClipFrame *fp;

      snprintf(msg, sizeof(msg), "request to switch into FULLSCREEN mode failed: %s\n", ClipMachineMemory->syserr);
      l = strlen(msg);
      out_log(ClipMachineMemory, msg, l, 0);
      out_err(ClipMachineMemory, msg, l, 0);
      for (fp = ClipMachineMemory->fp; fp; fp = fp->ClipFrame_up_of_ClipFrame)
      {
	 _clip_logg(0, "trace: file '%s' line %d", fp->filename_of_ClipFrame, fp->line_of_ClipFrame);
	 fprintf(stderr, "trace: file '%s' line %d\n", fp->filename_of_ClipFrame, fp->line_of_ClipFrame);
	 fflush(stderr);
      }

      exit(2);
   }
   /*clear_Screen(ClipMachineMemory->screen); */
}
Exemple #4
0
int
main(int argc, const char *argv[])
{
	if (argc < 2) {
		fprintf(stderr, "Usage: %s filename len\n", argv[0]);
		exit(1);
	}

	int i = 1;
	while (i < argc && argv[i][0] == '-') {
		switch (argv[i][1]) {
			case 'v':
				Opt_verbose = 1;
				break;
			case 's':
				Opt_sparse = 1;
				break;
			case 'f':
				Opt_force = 1;
				break;
			default:
				out_err("Unknown option: \'%c\'.", argv[i][1]);
				exit(2);
		}
		++i;
	}

	const char *filename = argv[i];
	long long len = atoll(argv[i + 1]);

	if (len < 0) {
		out_err("Invalid file length: %lld.\n", len);
		exit(3);
	}

	if (create_sparse_file(filename, len) < 0) {
		out_err("File creation failed.");
		exit(4);
	}

	if (Opt_verbose)
		print_file_size(filename);

	return 0;
}
Exemple #5
0
/*
 * print_file_size -- prints file size and its size on disk
 */
static void
print_file_size(const char *filename)
{
	LARGE_INTEGER filesize;
	FILE_COMPRESSION_INFO fci;

	HANDLE fh = CreateFileA(filename, GENERIC_READ,
			FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
			OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
	if (fh == INVALID_HANDLE_VALUE) {
		out_err("CreateFile");
		return;
	}

	BOOL ret = GetFileSizeEx(fh, &filesize);
	if (ret == FALSE) {
		out_err("GetFileSizeEx");
		goto err;
	}

	ret = GetFileInformationByHandleEx(fh, FileCompressionInfo,
			&fci, sizeof(fci));
	if (ret == FALSE) {
		out_err("GetFileInformationByHandleEx");
		goto err;
	}

	if (filesize.QuadPart < 65536)
		fprintf(stderr, "\ntotal size: %lluB",
				filesize.QuadPart);
	else
		fprintf(stderr, "\ntotal size: %lluKB",
				filesize.QuadPart / 1024);

	if (fci.CompressedFileSize.QuadPart < 65536)
		fprintf(stderr, ", actual size on disk: %lluKB\n",
				fci.CompressedFileSize.QuadPart);
	else
		fprintf(stderr, ", actual size on disk: %lluKB\n",
				fci.CompressedFileSize.QuadPart / 1024);

err:
	CloseHandle(fh);
}
Exemple #6
0
int
main(int argc, char *argv[])
{
	char buff[UT_MAX_ERR_MSG];

	START(argc, argv, "out_err");

	/* Execute test */
	common_init(LOG_PREFIX, LOG_LEVEL_VAR, LOG_FILE_VAR,
			MAJOR_VERSION, MINOR_VERSION);

	errno = 0;
	ERR("ERR #%d", 1);
	UT_OUT("%s", out_get_errormsg());

	errno = 0;
	ERR("!ERR #%d", 2);
	UT_OUT("%s", out_get_errormsg());

	errno = EINVAL;
	ERR("!ERR #%d", 3);
	UT_OUT("%s", out_get_errormsg());

	errno = EBADF;
	ut_strerror(errno, buff, UT_MAX_ERR_MSG);
	out_err(__FILE__, 100, __func__,
		"ERR1: %s:%d", buff, 1234);
	UT_OUT("%s", out_get_errormsg());

	errno = EBADF;
	ut_strerror(errno, buff, UT_MAX_ERR_MSG);
	out_err(NULL, 0, NULL,
		"ERR2: %s:%d", buff, 1234);
	UT_OUT("%s", out_get_errormsg());

	/* Cleanup */
	common_fini();

	DONE(NULL);
}
Exemple #7
0
/*
 * help_func -- prints help message for specified command
 */
static int
help_func(char *appname, int argc, char *argv[])
{
	if (argc > 1) {
		char *cmd_str = argv[1];
		struct command *cmdp = get_command(cmd_str);

		if (cmdp && cmdp->help) {
			cmdp->help(appname);
			return 0;
		} else {
			out_err("No help text for '%s' command\n", cmd_str);
			return -1;
		}
	} else {
		print_help(appname);
		return -1;
	}
}
Exemple #8
0
int
main(int argc, char *argv[])
{
	int opt;
	int option_index;

	char *appname = basename(argv[0]);
	if (argc < 2) {
		print_usage(appname);
		return 0;
	}

	while ((opt = getopt_long(2, argv, "Vh",
			long_options, &option_index)) != -1) {
		switch (opt) {
		case 'V':
			print_version(appname);
			return 0;
		case 'h':
			print_help(appname);
			return 0;
		default:
			print_usage(appname);
			return -1;
		}
	}

	char *cmd_str = argv[optind];

	struct command *cmdp = get_command(cmd_str);

	if (cmdp)
		return cmdp->func(appname, argc - 1, argv + 1);

	out_err("'%s' -- unknown command\n", cmd_str);

	return -1;
}
Exemple #9
0
void Viewer::init() {

  // initialize glfw
  glfwSetErrorCallback( err_callback );
  if( !glfwInit() ) {
    out_err("Error: could not initialize GLFW!");
    exit( 1 );
  }

  // create window
  string title = renderer ? "CMU462: " + renderer->name() : "CMU462";
  window = glfwCreateWindow( DEFAULT_W, DEFAULT_H, title.c_str(), NULL, NULL );
  if (!window) {
    out_err("Error: could not create window!");
    glfwTerminate();
    exit( 1 );
  }

  // set context
  glfwMakeContextCurrent( window );
  glfwSwapInterval(1);

  // framebuffer event callbacks
  glfwSetFramebufferSizeCallback( window, resize_callback );
  
  // key event callbacks
  glfwSetKeyCallback( window, key_callback );
  
  // cursor event callbacks
  glfwSetCursorPosCallback( window, cursor_callback );

  // wheel event callbacks
  glfwSetScrollCallback(window, scroll_callback);  
  
  // mouse button callbacks
  glfwSetInputMode(window, GLFW_STICKY_MOUSE_BUTTONS, 1);
  glfwSetMouseButtonCallback(window, mouse_button_callback);

  // initialize glew
  if (glewInit() != GLEW_OK) {
    out_err("Error: could not initialize GLEW!");
    glfwTerminate();
    exit( 1 );
  }

  // enable alpha blending
  glEnable(GL_BLEND);
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  // resize components to current window size, get DPI
  glfwGetFramebufferSize(window, (int*) &buffer_w, (int*) &buffer_h );
  if( buffer_w > DEFAULT_W ) HDPI = true;

  // initialize renderer if already set
  if (renderer){
    if (HDPI) renderer->use_hdpi_reneder_target();
    renderer->init();
  } 

  // initialize status OSD
  osd_text = new OSDText();
  if (osd_text->init(HDPI) < 0) {
    out_err("Error: could not initialize on-screen display!");
    exit( 1 );
  }
  
  // add lines for renderer and fps
  line_id_renderer  = osd_text->add_line(-0.95,  0.90, "Renderer", 
                                          18, Color(0.15, 0.5, 0.15));
  line_id_framerate = osd_text->add_line(-0.98, -0.96, "Framerate", 
                                          14, Color(0.15, 0.5, 0.15));

  // resize elements to current size
  resize_callback(window, buffer_w, buffer_h);

}
Exemple #10
0
void Viewer::err_callback( int error, const char* description ) {
    out_err( "GLFW Error: " << description );
}
Exemple #11
0
/*
 * create_sparse_file -- creates sparse file of given size
 */
static int
create_sparse_file(const char *filename, size_t len)
{
	/* create zero-length file */
	DWORD create = Opt_force ? CREATE_ALWAYS : CREATE_NEW;
	HANDLE fh = CreateFileA(filename, GENERIC_READ | GENERIC_WRITE,
			FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
			create, FILE_ATTRIBUTE_NORMAL, NULL);
	if (fh == INVALID_HANDLE_VALUE) {
		out_err("CreateFile");
		return -1;
	}
	SetLastError(0);

	/* check if sparse files are supported */
	DWORD flags = 0;
	BOOL ret = GetVolumeInformationByHandleW(fh, NULL, 0, NULL, NULL,
			&flags, NULL, 0);
	if (ret == FALSE) {
		if (Opt_verbose || Opt_sparse)
			out_err("GetVolumeInformationByHandle");
	} else if ((flags & FILE_SUPPORTS_SPARSE_FILES) == 0) {
		if (Opt_verbose || Opt_sparse)
			out_err("Volume does not support sparse files.");
		if (Opt_sparse)
			goto err;
	}

	/* mark file as sparse */
	if (flags & FILE_SUPPORTS_SPARSE_FILES) {
		DWORD nbytes;
		ret = DeviceIoControl(fh, FSCTL_SET_SPARSE, NULL, 0, NULL,
				0, &nbytes, NULL);
		if (ret == FALSE) {
			if (Opt_verbose || Opt_sparse)
				out_err("DeviceIoControl");
			if (Opt_sparse)
				goto err;
		}
	}

	/* set file length */
	LARGE_INTEGER llen;
	llen.QuadPart = len;

	DWORD ptr = SetFilePointerEx(fh, llen, NULL, FILE_BEGIN);
	if (ptr == INVALID_SET_FILE_POINTER) {
		out_err("SetFilePointerEx");
		goto err;
	}

	ret = SetEndOfFile(fh);
	if (ret == FALSE) {
		out_err("SetEndOfFile");
		goto err;
	}

	CloseHandle(fh);
	return 0;

err:
	CloseHandle(fh);
	DeleteFileA(filename);
	return -1;
}