Beispiel #1
0
int
dladdr(void *address, Dl_info *info)
{
	image_id image;
	char* imagePath;
	char* symbolName;
	void* location;
	image_info imageInfo;

	sStatus = __gRuntimeLoader->get_nearest_symbol_at_address(address, &image,
		&imagePath, &symbolName, NULL, &location);
	if (sStatus != B_OK)
		return 0;

	sStatus = get_image_info(image, &imageInfo);
	if (sStatus != B_OK)
		return 0;

	info->dli_fname = imagePath;
	info->dli_fbase = imageInfo.text;
	info->dli_sname = symbolName;
	info->dli_saddr = location;

	return 1;
}
Beispiel #2
0
error*
image__get_image_info(clobj_t _img, cl_image_info param, generic_info *out)
{
    auto img = static_cast<image*>(_img);
    return c_handle_error([&] {
            *out = img->get_image_info(param);
        });
}
Beispiel #3
0
/**
 * Return the name of the current process.
 * \param procname  returns the process name
 * \param size  size of the procname buffer
 * \return  TRUE or FALSE for success, failure
 */
boolean
os_get_process_name(char *procname, size_t size)
{
   const char *name;

   /* First, check if the GALLIUM_PROCESS_NAME env var is set to
    * override the normal process name query.
    */
   name = os_get_option("GALLIUM_PROCESS_NAME");

   if (!name) {
      /* do normal query */

#if defined(PIPE_SUBSYSTEM_WINDOWS_USER)
      char szProcessPath[MAX_PATH];
      char *lpProcessName;
      char *lpProcessExt;

      GetModuleFileNameA(NULL, szProcessPath, Elements(szProcessPath));

      lpProcessName = strrchr(szProcessPath, '\\');
      lpProcessName = lpProcessName ? lpProcessName + 1 : szProcessPath;

      lpProcessExt = strrchr(lpProcessName, '.');
      if (lpProcessExt) {
         *lpProcessExt = '\0';
      }

      name = lpProcessName;

#elif defined(__GLIBC__) || defined(__CYGWIN__)
      name = program_invocation_short_name;
#elif defined(PIPE_OS_BSD) || defined(PIPE_OS_APPLE)
      /* *BSD and OS X */
      name = getprogname();
#elif defined(PIPE_OS_HAIKU)
      image_info info;
      get_image_info(B_CURRENT_TEAM, &info);
      name = info.name;
#else
#warning unexpected platform in os_process.c
      return FALSE;
#endif

   }

   assert(size > 0);
   assert(procname);

   if (name && procname && size > 0) {
      strncpy(procname, name, size);
      procname[size - 1] = '\0';
      return TRUE;
   }
   else {
      return FALSE;
   }
}
static gpointer
_g_module_symbol (gpointer     handle,
		  const gchar *symbol_name)
{
  image_id id;
  status_t status;
  image_info info;
  int32 type, name_len;
  void *p;
  gchar *msg, name[256];
  gint n, l;
  
  id = (image_id) handle;
  
  status = get_image_info (id, &info);
  if (status != B_OK)
    {
      msg = g_strdup_printf ("failed to get_image_info(): %s", strerror (status));
      g_module_set_error (msg);
      g_free (msg);
      
      return NULL;
    }
  
  l = strlen (symbol_name);
  name_len = 256;
  type = B_SYMBOL_TYPE_ANY;
  n = 0;
  status = get_nth_image_symbol (id, n, name, &name_len, &type, &p);
  while (status == B_OK)
    {
      if (p && strncmp (name, symbol_name, l) == 0)
	return p;
      
      if (strcmp (name, "_end") == 0)
        {
	  msg = g_strdup_printf ("unmatched symbol name `%s'", symbol_name);
          g_module_set_error (msg);
	  g_free (msg);
	  
	  return NULL;
        }
      
      name_len = 256;
      type = B_SYMBOL_TYPE_ANY;
      n++;
      status = get_nth_image_symbol (id, n, name, &name_len, &type, &p);
    }
  
  msg = g_strdup_printf ("failed to get_image_symbol(%s): %s", symbol_name, strerror (status));
  g_module_set_error (msg);
  g_free (msg);
  
  return NULL;
}
static GstCaps *
get_caps (GUPnPDLNAGstImageInformation *gst_info)
{
    GUPnPDLNAGstImageInformationPrivate *priv = gst_info->priv;

    if (!priv->caps)
        priv->caps = gst_discoverer_stream_info_get_caps
                     (GST_DISCOVERER_STREAM_INFO
                      (get_image_info (gst_info)));

    return priv->caps;
}
static GUPnPDLNAIntValue
backend_get_depth (GUPnPDLNAImageInformation *self)
{
    GUPnPDLNAGstImageInformation *gst_info =
        GUPNP_DLNA_GST_IMAGE_INFORMATION (self);
    GstDiscovererVideoInfo *image_info = get_image_info (gst_info);
    guint data = gst_discoverer_video_info_get_depth (image_info);
    GUPnPDLNAIntValue value = GUPNP_DLNA_INT_VALUE_UNSET;

    if (data > 0 && data <= G_MAXINT) {
        value.state = GUPNP_DLNA_VALUE_STATE_SET;
        value.value = (gint) data;
    }

    return value;
}
Beispiel #7
0
BImageResources::BImageResources(void* memAddr)
{
    image_id image = find_image(memAddr);
    image_info info;
    if (get_image_info(image, &info) == B_OK) {
#if _SUPPORTS_RESOURCES
        BFile file(&info.name[0], B_READ_ONLY);
#else
        BString name(&info.name[0]);
        name += ".rsrc";
        BFile file(name.String(), B_READ_ONLY);
#endif
        if (file.InitCheck() == B_OK)
            fResources.SetTo(&file);
    }
}
void BoolRenderer::Init()
{
	TRACE();
	image_info	*info 	= new image_info;
	size_t		size;
	// look up the plugininfos
	get_image_info(editor->PluginID(),info);
	// init the ressource for the plugin files
	BResources *res=new BResources(new BFile((const char*)info->name,B_READ_ONLY));
	// load the addBool icon
	const void *data=res->LoadResource((type_code)'PNG ',"addBool",&size);
	if (data)
		//translate the icon because it was png but we ne a bmp 
		selected	= BTranslationUtils::GetBitmap(new BMemoryIO(data,size));
	data=res->LoadResource((type_code)'PNG ',"unselectedBool",&size);
	if (data)
		unselected	= BTranslationUtils::GetBitmap(new BMemoryIO(data,size));
}
Beispiel #9
0
void print_symbol( int nIndex, uint32 nAddress )
{
	int nModule;
	char zSymName[256];
	char zModuleName[64];
	void *pSymAddr = NULL;
	uint32 nTxtAddr = 0;

	printk( "%d -> %08x\n", nIndex, nAddress );

	nModule = find_module_by_address( ( void * )nAddress );
	if ( nModule >= 0 )
	{
		image_info sInfo;

		if ( get_image_info( nAddress < AREA_FIRST_USER_ADDRESS, nModule, -1, &sInfo ) >= 0 )
		{
			strncpy( zModuleName, sInfo.ii_name, 64 );
			zModuleName[63] = '\0';
			nTxtAddr = ( uint32 )sInfo.ii_text_addr;
		}
		else
		{			
			strcpy( zModuleName, "*unknown*" );
		}
		if ( get_symbol_by_address( nModule, ( const char * )nAddress, zSymName, 256, &pSymAddr ) < 0 )
		{
			strcpy( zSymName, "*unknown*" );
		}
	}
	else
	{
		strcpy( zModuleName, "*unknown*" );
		strcpy( zSymName, "*unknown*" );
	}
	
	printk( "   %s + %08x -> %s + %08x\n", zModuleName, nAddress - nTxtAddr, zSymName, nAddress - ( uint32 )pSymAddr );
}
static void
_g_module_close (gpointer handle,
		 gboolean is_unref)
{
  image_info info;
  gchar *name;
  
  if (unload_add_on ((image_id) handle) != B_OK)
    {
      gchar *msg;
      
      /* Try and get the name of the image. */
      if (get_image_info ((image_id) handle, &info) != B_OK)
	name = g_strdup ("unknown");
      else
	name = g_strdup (info.name);
      
      msg = g_strdup_printf ("failed to unload_add_on(%s): %s", name, strerror (status));
      g_module_set_error (msg);
      g_free (msg);
      g_free (name);
    }
}
Beispiel #11
0
int ploop_copy_init(struct ploop_disk_images_data *di,
		struct ploop_copy_param *param,
		struct ploop_copy_handle **h)
{
	int ret, err;
	int blocksize;
	char *image = NULL;
	char *format = NULL;
	char device[64];
	char partdev[64];
	struct ploop_copy_handle  *_h = NULL;
	int is_remote;
	char mnt[PATH_MAX] = "";

	is_remote = is_fd_socket(param->ofd);
	if (is_remote < 0) {
		ploop_err(0, "Invalid output fd %d: must be a file, "
				"a pipe or a socket", param->ofd);
		return SYSEXIT_PARAM;
	}

	if (param->ofd == STDOUT_FILENO)
		ploop_set_verbose_level(PLOOP_LOG_NOSTDOUT);
	else if (param->ofd == STDERR_FILENO)
		ploop_set_verbose_level(PLOOP_LOG_NOCONSOLE);

	if (ploop_lock_dd(di))
		return SYSEXIT_LOCK;

	if (ploop_find_dev_by_dd(di, device, sizeof(device))) {
		ploop_err(0, "Can't find running ploop device");
		ret = SYSEXIT_SYS;
		goto err;
	}

	ret = get_image_info(device, &image, &format, &blocksize);
	if (ret)
		goto err;


	_h = alloc_ploop_copy_handle(S2B(blocksize));
	if (_h == NULL) {
		ploop_err(0, "alloc_ploop_copy_handle");
		ret = SYSEXIT_MALLOC;
		goto err;
	}

	_h->raw = strcmp(format, "raw") == 0;
	_h->ofd = param->ofd;
	_h->is_remote = is_remote;
	_h->async = param->async;

	_h->devfd = open(device, O_RDONLY|O_CLOEXEC);
	if (_h->devfd == -1) {
		ploop_err(errno, "Can't open device %s", device);
		ret = SYSEXIT_DEVICE;
		goto err;
	}

	ret = get_partition_device_name(device, partdev, sizeof(partdev));
	if (ret)
		goto err;

	_h->partfd = open(partdev, O_RDONLY|O_CLOEXEC);
	if (_h->partfd == -1) {
		ploop_err(errno, "Can't open device %s", partdev);
		ret = SYSEXIT_DEVICE;
		goto err;
	}

	ret = SYSEXIT_OPEN;
	err = ploop_get_mnt_by_dev(device, mnt, sizeof(mnt));
	if (err == -1)
		goto err;
	else if (err == 0) {
		_h->mntfd = open(mnt, O_RDONLY|O_NONBLOCK|O_DIRECTORY);
		if (_h->mntfd < 0) {
			ploop_err(errno, "Can't open %s", mnt);
			goto err;
		}
	}

	ploop_log(0, "Send image %s dev=%s mnt=%s fmt=%s blocksize=%d local=%d",
			image, device, mnt, format, blocksize, !is_remote);

	if (open_delta(&_h->idelta, image, O_RDONLY|O_DIRECT, OD_ALLOW_DIRTY)) {
		ret = SYSEXIT_OPEN;
		goto err;
	}

	ret = complete_running_operation(di, device);
	if (ret)
		goto err;

	_h->cl = register_cleanup_hook(cancel_sender, _h);

	pthread_mutex_lock(&_h->sd.wait_mutex);
err:
	if (ret) {
		ploop_copy_release(_h);
		free_ploop_copy_handle(_h);
	} else
		*h = _h;

	free(image);
	ploop_unlock_dd(di);

	return ret;
}
Beispiel #12
0
void insert_image (gchar *a_filename)
{
  if (! a_filename)
     return;

  if (! g_file_test (a_filename, G_FILE_TEST_EXISTS))
     return;

  t_image_info *ii = get_image_info (a_filename);

  gchar *dir = g_path_get_dirname (cur_text_doc->file_name);
  gchar *filename = create_relative_link_to (dir, a_filename);
 
  if (! filename) 
     {
      g_free (dir); 
      return;
     }
       
  gchar *t;
  gchar *x = g_strrstr (filename, G_DIR_SEPARATOR_S);
  if (x)
     t = g_utf8_next_char (x);
  else
      t = filename; 

  gchar *temp = g_malloc (7777);

  if (! confile.xhtml_mode)
     {
      if (ii)
         g_snprintf (temp,
                     7777,
                     "<img src=\"%s\" border=\"0\" alt=\"\" width=\"%d\" height=\"%d\">",
                      t, ii->width, ii->height);
      else
          g_snprintf (temp,
                      7777,
                      "<img src=\"%s\" border=\"0\" alt=\"\" width=\"\" height=\"\">",
                      t);
      }
  else
      {
       if (ii)
          g_snprintf (temp,
                      7777,
                      "<img src=\"%s\" border=\"0\" alt=\"\" width=\"%d\" height=\"%d\" />",
                      t, ii->width, ii->height);
      else
          g_snprintf (temp,
                      7777,
                      "<img src=\"%s\" border=\"0\" alt=\"\" width=\"\" height=\"\" />",
                      t); 
      }

  doc_insert_at_cursor (cur_text_doc, temp);

  g_free (ii);
  g_free (temp);
  g_free (filename);
  g_free (dir);
}
Beispiel #13
0
int OTAClass::beginLocal(uint16_t port, bool reboot_when_success) {

    int ret = -1;

    // variables for image processing
    flash_t flash;
    uint32_t img2_addr, img2_len, img3_addr, img3_len;
    uint32_t img_upper_bound;
    uint32_t checksum = 0;
    uint32_t signature1, signature2;

    // variables for network processing
    int server_socket = -1;
    int client_socket = -1;
    struct sockaddr_in localHost;
    struct sockaddr_in client_addr;
    int socket_error, socket_timeout;
    socklen_t optlen;

    // variables for OTA
    unsigned char *buf = NULL;
    int read_bytes = 0, processed_len;
    uint32_t file_info[3];
    uint32_t ota_len;
    uint32_t ota_blk_size = 0;

    int i, n;

    do {
        sync_ota_addr();

        get_image_info(&img2_addr, &img2_len, &img3_addr, &img3_len);
        img_upper_bound = img2_addr + 0x10 + img2_len; // image2 base + header + len
        if (img3_len > 0) {
            img_upper_bound += 0x10 + img3_len; // image 3 header + len
        }

        if ((ota_addr & 0xfff != 0) || (ota_addr == ~0x0) || (ota_addr < img_upper_bound)) {
            OTA_PRINTF("Invalid OTA address: %08X\r\n", ota_addr);
            break;
        }

        buf = (unsigned char *) malloc (BUFSIZE);
        if (buf == NULL) {
            OTA_PRINTF("Fail to allocate memory\r\n");
            break;
        }

        server_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        if (server_socket < 0) {
            OTA_PRINTF("Fail to create socket\r\n");
            break;
        }

        memset(&localHost, 0, sizeof(localHost));
        localHost.sin_family = AF_INET;
        localHost.sin_port = htons(port);
        localHost.sin_addr.s_addr = INADDR_ANY;

        if (lwip_bind(server_socket, (struct sockaddr *)&localHost, sizeof(localHost)) < 0) {
            OTA_PRINTF("Bind fail\r\n");
            break;
        }

        if (lwip_listen(server_socket , 1) < 0) {
            OTA_PRINTF("Listen fail\r\n");
            break;
        }

        OTA_PRINTF("Wait for client\r\n");
        n = (int) sizeof( client_addr );
        memset(&client_addr, 0, sizeof(client_addr));
        client_socket = lwip_accept(server_socket, (struct sockaddr *) &client_addr, (socklen_t *)&n);
        OTA_PRINTF("Client connected. IP:%s port:%d\r\n\r\n", inet_ntoa(client_addr.sin_addr.s_addr), ntohs(client_addr.sin_port));

        socket_timeout = DEFAULT_IMAGE_DOWNLOAD_TIMEOUT;
        lwip_setsockopt(client_socket, SOL_SOCKET, SO_RCVTIMEO, &socket_timeout, sizeof(socket_timeout));        

        OTA_PRINTF("Read OTA info...\r\n");
        read_bytes = read(client_socket, file_info, sizeof(file_info));
        if (read_bytes < 0) {
           OTA_PRINTF("Fail to read OTA info\r\n");
           break;
        }

        if (file_info[2] == 0) {
            OTA_PRINTF("OTA image len is 0\r\n");
            break;
        }

        ota_len = file_info[2];
        ota_blk_size = ((ota_len - 1) / 4096) + 1;
        for (i = 0; i < ota_blk_size; i++) {
            flash_erase_sector(&flash, ota_addr + i * 4096);
        }

        OTA_PRINTF("Start download\r\n");

        // Now download OTA image
        processed_len = 0;
        while( processed_len < ota_len ) {
            memset(buf, 0, BUFSIZE);
            read_bytes = read(client_socket, buf, BUFSIZE);

            if (read_bytes < 0) {
                optlen = sizeof(socket_error);
                getsockopt(client_socket, SOL_SOCKET, SO_ERROR, &socket_error, &optlen);
                if (socket_error == EAGAIN) {
                    // socket timeout
                }
                break;
            }

            if (flash_stream_write(&flash, ota_addr + processed_len, read_bytes, buf) < 0) {
                OTA_PRINTF("Write sector fail\r\n");
                break;
            }

            processed_len += read_bytes;
        }

        if (processed_len != ota_len) {
            OTA_PRINTF("Download fail\r\n");
            break;
        }

        // Read OTA image from flash and calculate checksum
        checksum = processed_len = 0;
        while ( processed_len < ota_len ) {
            n = (processed_len + BUFSIZE < ota_len) ? BUFSIZE : (ota_len - processed_len);
            flash_stream_read(&flash, ota_addr + processed_len, n, buf);
            for (i=0; i<n; i++) checksum += (buf[i] & 0xFF);
            processed_len += n;
        }

        if (checksum != file_info[0]) {
            OTA_PRINTF("Bad checksum:%d expected:%d\r\n", checksum, file_info[0]);
            break;
        }

        // Put signature for OTA image
        flash_write_word(&flash, ota_addr +  8, 0x35393138);
        flash_write_word(&flash, ota_addr + 12, 0x31313738);
        flash_read_word(&flash, ota_addr +  8, &signature1);
        flash_read_word(&flash, ota_addr + 12, &signature2);
        if (signature1 != 0x35393138 || signature2 != 0x31313738) {
            OTA_PRINTF("Put signature fail\r\n");
            break;
        }

        // Mark image 2 as old image
        flash_write_word(&flash, img2_addr + 8, 0x35393130);

        ret = 0;
        OTA_PRINTF("OTA success\r\n");

    } while (0);

    if (buf != NULL) {
        free(buf);
    }

    if (server_socket >= 0) {
        close(server_socket);
    }

    if (client_socket >= 0) {
        close(client_socket);
    }

    if (ret < 0) {
        OTA_PRINTF("OTA fail\r\n");
    } else {
        if (reboot_when_success) {
            sys_reset();
        }
    }

    return ret;
}
Beispiel #14
0
int main(int argc, char *argv[])
{
	
	image_info *info;


	int i;
	BYTE *bufp;
	BYTE *ppm, *ptr;
	FILE *fp_src, *fp_dest;
	char *dest;
	BYTE invert=0;
	BYTE qvga = 0;
	int size;
	float gamma_factor;
	BYTE gtable[256];
	int b;
	BYTE *buf;
	BYTE *buf2;
	int WIDTH=176, HEIGHT=144;
	BYTE outdoors;
        GtkWidget *window;
	GtkWidget *image;
	GtkWidget *event_box;
	int current = 1;
	int offset_correct = 0;

	if ( !(argc > 1) ){
		printf("Syntax: show_sonix_raw sourcefile, or \n");
		printf("Syntax: show_sonix_raw -useoffset sourcefile, or \n");
		printf("Syntax: show_sonix_raw -useoffset -invert sourcefile\n");
		return 0;
	}

	if ((strcmp(argv[current], "-qvga") == 0) && (current+1 < argc)) 
	{ 
		qvga = 1;
		offset_correct=8;
		current += 1;
		if (argc != 3) {
			printf("Syntax: show_sonix_raw -qvga sourcefile\n");
			return 0;
		}
	}


	if ( !(argc > 2) && (strcmp(argv[current], "-useoffset") == 0) )
	{
		printf("Syntax: show_sonix_raw sourcefile, or \n");
		printf("Syntax: show_sonix_raw -useoffset sourcefile \n");
		printf("Syntax: show_sonix_raw -useoffset -invert sourcefile\n");
		return 0;
	}

		printf("argc=%i\n", argc);


	if ((strcmp(argv[current], "-useoffset") == 0) && (current+1 < argc)) {
		offset_correct = 8;
		current += 1;
		printf("useoffset option used\n");
		printf("current=%i\n", current);
		if ( !(argc > 2) || !(argc < 5) ){
			printf("Syntax: show_sonix_raw sourcefile, or \n");
			printf("Syntax: show_sonix_raw -useoffset sourcefile, or \n");
			printf("Syntax: show_sonix_raw -useoffset -invert sourcefile, or\n");
			printf("Syntax: show_sonix_raw -qvga sourcefile\n");
			return 0;
		}
	}

	if ( !(argc > 3) && (strcmp(argv[current], "-invert") == 0) )
	{
		printf("Syntax: show_sonix_raw sourcefile, or \n");
		printf("Syntax: show_sonix_raw -useoffset sourcefile, or \n");
		printf("Syntax: show_sonix_raw -useoffset -invert sourcefile\n");
		return 0;
	}

	if ((strcmp(argv[current], "-invert") == 0) && (current+1 < argc)) {
		invert = 1;
		current += 1;
		printf("invert option used\n");
		printf("current=%i\n", current);
		if ( !(argc > 3) || !(argc < 5) ){
			printf("Syntax: show_sonix_raw sourcefile, or \n");
			printf("Syntax: show_sonix_raw -useoffset sourcefile, or \n");
			printf("Syntax: show_sonix_raw -useoffset -invert sourcefile \n");
			return 0;
		}

	}

	printf("Options: offset=%i invert=%i\n", offset_correct, invert);


	fprintf (stderr, "Name of source file is %s\n", argv[current]);
	
	/* input file is raw_(some characters).raw, so, first thing, we find 
	 * the "." in the name.
	 */

	dest = malloc(strlen(argv[current]));
	if (!dest){
		free(dest);
		return -1;
	}

	if ((!strchr(argv[current], 0x2e))|| (strncmp(argv[current], "raw", 3))) {
		fprintf (stderr, "Source file appears not to be a gphoto2 raw file.\n");
		fprintf (stderr, "Its name should begin with raw_ and end with .raw\n");		
		fprintf (stderr, "Exiting.\n");
		return 0; 
	}

	i = strchr(argv[current], 0x2e) - argv[current];

	/* and throw away the period (to avoid clobbering any finished images
	 * from gphoto2 which are in the same directory) and throw away the 
	 * suffix.
	 */

	strncpy(dest, argv[current] + 4, i - 4);
	/* then affix "ppm" as a suffix (no preceding period) */
	strcat (dest, "ppm");
	fprintf (stderr, "Destination file will be called %s\n", dest);
	/* now open the raw file */
	if ( (fp_src = fopen(argv[current], "rb") ) == NULL )
	{
		fprintf (stderr, "Error opening source file.\n");
		return 0;
	}
	/* get the size of the raw file and assign that size to "b" */    
	fseek(fp_src, 0, 2);
	b = ftell(fp_src);
	fseek(fp_src, 0, 0);

	buf = malloc(b);
	if (!buf) return -1;

	/* read the raw file to "buf", and close it */
	fread (buf, 1, b, fp_src);
	fclose (fp_src);

	info = malloc(512);
	if (!info) { free(info); return -1; }


	get_image_info( info, buf, b, qvga);

	/* If there is a header, then we print it as debug output, then 
	 * move past it, to the data. 
	 */
	bufp = buf+offset_correct;
	/* show header */
	for (i = 0; i < HEADER_LEN; i++) {
		fprintf(stderr, " %02X", buf[i]);
	}
	fprintf(stderr, "\n");

	WIDTH = info->width;
	HEIGHT = info->height;
	outdoors = info->outdoors;
	gamma_factor = info->gamma;
	gp_gamma_fill_table(gtable, gamma_factor);
	buf2 = malloc(WIDTH * HEIGHT+256);
	if (!buf2) {
		free (buf2);
		return -1;
	}
	if((offset_correct)&&!(qvga)) {
		info->reverse = 1;
		info->bayer = BAYER_TILE_BGGR;
	}
	if (info->compression) { /* non-zero if compression in use */
		sonix_decode(buf2, bufp, WIDTH,HEIGHT);	
	 } else {
		memcpy(buf2, bufp, WIDTH*HEIGHT);
	}
	free(buf);
	if (invert)
		reverse_bytes(buf2, WIDTH*HEIGHT);
	ppm = malloc (WIDTH * HEIGHT * 3 + 256); /* Data + header */
	if (!ppm) {
		free (buf2);
		return 0;
	}

	memset (ppm, 0, WIDTH * HEIGHT * 3 + 256);

	sprintf ((char *)ppm,
        	"P6\n"
        	"#CREATOR: My_decoder\n"
        	"%d %d\n"
        	"255\n", WIDTH, HEIGHT);

        ptr = ppm + strlen ((char *)ppm);
        size = strlen ((char *)ppm) + (WIDTH * HEIGHT * 3);
	gp_bayer_decode(buf2, WIDTH, HEIGHT, ptr, info->bayer);
	free(buf2);
        white_balance(ptr, WIDTH * HEIGHT, 1.2);

	if ( (fp_dest = fopen(dest, "wb") ) == NULL )
	{
		fprintf (stderr, "Error opening dest file.\n");
		return 0;
	}
	fwrite(ppm, 1, size, fp_dest);
	fclose (fp_dest);
	free (ppm);

	/* The file has been saved. The GUI effects follow now. */
        gtk_init (&argc, &argv);
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);


	event_box = gtk_event_box_new();
	gtk_container_add(GTK_CONTAINER (window), event_box);
	gtk_widget_show(event_box);

	/* This lets the Window Manager to close the window _and_ sets up 
	 * this program to exit when the window is closed. 
	 */

        g_signal_connect (G_OBJECT (window), "delete_event",
                          G_CALLBACK (delete_event), NULL);
	/* This displays the image file. */
	image = gtk_image_new_from_file(dest);
	gtk_container_add(GTK_CONTAINER(event_box), image);
	gtk_widget_show (image);
        gtk_widget_show (window);
        gtk_main ();
	free(info);
	free(dest);
	return 0;
}
Beispiel #15
0
int ploop_copy_send(struct ploop_copy_send_param *arg)
{
	struct delta idelta = { .fd = -1 };
	int tracker_on = 0;
	int fs_frozen = 0;
	int devfd = -1;
	int mntfd = -1;
	int ret = 0;
	char *send_from = NULL;
	char *format = NULL;
	void *iobuf[2] = {};
	int blocksize;
	__u64 cluster;
	__u64 pos;
	__u64 iterpos;
	__u64 trackpos;
	__u64 trackend;
	__u64 xferred;
	int iter;
	struct ploop_track_extent e;
	int i;
	pthread_t send_th = 0;
	struct send_data sd = {
		.mutex = PTHREAD_MUTEX_INITIALIZER,
		.cond = PTHREAD_COND_INITIALIZER,
		.cond_sent = PTHREAD_COND_INITIALIZER,
	};

	if (!arg)
		return SYSEXIT_PARAM;

	sd.fd = arg->ofd;
	sd.is_pipe = is_fd_pipe(arg->ofd);
	if (sd.is_pipe < 0) {
		ploop_err(0, "Invalid output fd %d: must be a file, "
				"a pipe or a socket", arg->ofd);
		return SYSEXIT_PARAM;
	}

	if (arg->feedback_fd >= 0 && is_fd_pipe(arg->feedback_fd) != 1) {
		ploop_err(errno, "Invalid feedback fd %d: must be "
				"a pipe or a socket", arg->feedback_fd);
		return SYSEXIT_PARAM;
	}

	/* If data is to be send to stdout or stderr,
	 * we have to disable logging to appropriate fd.
	 *
	 * As currently there's no way to disable just stderr,
	 * so in this case we have to disable stdout as well.
	 */
	if (arg->ofd == STDOUT_FILENO)
		ploop_set_verbose_level(PLOOP_LOG_NOSTDOUT);
	else if (arg->ofd == STDERR_FILENO)
		ploop_set_verbose_level(PLOOP_LOG_NOCONSOLE);

	devfd = open(arg->device, O_RDONLY);
	if (devfd < 0) {
		ploop_err(errno, "Can't open device %s", arg->device);
		ret = SYSEXIT_DEVICE;
		goto done;
	}

	mntfd = open_mount_point(arg->device);
	if (mntfd < 0) {
		/* Error is printed by open_mount_point() */
		ret = SYSEXIT_OPEN;
		goto done;
	}

	ret = get_image_info(arg->device, &send_from, &format, &blocksize);
	if (ret)
		goto done;
	cluster = S2B(blocksize);

	ret = SYSEXIT_MALLOC;
	for (i = 0; i < 2; i++)
		if (p_memalign(&iobuf[i], 4096, cluster))
			goto done;

	ret = complete_running_operation(NULL, arg->device);
	if (ret)
		goto done;

	ret = ioctl_device(devfd, PLOOP_IOC_TRACK_INIT, &e);
	if (ret)
		goto done;
	tracker_on = 1;

	if (open_delta_simple(&idelta, send_from, O_RDONLY|O_DIRECT, OD_NOFLAGS)) {
		ret = SYSEXIT_OPEN;
		goto done;
	}

	ret = pthread_create(&send_th, NULL, send_thread, &sd);
	if (ret) {
		ploop_err(ret, "Can't create send thread");
		ret = SYSEXIT_SYS;
		goto done;
	}

	ploop_log(-1, "Sending %s", send_from);

	trackend = e.end;
	for (pos = 0; pos < trackend; ) {
		int n;

		trackpos = pos + cluster;
		ret = ioctl_device(devfd, PLOOP_IOC_TRACK_SETPOS, &trackpos);
		if (ret)
			goto done;

		n = do_pread(cluster, pos);
		if (n == 0) /* EOF */
			break;

		async_send(n, pos);
		pos += n;
	}
	/* First copy done */

	iter = 1;
	iterpos = 0;
	xferred = 0;

	for (;;) {
		int err;

		err = ioctl(devfd, PLOOP_IOC_TRACK_READ, &e);
		if (err == 0) {

			//fprintf(stderr, "TRACK %llu-%llu\n", e.start, e.end); fflush(stdout);

			if (e.end > trackend)
				trackend = e.end;

			if (e.start < iterpos)
				iter++;
			iterpos = e.end;
			xferred += e.end - e.start;

			for (pos = e.start; pos < e.end; ) {
				int n;
				int copy = e.end - pos;

				if (copy > cluster)
					copy = cluster;
				if (pos + copy > trackpos) {
					trackpos = pos + copy;
					if (ioctl(devfd, PLOOP_IOC_TRACK_SETPOS, &trackpos)) {
						ploop_err(errno, "PLOOP_IOC_TRACK_SETPOS");
						ret = SYSEXIT_DEVIOC;
						goto done;
					}
				}
				n = do_pread(copy, pos);
				if (n == 0) {
					ploop_err(0, "Unexpected EOF");
					ret = SYSEXIT_READ;
					goto done;
				}
				async_send(n, pos);
				pos += n;
			}
		} else {
			if (errno == EAGAIN) /* no more dirty blocks */
				break;
			ploop_err(errno, "PLOOP_IOC_TRACK_READ");
			ret = SYSEXIT_DEVIOC;
			goto done;
		}

		if (iter > 10 || (iter > 1 && xferred > trackend))
			break;
	}

	/* Live iterative transfers are done. Either we transferred
	 * everything or iterations did not converge. In any case
	 * now we must suspend VE disk activity. Now it is just
	 * call of an external program (something sort of
	 * "killall -9 writetest; sleep 1; umount /mnt2"), actual
	 * implementation must be intergrated to vzctl/vzmigrate
	 * and suspend VE with subsequent fsyncing FS.
	 */

	/* Send the sync command to receiving side. Since older ploop
	 * might be present on the other side, we need to not break the
	 * backward compatibility, so just send the first few (SYNC_MARK)
	 * bytes of delta file contents. New ploop_receive() interprets
	 * this as "sync me" command, while the old one just writes those
	 * bytes which is useless but harmless.
	 */
	if (sd.is_pipe) {
		char buf[LEN_STATUS + 1] = {};

		ret = do_pread(4096, 0);
		if (ret < SYNC_MARK) {
			ploop_err(errno, "Short read");
			ret = SYSEXIT_READ;
			goto done;
		}
		TS("SEND 0 %d (sync)", SYNC_MARK);
		async_send(SYNC_MARK, 0);

		/* Now we should wait for the other side to finish syncing
		 * before freezing the container, to optimize CT frozen time.
		 */
		if (arg->feedback_fd < 0) {
			/* No descriptor to receive a response back is given.
			 * As ugly as it looks, let's just sleep for some time
			 * hoping the other side will finish sync.
			 */
			TS("SLEEP 5");
			sleep(5);
			goto sync_done;
		}

		/* Wait for feedback from the receiving side */

		/* FIXME: use select/poll with a timeout */
		if (read(arg->feedback_fd, buf, LEN_STATUS)
				!= LEN_STATUS) {
			ploop_err(errno, "Can't read feedback");
			ret = SYSEXIT_PROTOCOL;
			goto done;
		}

		if (strncmp(buf, STATUS_OK, LEN_STATUS) == 0) {
			goto sync_done;
		}
		else if (strncmp(buf, STATUS_FAIL, LEN_STATUS) == 0) {
			ploop_err(0, "Remote side reported sync failure");
			ret = SYSEXIT_FSYNC;
			goto done;
		}
		else {
			ploop_err(0, "Got back feedback: %s", buf);
			ret = SYSEXIT_PROTOCOL;
			goto done;
		}
	} else {
		/* Writing to local file */
		fdatasync(arg->ofd);
	}

sync_done:
	/* Freeze the container */
	TS("FLUSH");
	ret = run_cmd(arg->flush_cmd);
	if (ret)
		goto done;

	/* Sync fs */
	TS("SYNCFS");
	if (sys_syncfs(mntfd)) {
		ploop_err(errno, "syncfs() failed");
		ret = SYSEXIT_FSYNC;
		goto done;
	}

	/* Flush journal and freeze fs (this also clears the fs dirty bit) */
	TS("FIFREEZE");
	ret = ioctl_device(mntfd, FIFREEZE, 0);
	if (ret)
		goto done;
	fs_frozen = 1;

	TS("IOC_SYNC");
	ret = ioctl_device(devfd, PLOOP_IOC_SYNC, 0);
	if (ret)
		goto done;

	iter = 1;
	iterpos = 0;

	for (;;) {
		int err;
		struct ploop_track_extent e;

		err = ioctl(devfd, PLOOP_IOC_TRACK_READ, &e);
		if (err == 0) {
			__u64 pos;

			//fprintf(stderr, "TRACK %llu-%llu\n", e.start, e.end); fflush(stdout);

			if (e.end > trackend)
				trackend = e.end;
			if (e.start < iterpos)
				iter++;
			iterpos = e.end;

			for (pos = e.start; pos < e.end; ) {
				int n;
				int copy = e.end - pos;

				if (copy > cluster)
					copy = cluster;
				if (pos + copy > trackpos) {
					trackpos = pos + copy;
					ret = ioctl(devfd, PLOOP_IOC_TRACK_SETPOS, &trackpos);
					if (ret)
						goto done;
				}
				TS("READ %llu %d", pos, copy);
				n = do_pread(copy, pos);
				if (n == 0) {
					ploop_err(0, "Unexpected EOF");
					ret = SYSEXIT_READ;
					goto done;
				}
				TS("SEND %llu %d", pos, n);
				async_send(n, pos);
				pos += n;
			}
		} else {
			if (errno == EAGAIN)
				break;

			ploop_err(errno, "PLOOP_IOC_TRACK_READ");
			ret = SYSEXIT_DEVIOC;
			goto done;
		}

		if (iter > 2) {
			ploop_err(0, "Too many iterations on frozen FS, aborting");
			ret = SYSEXIT_LOOP;
			goto done;
		}
	}

	/* Must clear dirty flag on ploop1 image. */
	if (strcmp(format, "ploop1") == 0) {
		int n;
		struct ploop_pvd_header *vh;

		TS("READ 0 4096");
		n = do_pread(4096, 0);
		if (n < SECTOR_SIZE) {
			ploop_err(errno, "Short read");
			ret = SYSEXIT_READ;
			goto done;
		}

		vh = iobuf[i];
		vh->m_DiskInUse = 0;

		TS("SEND 0 %d (1st sector)", SECTOR_SIZE);
		async_send(SECTOR_SIZE, 0);
	}

	TS("IOCTL TRACK_STOP");
	ret = ioctl(devfd, PLOOP_IOC_TRACK_STOP, 0);
	if (ret)
		goto done;
	tracker_on = 0;

	TS("SEND 0 0 (close)");
	async_send(0, 0);
	pthread_join(send_th, NULL);
	send_th = 0;

done:
	if (send_th)
		pthread_cancel(send_th);
	if (fs_frozen)
		(void)ioctl_device(mntfd, FITHAW, 0);
	if (tracker_on)
		(void)ioctl_device(devfd, PLOOP_IOC_TRACK_ABORT, 0);
	free(iobuf[0]);
	free(iobuf[1]);
	if (devfd >=0)
		close(devfd);
	if (mntfd >=0)
		close(mntfd);
	free(send_from);
	if (idelta.fd >= 0)
		close_delta(&idelta);

	TS("DONE");
	return ret;
}
#undef do_pread
#undef async_send

/* Deprecated, please use ploop_copy_send() instead */
int ploop_send(const char *device, int ofd, const char *flush_cmd,
		int is_pipe)
{
	struct ploop_copy_send_param s = {
		.device		= device,
		.ofd		= ofd,
		.flush_cmd	= flush_cmd,
	};

	return ploop_copy_send(&s);
}
Beispiel #16
0
void
beos_startup(int argc, char **argv)
{
	if (strlen(argv[0]) >= 10 && !strcmp(argv[0] + strlen(argv[0]) - 10, "postmaster"))
	{
		/*
		 * We are in the postmaster, create the protection semaphore for
		 * shared mem remapping
		 */
		beos_shm_sem = create_sem(1, "beos_shm_sem");
	}

	if (argc > 1 && strcmp(argv[1], "-beossupportserver") == 0)
	{
		/* We are in the support server, run it ... */

		port_id		port_in;
		port_id		port_out;

		/* Get back port ids from arglist */
		sscanf(argv[2], "%d", (int *) (&port_in));
		sscanf(argv[3], "%d", (int *) (&port_out));

		/* Main server loop */
		for (;;)
		{
			int32 opcode = 0;
			char		datas[4000];

			/*
			 * Wait for a message from the backend : 1 : load a shared object
			 * 2 : unload a shared object any other : exit support server
			 */
			read_port(port_in, &opcode, datas, 4000);

			switch (opcode)
			{
					image_id	addon;
					image_info	info_im;
					area_info	info_ar;
					void	   *fpt;

					/* Load Add-On */
				case 1:

					/* Load shared object */
					addon = load_add_on(datas);

					/* send back the shared object Id */
					write_port(port_out, addon, NULL, 0);

					/* Get Shared Object infos */
					get_image_info(addon, &info_im);

					/* get text segment info */
					get_area_info(area_for(info_im.text), &info_ar);
					/* Send back area_id of text segment */
					write_port(port_out, info_ar.area, info_ar.name, strlen(info_ar.name) + 1);
					/* Send back real address of text segment */
					write_port(port_out, (int) info_ar.address, info_ar.name, strlen(info_ar.name) + 1);


					/* get data segment info */
					get_area_info(area_for(info_im.data), &info_ar);
					/* Send back area_id of data segment */
					write_port(port_out, info_ar.area, info_ar.name, strlen(info_ar.name) + 1);
					/* Send back real address of data segment */
					write_port(port_out, (int) info_ar.address, info_ar.name, strlen(info_ar.name) + 1);
					break;
					/* UnLoad Add-On */
				case 2:

					/*
					 * Unload shared object and send back the result of the
					 * operation
					 */
					write_port(port_out, unload_add_on(*((int *) (datas))), NULL, 0);
					break;
					/* Cleanup and exit */
				case 3:

					/* read image Id on the input port */
					read_port(port_in, &addon, NULL, 0);

					/* Loading symbol */
					fpt = NULL;


					if (get_image_symbol(addon, datas, B_SYMBOL_TYPE_TEXT, &fpt) == B_OK);
					{
						/*
						 * Sometime the loader return B_OK for an inexistant
						 * function with an invalid address !!! Check that the
						 * return address is in the image range
						 */

						get_image_info(addon, &info_im);
						if ((fpt < info_im.text) ||(fpt >= (info_im.text +info_im.text_size)))
							fpt = NULL;
					}

					/* Send back fptr of data segment */
					write_port(port_out, (int32) (fpt), NULL, 0);
					break;

				default:
					/* Free system resources */
					delete_port(port_in);
					delete_port(port_out);
					/* Exit */
					exit(0);
					break;
			}
		}
		/* Never be there */
		exit(1);
	}
}