Esempio n. 1
0
int write_zero_padding(char* output, int nzeros){
	int fd = open(output, O_WRONLY | O_CREAT);
	if(fd < 0){
		perror("can't create padding file");
		return -1;
	}

	if(ftruncate(fd,0) < 0){
		perror("can't erase padding file");
		return -1;
	}

	if(chmod(output, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0){
		perror("can't set permissions 0644 of TRX file");
	}

	uint8_t zero = 0;

	for(int i = 0; i < nzeros; i++){
		WRITE_HEADER(zero);
	}

	close(fd);
	return 0;
}
Esempio n. 2
0
uint32 TextureDictionary::write(ostream &rw)
{
	HeaderInfo header;
	header.build = version;
	uint32 writtenBytesReturn;

	/*
	 * writtenBytesReturn will always contain the number of bytes
	 * written in a sub-block, it is used like a return value.
	 */

	// Texture Dictionary
	SKIP_HEADER();

	// Struct
	{
		SKIP_HEADER();
		bytesWritten += writeUInt16(texList.size(), rw);
		// TODO, wtf is that?
		bytesWritten += writeUInt16(0, rw);
		WRITE_HEADER(CHUNK_STRUCT);
	}
	bytesWritten += writtenBytesReturn;

	// Texture Natives
	for (uint32 i = 0; i < texList.size(); i++) {
		if (texList[i].platform == PLATFORM_D3D8 ||
		    texList[i].platform == PLATFORM_D3D9) {
			bytesWritten += texList[i].writeD3d(rw);
		} else {
			cerr << "can't write platform " <<
				texList[i].platform << endl;
		}
	}

	// Extension
	{
		SKIP_HEADER();
		WRITE_HEADER(CHUNK_EXTENSION);
	}
	bytesWritten += writtenBytesReturn;

	WRITE_HEADER(CHUNK_TEXDICTIONARY);

	return bytesWritten;
}
Esempio n. 3
0
int write_trx_header(char* output, struct trx_header* header, int is_full)
{
	int fd = open(output, O_WRONLY | O_CREAT);
	if(fd < 0){
		perror("can't create file");
		return -1;
	}

	if(ftruncate(fd,0) < 0){
		perror("can't erase TRX file");
		return -1;
	}

	if(chmod(output, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0){
		perror("can't set permissions 0644 of TRX file");
	}

	if(is_full){
		WRITE_HEADER(header->magic);
		WRITE_HEADER(header->file_length);
		WRITE_HEADER(header->crc32);
	}
	WRITE_HEADER(header->flags);
	WRITE_HEADER(header->version);
	for (int i = 0; i < NUM_OFFSETS; i++){
		WRITE_HEADER(header->offsets[i]);
	}

	close(fd);
	return 0;
}
Esempio n. 4
0
static INLINE IMG_VOID *PVRSRVTimeTraceWriteHeader(IMG_UINT32 *pui32TraceItem, IMG_UINT32 ui32Group,
							IMG_UINT32 ui32Class, IMG_UINT32 ui32Token,
							IMG_UINT32 ui32Size, IMG_UINT32 ui32Type,
							IMG_UINT32 ui32Count)
{
	/* Sanity check arg's */
	CHECKSIZE(ui32Group, PVRSRV_TRACE_GROUP_MASK);
	CHECKSIZE(ui32Class, PVRSRV_TRACE_CLASS_MASK);
	CHECKSIZE(ui32Token, PVRSRV_TRACE_TOKEN_MASK);

	CHECKSIZE(ui32Size, PVRSRV_TRACE_SIZE_MASK);
	CHECKSIZE(ui32Type, PVRSRV_TRACE_TYPE_MASK);
	CHECKSIZE(ui32Count, PVRSRV_TRACE_COUNT_MASK);

	/* Trace header */
	pui32TraceItem[PVRSRV_TRACE_HEADER] = WRITE_HEADER(GROUP, ui32Group);
	pui32TraceItem[PVRSRV_TRACE_HEADER] |= WRITE_HEADER(CLASS, ui32Class);
	pui32TraceItem[PVRSRV_TRACE_HEADER] |= WRITE_HEADER(TOKEN, ui32Token);

	/* Data header */
	pui32TraceItem[PVRSRV_TRACE_DATA_HEADER] = WRITE_HEADER(SIZE, ui32Size);
	pui32TraceItem[PVRSRV_TRACE_DATA_HEADER] |= WRITE_HEADER(TYPE, ui32Type);
	pui32TraceItem[PVRSRV_TRACE_DATA_HEADER] |= WRITE_HEADER(COUNT, ui32Count);

	pui32TraceItem[PVRSRV_TRACE_TIMESTAMP] = OSFuncHighResTimerGetus(g_psTimer);
	pui32TraceItem[PVRSRV_TRACE_HOSTUID] = g_ui32HostUID++;

	return ui32Size?((IMG_VOID *) &pui32TraceItem[PVRSRV_TRACE_DATA_PAYLOAD]):NULL;
}
Esempio n. 5
0
/*---------------------------------------------------------------------------*/
static int
remove_by_page(uint16_t page, int remove_log, int close_fds)
{
  struct file_header hdr;
  int i;
  uint16_t log_page;

  if(page >= COFFEE_PAGE_COUNT) {
    return -1;
  }
  
  READ_HEADER(&hdr, page);
  if(!COFFEE_PAGE_ACTIVE(hdr)) {
    return -1;
  }
  
  dir_cache_del(page);
  hdr.flags |= COFFEE_FLAG_OBSOLETE;
  WRITE_HEADER(&hdr, page);
  if(remove_log && COFFEE_PAGE_MODIFIED(hdr)) {
    log_page = hdr.log_page;
    dir_cache_del(log_page);
    READ_HEADER(&hdr, log_page);
    hdr.flags |= COFFEE_FLAG_OBSOLETE;
    WRITE_HEADER(&hdr, log_page);
  }
  
  /* Close all file descriptors that reference the remove file. */
  if(close_fds) {
    for(i = 0; i < COFFEE_FD_SET_SIZE; i++) {
      if(coffee_fd_set[i].file_page == page) {
	coffee_fd_set[i].flags = COFFEE_FD_FREE;
      }
    }
  }

  return 0;
}
Esempio n. 6
0
uint32 NativeTexture::writeD3d(ostream &rw)
{
	HeaderInfo header;
	header.build = version;
	uint32 writtenBytesReturn;

	if (platform != PLATFORM_D3D8 &&
	    platform != PLATFORM_D3D9)
		return 0;

	// Texture Native
	SKIP_HEADER();

	// Struct
	{
		SKIP_HEADER();
		bytesWritten += writeUInt32(platform, rw);
		bytesWritten += writeUInt32(filterFlags, rw);

		char buffer[32];
		strncpy(buffer, name.c_str(), 32);
		rw.write(buffer, 32);
		strncpy(buffer, maskName.c_str(), 32);
		rw.write(buffer, 32);
		bytesWritten += 2*32;

		bytesWritten += writeUInt32(rasterFormat, rw);
/*
if(rasterFormat == RASTER_8888 && !hasAlpha ||
   rasterFormat == RASTER_888 && hasAlpha)
	cout << "mismatch " << hex << rasterFormat << endl;
*/
		if (platform == PLATFORM_D3D8) {
			bytesWritten += writeUInt32(hasAlpha, rw);
		} else {
			if (dxtCompression) {
				char fourcc[5] = "DXT0";
				fourcc[3] += dxtCompression;
				rw.write(fourcc, 4);
				bytesWritten += 4;
			} else {
				// 0x15 or 0x16
				bytesWritten += writeUInt32(0x16-hasAlpha, rw);
			}
		}
		bytesWritten += writeUInt16(width[0], rw);
		bytesWritten += writeUInt16(height[0], rw);
		bytesWritten += writeUInt8(depth, rw);
		bytesWritten += writeUInt8(mipmapCount, rw);
		bytesWritten += writeUInt8(0x4, rw);
		if (platform == PLATFORM_D3D8)
			bytesWritten += writeUInt8(dxtCompression, rw);
		else
			bytesWritten += writeUInt8(
				(dxtCompression ? 8 : 0) | hasAlpha, rw);

		/* Palette */
		if (rasterFormat & RASTER_PAL8 || rasterFormat & RASTER_PAL4) {
			uint32 paletteSize = 1 << depth;
			rw.write(reinterpret_cast <char *> (palette),
				paletteSize*4*sizeof(uint8));
			bytesWritten += paletteSize*4*sizeof(uint8);
		}

		/* Texels */
		for (uint32 i = 0; i < mipmapCount; i++) {
/*
			uint32 dataSize = width[i]*height[i];
			if (!dxtCompression)
				dataSize *= depth/8;
			else if (dxtCompression == 1)
				dataSize /= 2;
*/
			uint32 dataSize = dataSizes[i];

			bytesWritten += writeUInt32(dataSize, rw);
			rw.write(reinterpret_cast <char *> (&texels[i][0]),
				dataSize*sizeof(uint8));
			bytesWritten += dataSize*sizeof(uint8);
		}

		WRITE_HEADER(CHUNK_STRUCT);
	}
	bytesWritten += writtenBytesReturn;

	// Extension
	{
		SKIP_HEADER();
		WRITE_HEADER(CHUNK_EXTENSION);
	}
	bytesWritten += writtenBytesReturn;

	WRITE_HEADER(CHUNK_TEXTURENATIVE);

	return bytesWritten;
}
Esempio n. 7
0
/* This is the right way according to the Spec 1170 */
void SPC_Child_Terminated(int i)
/*----------------------------------------------------------------------+*/
{
  /* This catches signals for sub-process termination */
  int type, cause, status;
  pid_t wait_pid, pid;
  SPC_Channel_Ptr channel;
  protocol_request     req, *prot;
  buffered_data        data, *pdata;
  int length;
  int indx;
  int saved_errno = errno;

  prot  = (&req);
  pdata = (&data);

  prot->dataptr=pdata;

  wait_pid = -1;
  while(pid = waitpid(wait_pid, &status, WNOHANG)) {
    if((pid == -1 && errno == ECHILD) || pid == 0) {
      /* no more children.  Return */
      errno = saved_errno;
      return;
    }
    
    /* Okay, we got the process ID of a terminated child.  Find the
       channel associated with this PID. */
    channel=SPC_Find_PID(pid);
#ifdef DEBUG
    fprintf(stderr, (XeString)"got SIGCHLD, pid: %d, channel: %p\n", pid, channel);
#endif

    if(!channel) {
      continue;
    }

    _DtSvcProcessLock();
    /*
     * Look for this process in the pid list.  If found, mark it
     * as done.
     */
    if (SPC_pid_list != NULL) {
      for (indx=0; SPC_pid_list[indx] != NULL; indx++)
        if (SPC_pid_list[indx] == pid) {
	   SPC_pid_list[indx] = SPCD_DEAD_PROCESS;
	   break;
	}
    }
    _DtSvcProcessUnlock();

    /* We have the channel.  Mark it as being closed. */

    channel->status     = status;

    /* If we this channel is set up for synchronous termination,
       write the protocol request to record that this guy died.
       Otherwise, call the termination handler directly. */
    
    if(IS_SPCIO_SYNC_TERM(channel->IOMode)) {

      /* This code is basically what SPC_Write_Protocol_Request does.
	 It is replicated here because a call to SPC_W_P_R would have
	 to be re-enterant if we called it here, and SPC_W_P_R is not
	 re-enterant at this time. */
      
      SPC_Reset_Protocol_Ptr(prot, channel, APPLICATION_DIED, 0);
      pdata->len=WRITE_APPLICATION_DIED(pdata, status);
      length=WRITE_HEADER(pdata, channel->cid,
			  prot->request_type,
			  pdata->len,
			  0);
      pdata->data[length]=(XeChar)' ';
      length=pdata->len+REQUEST_HEADER_LENGTH;
      if(write(write_terminator->sid, pdata->data, length)==ERROR)
	SPC_Error(SPC_Internal_Error);
      pdata->offset=REQUEST_HEADER_LENGTH;
      print_protocol_request((XeString) (XeString)"  <-- INTERNAL APPLICATION_DIED", prot);
    }
    else {
      SPC_Change_State(channel, NULL, -1, 0);
      if(channel->Terminate_Handler) {
	XeSPCGetProcessStatus(channel, &type, &cause);
	(* channel->Terminate_Handler)
	  (channel, channel->pid, type, cause, channel->Terminate_Data);
      }
    }
    /* Loop around & get another PID */
  }
  errno = saved_errno;
}
Esempio n. 8
0
/*!
******************************************************************************

 @Function	PVRSRVTimeTraceAllocItem

 @Description

 Allocate a trace item from the buffer of the current process

 @Output ppsTraceItem :	Pointer to allocated trace item

 @Input ui32Size : Size of data packet to be allocated

 @Return none

******************************************************************************/
static IMG_VOID
PVRSRVTimeTraceAllocItem(IMG_UINT32 **pui32Item, IMG_UINT32 ui32Size)
{
	IMG_UINT32 ui32PID = OSGetCurrentProcessIDKM();
	IMG_UINT32 ui32AllocOffset;
	sTimeTraceBuffer *psBuffer = (sTimeTraceBuffer *) HASH_Retrieve(g_psBufferTable, (IMG_UINTPTR_T) ui32PID);

	/* The caller only asks for extra data space */
	ui32Size += PVRSRV_TRACE_ITEM_SIZE;

	/* Always round to 32-bit */
	ui32Size = ((ui32Size - 1) & (~0x3)) + 0x04;

	if (!psBuffer)
	{
		PVRSRV_ERROR eError;

		PVR_DPF((PVR_DBG_MESSAGE, "PVRSRVTimeTraceAllocItem: Creating buffer for PID %u", (IMG_UINT32) ui32PID));
		eError = PVRSRVTimeTraceBufferCreate(ui32PID);
		if (eError != PVRSRV_OK)
		{
			*pui32Item = IMG_NULL;
			PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceAllocItem: Failed to create buffer"));
			return;
		}
		
		psBuffer = (sTimeTraceBuffer *) HASH_Retrieve(g_psBufferTable, (IMG_UINTPTR_T) ui32PID);
		if (psBuffer == IMG_NULL)
		{
			*pui32Item = NULL;
			PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceAllocItem: Failed to retrieve buffer"));
			return;
		}
	}

	/* Can't allocate more then buffer size */
	if (ui32Size >= TIME_TRACE_BUFFER_SIZE)
	{
		*pui32Item = NULL;
		PVR_DPF((PVR_DBG_ERROR, "PVRSRVTimeTraceAllocItem: Error trace item too large (%d)", ui32Size));
		return;
	}

	/* FIXME: Enter critical section? */

	/* Always ensure we have enough space to write a padding message */
	if ((psBuffer->ui32Woff + ui32Size + PVRSRV_TRACE_ITEM_SIZE) > TIME_TRACE_BUFFER_SIZE)
	{
		IMG_UINT32 *ui32WriteEOB = (IMG_UINT32 *) &psBuffer->pui8Data[psBuffer->ui32Woff];
		IMG_UINT32 ui32Remain = TIME_TRACE_BUFFER_SIZE - psBuffer->ui32Woff;

		/* Not enough space at the end of the buffer, back to the start */
		*ui32WriteEOB++ = WRITE_HEADER(GROUP, PVRSRV_TRACE_GROUP_PADDING);
		*ui32WriteEOB++ = 0;		/* Don't need timestamp */
		*ui32WriteEOB++ = 0;		/* Don't need UID */
		*ui32WriteEOB = WRITE_HEADER(SIZE, (ui32Remain - PVRSRV_TRACE_ITEM_SIZE));
		psBuffer->ui32ByteCount += ui32Remain;
		psBuffer->ui32Woff = ui32AllocOffset = 0;
	}
	else
		ui32AllocOffset = psBuffer->ui32Woff;

	psBuffer->ui32Woff = psBuffer->ui32Woff + ui32Size;
	psBuffer->ui32ByteCount += ui32Size;

	/* This allocation will start overwritting past our read pointer, move the read pointer along */
	while (psBuffer->ui32ByteCount > TIME_TRACE_BUFFER_SIZE)
	{
		IMG_UINT32 *psReadItem = (IMG_UINT32 *) &psBuffer->pui8Data[psBuffer->ui32Roff];
		IMG_UINT32 ui32ReadSize;

		ui32ReadSize = PVRSRVTimeTraceItemSize(psReadItem);
		psBuffer->ui32Roff = (psBuffer->ui32Roff + ui32ReadSize) & (TIME_TRACE_BUFFER_SIZE - 1);
		psBuffer->ui32ByteCount -= ui32ReadSize;
	}

	*pui32Item = (IMG_UINT32 *) &psBuffer->pui8Data[ui32AllocOffset];
	/* FIXME: Exit critical section? */
}
Esempio n. 9
0
static void print_header(FILE *fout, const char *field, const char *format)
{
    const char *start = field;
    const char *end = strchr(start, ',');
    int first = 1;

    if (strcmp(format, "XML") == 0) {
        fprintf(fout, "<xml>\n");
        return;
    }

#define WRITE_HEADER(field_name)  \
        if (strncmp(start, field_name, end - start) == 0) { \
            if (strcmp(format, "CSV") == 0) { \
                if (!first) { \
                    fprintf(fout, ","); \
                } \
                fprintf(fout, "\"%s\"", field_name); \
            } else if (strcmp(format, "TAB") == 0) { \
                if (!first) { \
                    fprintf(fout, "\t"); \
                } \
                fprintf(fout, "%s", field_name); \
            } \
            first = 0; \
        }
    for (;;) {
        if (end == NULL) {
            end = start + strlen(start);
        }

        WRITE_HEADER("ip");
        WRITE_HEADER("countryshort");
        WRITE_HEADER("countrylong");
        WRITE_HEADER("region");
        WRITE_HEADER("city");
        WRITE_HEADER("isp");
        WRITE_HEADER("latitude");
        WRITE_HEADER("longitude");
        WRITE_HEADER("domain");
        WRITE_HEADER("zipcode");
        WRITE_HEADER("timezone");
        WRITE_HEADER("netspeed");
        WRITE_HEADER("iddcode");
        WRITE_HEADER("areacode");
        WRITE_HEADER("weatherstationcode");
        WRITE_HEADER("weatherstationname");
        WRITE_HEADER("mcc");
        WRITE_HEADER("mnc");
        WRITE_HEADER("mobilebrand");
        WRITE_HEADER("elevation");
        WRITE_HEADER("usagetype");

        if (*end == ',') {
            start = end + 1;
            end = strchr(start, ',');
        } else {
            break;
        }
    }
    fprintf(fout, "\n");
}