Example #1
0
extern unsigned_32 DWRVMReadDWord( dr_handle hdl )
/************************************************/
{    unsigned_32    dword = *((unsigned_32 _WCUNALIGNED *)(hdl));
    if( DWRCurrNode->byte_swap ) {
        SWAP_32( dword );
    }
    return( dword );
}
Example #2
0
/* Utility routine to look for a note of given type. If found, will
 * return a pointer to its name in memory that caller must free. The
 * file pointer will be positioned at the beginning of note data.
 */
char *find_note( int fd, Elf32_Ehdr *ehdr, Elf32_Phdr *phdr,
                 bool swap, Elf_Note *note )
{
    int             i;
    int             ntype = note->n_type;
    char            *name = NULL;

    /* Loop over program headers */
    for( i = 0; i < ehdr->e_phnum ; ++i, ++phdr ) {
        off_t           read_len;
        off_t           skip;

        if( phdr->p_type != PT_NOTE ) continue;

        /* We found a note segment, loop over the notes */
        read_len = 0;
        while( read_len < phdr->p_filesz ) {
            lseek( fd, phdr->p_offset + read_len, SEEK_SET );
            if( read( fd, note, sizeof( Elf_Note ) ) != sizeof( Elf_Note ) ) {
                break;
            }
            read_len += sizeof( Elf_Note );
            if( swap ) {
                SWAP_32( note->n_namesz );
                SWAP_32( note->n_descsz );
                SWAP_32( note->n_type );
            }
            if( note->n_type == ntype ) {
                /* Found our note, allocate memory for name and read it */
                name = malloc( note->n_namesz );
                if( name ) {
                    read( fd, name, note->n_namesz );
                    /* Skip over padding so that caller can read note data */
                    skip = ((note->n_namesz + ELF_ROUND) & ~ELF_ROUND) - note->n_namesz;
                    lseek( fd, skip, SEEK_CUR );
                }
                break;
            }
            /* Skip over note contents */
            read_len += (note->n_namesz + ELF_ROUND) & ~ELF_ROUND;
            read_len += (note->n_descsz + ELF_ROUND) & ~ELF_ROUND;
        }
    }
    return( name );
}
Example #3
0
void Scm_WriteBinaryS32(ScmObj sval, ScmPort *oport, ScmSymbol *endian)
{
    swap_s32_t v;
    ENSURE_OPORT(oport);
    CHECK_ENDIAN(endian);
    v.val = Scm_GetInteger32Clamp(sval, FALSE, FALSE);
    SWAP_32(endian, v);
    Scm_Putz(v.buf, 4, oport);
}
Example #4
0
void Scm_WriteBinaryF32(ScmObj sval, ScmPort *oport, ScmSymbol *endian)
{
    swap_f32_t v;
    ENSURE_OPORT(oport);
    CHECK_ENDIAN(endian);
    v.val = (float)Scm_GetDouble(sval);
    SWAP_32(endian, v);
    Scm_Putz(v.buf, 4, oport);
}
Example #5
0
//------------------------------------------------------------------------
bool PresetFile::writeInt32 (int32 value)
{
#if BYTEORDER == kBigEndian
	SWAP_32 (value)
#endif	
	int32 numBytesWritten = 0;
	stream->write (&value, sizeof (int32), &numBytesWritten);
	return numBytesWritten == sizeof (int32);
}
Example #6
0
File: ctf.c Project: DataIX/src
static int
write_label(void *arg1, void *arg2)
{
	labelent_t *le = arg1;
	ctf_buf_t *b = arg2;
	ctf_lblent_t ctl;

	ctl.ctl_label = strtab_insert(&b->ctb_strtab, le->le_name);
	ctl.ctl_typeidx = le->le_idx;

	if (target_requires_swap) {
		SWAP_32(ctl.ctl_label);
		SWAP_32(ctl.ctl_typeidx);
	}

	ctf_buf_write(b, &ctl, sizeof (ctl));

	return (1);
}
Example #7
0
//------------------------------------------------------------------------
tresult PLUGIN_API Plug::getState (IBStream* state)
{
	// here we need to save the model

	int32 toSaveBypass = bBypass ? 1 : 0;

#if BYTEORDER == kBigEndian
	SWAP_32 (toSaveBypass)
#endif
	state->write (&toSaveBypass, sizeof (int32));

	int32 toSavePrefetchSupport = mPrefetchableMode;

#if BYTEORDER == kBigEndian
	SWAP_32 (toSavePrefetchSupport)
#endif
	state->write (&toSavePrefetchSupport, sizeof (int32));

	return kResultOk;
}
Example #8
0
//------------------------------------------------------------------------
tresult PLUGIN_API AGain::getState (IBStream* state)
{
	// here we need to save the model

	float toSaveGain = fGain;
	float toSaveGainReduction = fGainReduction;
	int32 toSaveBypass = bBypass ? 1 : 0;

#if BYTEORDER == kBigEndian
	SWAP_32 (toSaveGain)
	SWAP_32 (toSaveGainReduction)
	SWAP_32 (toSaveBypass)
#endif

	state->write (&toSaveGain, sizeof (float));
	state->write (&toSaveGainReduction, sizeof (float));
	state->write (&toSaveBypass, sizeof (int32));

	return kResultOk;
}
Example #9
0
unsigned int htole32(unsigned int x)
{
    unsigned short n = 0x1234;
    unsigned char* ch = (unsigned char*)&n;

    if (*ch == 0x34)
    {
        /* Little-endian */
        return x;
    } else {
        return SWAP_32(x);
    }
}
Example #10
0
File: ctf.c Project: DataIX/src
static void
write_unsized_type_rec(ctf_buf_t *b, ctf_type_t *ctt)
{
	ctf_stype_t *cts = (ctf_stype_t *)ctt;

	if (target_requires_swap) {
		SWAP_32(cts->ctt_name);
		SWAP_16(cts->ctt_info);
		SWAP_16(cts->ctt_size);
	}

	ctf_buf_write(b, cts, sizeof (*cts));
}
Example #11
0
/*
 * byte swap ELF program header
 */
static void swap_phdr( Elf32_Phdr *elf_prog )
/*******************************************/
{
    if( Byte_swap ) {
        /* Byte swap program header */
        SWAP_32( elf_prog->p_type );
        SWAP_32( elf_prog->p_offset );
        SWAP_32( elf_prog->p_vaddr );
        SWAP_32( elf_prog->p_paddr );
        SWAP_32( elf_prog->p_filesz );
        SWAP_32( elf_prog->p_memsz );
        SWAP_32( elf_prog->p_flags );
        SWAP_32( elf_prog->p_align );
    }
}
Example #12
0
/* Read ELF header and check if it's roughly what we're expecting */
int elf_read_hdr( int fd, Elf32_Ehdr *e_hdr )
{
//    Elf32_Phdr  phdr;
//    size_t      i;
    int     result = FALSE;

    lseek( fd, 0, SEEK_SET );
    if( read( fd, e_hdr, sizeof( *e_hdr ) ) >= sizeof( *e_hdr ) &&
        memcmp( e_hdr->e_ident, ELF_SIGNATURE, 4 ) == 0 &&
        e_hdr->e_ident[EI_CLASS] == ELFCLASS32) {
#ifdef __BIG_ENDIAN__
        if( e_hdr->e_ident[EI_DATA] == ELFDATA2LSB )
            core_info.swap_bytes = TRUE;
#else
        if( e_hdr->e_ident[EI_DATA] == ELFDATA2MSB )
            core_info.swap_bytes = TRUE;
#endif
        if( core_info.swap_bytes ) {
            SWAP_16( e_hdr->e_type );
            SWAP_16( e_hdr->e_machine );
            SWAP_32( e_hdr->e_version );
            SWAP_32( e_hdr->e_entry );
            SWAP_32( e_hdr->e_phoff );
            SWAP_32( e_hdr->e_shoff );
            SWAP_32( e_hdr->e_flags );
            SWAP_16( e_hdr->e_ehsize );
            SWAP_16( e_hdr->e_phentsize );
            SWAP_16( e_hdr->e_phnum );
            SWAP_16( e_hdr->e_shentsize );
            SWAP_16( e_hdr->e_shnum );
            SWAP_16( e_hdr->e_shstrndx );
        }
        if( e_hdr->e_phoff != 0 && e_hdr->e_phentsize >= sizeof( Elf32_Phdr ) ) {
            result = TRUE;
        }
    }
    return( result );
}
Example #13
0
int readRAWIVHeader( int *xDim, int *yDim, int *zDim, double *xCenter, double *yCenter, double *zCenter, double *scale, char *fileName )
{
   FILE *fp;
   
   if ( ( fp = fopen( fileName, "rb" ) ) == NULL )
     {
      fprintf( stderr, "\nError: Failed to open file %s!\n\n", fileName );
      return 0;
     }
     
   RAWIVHeader header;

   if ( fread( &header, sizeof( header ), 1, fp ) != 1 )  
     {
      fprintf( stderr, "\nError: Failed to read header from file %s!\n\n", fileName );
      fclose( fp );      
      return 0;      
     }

   if ( !bigEndian( ) )
     {
      for ( int i = 0; i < 3; i++ )
        {
         SWAP_32( &( header.minExt[ i ] ) );
         SWAP_32( &( header.maxExt[ i ] ) );         
         SWAP_32( &( header.dim[ i ] ) );         
         SWAP_32( &( header.origin[ i ] ) );                           
         SWAP_32( &( header.span[ i ] ) );         
        }
        
      SWAP_32( &( header.numVertices ) );  
      SWAP_32( &( header.numCells ) );        
     }
   
   *xCenter = ( header.minExt[ 0 ] + header.maxExt[ 0 ] ) / 2.0;
   *yCenter = ( header.minExt[ 1 ] + header.maxExt[ 1 ] ) / 2.0;
   *zCenter = ( header.minExt[ 2 ] + header.maxExt[ 2 ] ) / 2.0;      
      
   float gridLength1D = header.maxExt[ 0 ] - header.minExt[ 0 ];   
   *scale = 1.0 / gridLength1D;
   
   *xDim = header.dim[ 0 ];
   *yDim = header.dim[ 1 ];
   *zDim = header.dim[ 2 ];      
   
   fclose( fp );
   
   return 1;
}
Example #14
0
static void
label(ud_handle_t udh, uint32_t set_flags)
{
	if (set_flags == 0) {
		if (udh->udfs.flags & VALID_MVDS) {
			print_info(&udh->udfs.mvds, "mvds", udh);
		}
		if (udh->udfs.flags & VALID_RVDS) {
			print_info(&udh->udfs.rvds, "rvds", udh);
		}
		return;
	} else {

		if (udh->udfs.flags & VALID_MVDS) {
			label_vds(&udh->udfs.mvds, set_flags, udh);
		}
		if (udh->udfs.flags & VALID_RVDS) {
			label_vds(&udh->udfs.rvds, set_flags, udh);
		}
		if (((set_flags & (SET_FSNAME | SET_VOLNAME)) ==
			(SET_FSNAME | SET_VOLNAME)) &&
			(udh->udfs.fsd_len != 0)) {
			struct file_set_desc *fsd;

			off = udh->udfs.fsd_loc * udh->udfs.lbsize;
			if (ud_read_dev(udh, off, buf,
				udh->udfs.fsd_len) != 0) {
				return;
			}

			/* LINTED */
			fsd = (struct file_set_desc *)buf;

			set_dstring(fsd->fsd_lvid,
				volname, sizeof (fsd->fsd_lvid));
			set_dstring(fsd->fsd_fsi,
				volname, sizeof (fsd->fsd_fsi));

			ud_make_tag(udh, &fsd->fsd_tag, UD_FILE_SET_DESC,
				SWAP_32(fsd->fsd_tag.tag_loc),
				SWAP_16(fsd->fsd_tag.tag_crc_len));

			(void) ud_write_dev(udh, off, buf, udh->udfs.fsd_len);
		}
	}
}
Example #15
0
//------------------------------------------------------------------------
tresult PLUGIN_API Plug::setState (IBStream* state)
{
	// called when we load a preset, the model has to be reloaded

	int32 savedBypass = 0;
	if (state->read (&savedBypass, sizeof (int32)) != kResultOk)
	{
		return kResultFalse;
	}

#if BYTEORDER == kBigEndian
	SWAP_32 (savedBypass)
#endif
	
	bBypass = savedBypass > 0;

	return kResultOk;
}
Example #16
0
/* Read ELF program headers */
static int elf_read_phdr( int fd, Elf32_Ehdr *e_hdr, Elf32_Phdr **pp_hdr )
{
    Elf32_Phdr      *e_phdr;
    int             i;
    int             result = false;

    *pp_hdr = malloc( sizeof( *e_phdr ) * e_hdr->e_phnum );
    if( *pp_hdr != NULL ) {
        int         error = false;

        e_phdr = *pp_hdr;
        if( lseek( fd, e_hdr->e_phoff, SEEK_SET ) == e_hdr->e_phoff ) {
            for( i = 0; i < e_hdr->e_phnum; i++ ) {
                if( read( fd, e_phdr, sizeof( *e_phdr ) ) < sizeof( *e_phdr ) ) {
                    error = true;
                    break;
                }
                /* Skip any extra bytes that might be present */
                if( lseek( fd, e_hdr->e_phentsize - sizeof( *e_phdr ), SEEK_CUR ) < 0 ) {
                    error = true;
                    break;
                }
                if( Core.swap_bytes ) {
                    SWAP_32( e_phdr->p_type );
                    SWAP_32( e_phdr->p_offset );
                    SWAP_32( e_phdr->p_vaddr );
                    SWAP_32( e_phdr->p_paddr );
                    SWAP_32( e_phdr->p_filesz );
                    SWAP_32( e_phdr->p_memsz );
                    SWAP_32( e_phdr->p_flags );
                    SWAP_32( e_phdr->p_align );
                }
                e_phdr++;
            }
        }
        if( !error ) {
            result = true;
        }
    }
    return( result );
}
//------------------------------------------------------------------------
tresult PLUGIN_API PlugController::setComponentState (IBStream* state)
{
	// we receive the current state of the component (processor part)
	// we read only the gain and bypass value...
	if (state)
	{
		// read the bypass
		int32 bypassState;
		if (state->read (&bypassState, sizeof (bypassState)) == kResultTrue)
		{
#if BYTEORDER == kBigEndian
			SWAP_32 (bypassState)
#endif
			setParamNormalized (kBypassId, bypassState ? 1 : 0);
		}
	}

	return kResultOk;
}
Example #18
0
// write packet to stream file ------------------------------------------------
//
PRIVATE
void SaveLocalPacket( NetPacketExternal* pExtPkt )
{
	ASSERT( pExtPkt != NULL );
	
	if ( pcktfp == NULL ) {
		if ( ( pcktfp = fopen( PACKET_STREAM_FILENAME, "wb" ) ) == NULL ) {
			PANIC( 0 );
		}
	}
	
	// save timecode (little-endian)
	if ( start_timecode == 0 ) {
		start_timecode = SYSs_GetRefFrameCount();
	}
	
	refframe_t current_refframes = SWAP_32( SYSs_GetRefFrameCount() - start_timecode );
	fwrite( &current_refframes, 1, sizeof( int ), pcktfp );
	
	// save packet
	fwrite( pExtPkt, 1, NET_UDP_DATA_LENGTH, pcktfp );
}
Example #19
0
/*
 * Dump the Mach-O header at offset 'start', if any.
 */
bool Dmp_macho_header( unsigned long start )
/******************************************/
{
    struct mach_header  mhead;
    
    Wread( &mhead, sizeof( mhead ) );
    if( (mhead.magic != MH_MAGIC) && (mhead.magic != MH_CIGAM) ) {
        return( 0 );
    }
    if( mhead.magic == MH_CIGAM ) {
        Byte_swap = true;
        SWAP_32( mhead.cputype );
        SWAP_32( mhead.cpusubtype );
        SWAP_32( mhead.filetype );
        SWAP_32( mhead.ncmds );
        SWAP_32( mhead.sizeofcmds );
        SWAP_32( mhead.flags );
    }

    Banner( "Mach-O Header" );
    if( start != 0 ) {
        Wdputs( "File Offset: " );
        Puthex( start, 8 );
        Wdputslc( "\n" );
    }
    Wdputs( "magic                                       = " );
    Puthex( mhead.magic, 8 );
    Wdputs( "\ncputype                                     = " );
    Puthex( mhead.cputype, 8 );
    Wdputs( "H\ncpusubtype                                  = " );
    Puthex( mhead.cpusubtype, 8 );
    Wdputs( "H\nfiletype                                    = " );
    Puthex( mhead.filetype, 8 );
    Wdputslc( "H\nncmds                                       = " );
    Puthex( mhead.ncmds, 8 );
    Wdputslc( "H\nsizeofcmds                                  = " );
    Puthex( mhead.sizeofcmds, 8 );
    Wdputslc( "H\nflags                                       = " );
    Puthex( mhead.flags, 8 );
    Wdputslc( "H\n" );
    dmp_file_type( mhead.filetype );
    Wdputslc( "\n" );
    dmp_cmd_list( start, mhead.ncmds );
    dmp_prog_sec( start );
    return( 1 );
}
Example #20
0
UInt32 mlsConfigGetBlacklistExpiredTime()
{
	return SWAP_32(gConfigData.blacklistExpiredTime);
}
Example #21
0
		.sftpUserName					= "******",
		.sftpPassword					= "******",
#endif
		.PABX							= 0,
		.teminalStatus					= 0,
		.ezMDLimit						= SWAP_16(100),
		.netsMDLimit					= SWAP_16(100),
		.receiptMerchantHeader1			= "Molisys",
		.receiptMerchantHeader2			= "",
		.receiptMerchantHeader3			= "",
		.receiptCopyNumber				= 1,
		.refNumberFlag					= 0,
		.batchClearanceDay				= SWAP_16(1),
		.mdFileWarningAge				= SWAP_16(2),
		.mdFileErrorAge					= SWAP_16(4),
		.blacklistExpiredTime			= SWAP_32(86400),
		.supervisorCardID				= "0000000000000000",
		.integratePOSMode				= 0,
		.HPLCTPDU						= "0000000000",
		.agentID						= 0,
		.transactionUserData			= "0000000",
		.autoLoadCepasAdult				= 0,
		.productionTest					= 'T',
		.issuerRange					= {0x10, 0x00, 0x10, 0x10, 0x04, 0x80, 0x00, 0x80, 0x10, 0x03,0x11,0x11,0x11,0x11,0x02,0x00},
		.cepasPOSEnable					= (CONFIG_DEBIT_ALLOW_MASK_EZLINK | CONFIG_DEBIT_ALLOW_MASK_TRANSIT_LINK | CONFIG_DEBIT_ALLOW_MASK_NETS),
		.autoLoadCepasConcession		= 0,
		.ezCategoryTable				= {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
		.ezCardProfile					= {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
		.featureCode					= 0x01,
		.sodTime						= SWAP_32(5 * 60),
		.autoSettlementTime				= SWAP_32(5 * 60),
Example #22
0
bool MappedRawVFile::readHeader()
{
  Variable::VariableType rawv_type_conv[] = { Variable::UCHAR, Variable::UCHAR, Variable::USHORT, Variable::UINT, Variable::FLOAT, Variable::DOUBLE };
  int rawv_type_sizes[] = { 0, 1, 2, 4, 4, 8 };
  char *rawv_type_strings[] = { NULL, "unsigned char", "unsigned short", "unsigned int/long", "float", "double" };
  unsigned int i,j,a,b,c;
  VariableRecord *var_records;
  RawVHeader header;
  lfmap_ptr_t head_ptr, var_rec_ptr;

  head_ptr = lfmap_ptr(m_LFMappedVolumeFile,0,sizeof(RawVHeader));
  if(head_ptr == NULL)
    {
      fprintf(stderr,"MappedRawVFile::readHeader(): Truncated header, invalid RawV file.\n");
      return false;
    }

  memcpy(&header,head_ptr,sizeof(RawVHeader));
  
  if(!big_endian())
    {
      SWAP_32(&(header.magic));
      for(i=0; i<3; i++) SWAP_32(&(header.dim[i]));
      SWAP_32(&(header.numTimesteps));
      SWAP_32(&(header.numVariables));
      for(i=0; i<4; i++) SWAP_32(&(header.min[i]));
      for(i=0; i<4; i++) SWAP_32(&(header.max[i]));
    }
  
  /* initial error check */
  if(header.magic != 0xBAADBEEF)
    {
      fprintf(stderr,"MappedRawVFile::readHeader(): Error: Magic number not present in file.\n");
      return false;
    }
  
  /* variable initialization */
  m_XDim = header.dim[0];
  m_YDim = header.dim[1];
  m_ZDim = header.dim[2];
  m_XSpan = (header.max[0] - header.min[0])/(header.dim[0] - 1);
  m_YSpan = (header.max[1] - header.min[1])/(header.dim[1] - 1);
  m_ZSpan = (header.max[2] - header.min[2])/(header.dim[2] - 1);
  m_TSpan = (header.max[3] - header.min[3])/header.numTimesteps;
#ifdef DEBUG
  printf("MappedRawVFile::readHeader(): XDim: %lld, YDim: %lld, ZDim: %lld\n",m_XDim,m_YDim,m_ZDim);
  printf("MappedRawVFile::readHeader(): XSpan: %f, YSpan: %f, ZSpan: %f, TSpan: %f\n",m_XSpan,m_YSpan,m_ZSpan,m_TSpan);
#endif
  m_NumVariables = header.numVariables;
  m_NumTimesteps = header.numTimesteps;
#ifdef DEBUG
  printf("MappedRawVFile::readHeader(): Num Variables: %d, Num Timesteps: %d\n",m_NumVariables,m_NumTimesteps);
#endif
  
  /* error checking */
  lfmap_uint64_t dataBytes=0;
  if(sizeof(RawVHeader)+sizeof(VariableRecord)*m_NumVariables>=m_Filesize)
  {
    fprintf(stderr,"MappedRawVFile::readHeader(): Error: Incorrect filesize.\n");
    return false;
  }
  if(m_NumVariables == 0)
  {
    fprintf(stderr,"MappedRawVFile::readHeader(): Error: Number of variables == 0.\n");
    return false;
  }

  /* make a copy of the variable records in the case that the pointer changes due to
     an lfmap remapping */
  var_records = (VariableRecord*)malloc(m_NumVariables*sizeof(VariableRecord));
  var_rec_ptr = lfmap_ptr(m_LFMappedVolumeFile,sizeof(RawVHeader),sizeof(VariableRecord)*m_NumVariables);
  if(var_rec_ptr == NULL)
    {
      fprintf(stderr,"MappedRawVFile::readHeader(): Error: Variable records truncated, not a RawV file.\n");
      free(var_records);
      return false;
    }
  memcpy(var_records,var_rec_ptr,m_NumVariables*sizeof(VariableRecord));

  for(i=0; i<m_NumVariables; i++)
  {
#ifdef DEBUG
    printf("MappedRawVFile::readHeader(): Checking variable record for variable '%d'.\n",i);
#endif
    /* check for null byte in variable name */
    for(j=0; j<64; j++)
      if(var_records[i].varName[j] == '\0') break;
    if(j==64)
      {
	fprintf(stderr,"MappedRawVFile::readHeader(): Error: Non null terminated variable name for variable '%d'\n",i);
	free(var_records);
	return false;
      }
	 
    if(var_records[i].varType > 5)
      {
	fprintf(stderr,"MappedRawVFile::readHeader(): Illegal variable type '%d'.\n",var_records[i].varType);
	free(var_records);
	return false;
      }
    dataBytes += m_XDim*m_YDim*m_ZDim*rawv_type_sizes[var_records[i].varType]*m_NumTimesteps;
#ifdef DEBUG
    printf("MappedRawVFile::readHeader(): Variable record for variable '%d' ('%s' of type '%s') correct.\n",
	   i,var_records[i].varName,rawv_type_strings[var_records[i].varType]);
#endif
  }
  if(sizeof(RawVHeader)+sizeof(VariableRecord)*m_NumVariables+dataBytes != m_Filesize)
    {
      fprintf(stderr,"MappedRawVFile::readHeader(): File size does not match header info.\n");
      free(var_records);
      return false;
    }
  
  m_Variables = new Variable*[m_NumVariables*m_NumTimesteps];
  for(i=0; i<m_NumVariables; i++)
    for(j=0; j<m_NumTimesteps; j++)
      {
	int index = i+m_NumVariables*j;
	lfmap_uint64_t single_length = m_XDim*m_YDim*m_ZDim*rawv_type_sizes[var_records[i].varType];
	lfmap_uint64_t var_start=0;
	for(unsigned int d=0; d<i; d++) /* count the number of bytes to the start of this variable */
	  var_start += m_XDim*m_YDim*m_ZDim*rawv_type_sizes[var_records[d].varType]*m_NumTimesteps;
#ifdef DEBUG
	printf("MappedRawVFile::readHeader(): Reading variable '%s' of type '%s' (timestep %d)\n",var_records[i].varName,rawv_type_strings[var_records[i].varType],j);
#endif
	m_Variables[index] = new Variable(this,(sizeof(RawVHeader)+sizeof(VariableRecord)*m_NumVariables)+var_start+single_length*j,var_records[i].varName,rawv_type_conv[var_records[i].varType],!big_endian());
	/* get the min/max value */
	if(rawv_type_conv[var_records[i].varType] == Variable::UCHAR || !m_CalcMinMax)
	  {
	    m_Variables[index]->m_Min = 0;
	    m_Variables[index]->m_Max = 255;
	  }
	else
	  {
	    lfmap_ptr_t slice = (lfmap_ptr_t)malloc(m_XDim*m_YDim*rawv_type_sizes[var_records[i].varType]);
#ifdef USING_QT
	    QProgressDialog progress(QString("Calculating variable min/max for variable %1, timestep %2").arg(i).arg(j),
				     "Abort",m_ZDim,NULL,"progress",true);
	    progress.show();
#endif

	    m_Variables[index]->m_Min = m_Variables[index]->m_Max = m_Variables[index]->get(0,0,0);
	    for(c=0; c<m_ZDim; c++)
	      {
		double val;

		m_Variables[index]->get(0,0,c,m_XDim,m_YDim,1,slice); /* get a slice at a time because it's much faster */

#define GETMIN(vartype)                                                                                      \
		{                                                                                            \
		  for(a=0; a<m_XDim; a++)                                                                    \
		    for(b=0; b<m_YDim; b++)                                                                  \
		      {                                                                                      \
			val = double(*((vartype *)(slice+(a+m_XDim*b)*sizeof(vartype))));                    \
			if(m_Variables[index]->m_Min > val)                                                  \
			  m_Variables[index]->m_Min = val;                                                   \
			else if(m_Variables[index]->m_Max < val)                                             \
			  m_Variables[index]->m_Max = val;                                                   \
		      }                                                                                      \
		}

		switch(rawv_type_conv[var_records[i].varType])
		  {
		  case Variable::UCHAR:  GETMIN(unsigned char);  break;
		  case Variable::USHORT: GETMIN(unsigned short); break;
		  case Variable::UINT:   GETMIN(unsigned int);   break;
		  case Variable::FLOAT:  GETMIN(float);          break;
		  case Variable::DOUBLE: GETMIN(double);         break;
		  }

#undef GETMIN

#ifdef DEBUG
		fprintf(stderr,"%5.2f %%\r",(((float)c)/((float)((int)(m_ZDim-1))))*100.0);
#endif

#ifdef USING_QT
		progress.setProgress(c);
		qApp->processEvents();
		if(progress.wasCanceled())
		  return false;
#endif
	      }
#ifdef DEBUG
	    printf("\n");
#endif

#ifdef USING_QT
	    progress.setProgress(m_ZDim);
#endif

	    free(slice);
	  }
#ifdef DEBUG
	printf("MappedRawVFile::readHeader(): Variable %d, Timestep %d: min: %f, max: %f\n",i,j,m_Variables[index]->m_Min,m_Variables[index]->m_Max);
#endif
      }

  free(var_records);
  return true;
}
Example #23
0
/*
 * Search for the prn in the array
 * of partitions and translate
 * to the disk block number
 */
daddr_t
ud_xlate_to_daddr(struct udf_vfs *udf_vfsp,
	uint16_t prn, uint32_t blkno, int32_t nblks, uint32_t *count)
{
	int32_t i;
	struct ud_map *map;
	struct ud_part *ud_parts;
	uint32_t lblkno, retblkno = 0, *addr;
	uint32_t begin_req, end_req;
	uint32_t begin_bad, end_bad;

	ud_printf("ud_xlate_to_daddr\n");

	/* Is prn valid */
	if (prn < udf_vfsp->udf_nmaps) {
		map = &(udf_vfsp->udf_maps[prn]);

		if (map->udm_flags == UDM_MAP_VPM) {
			/*
			 * Map is Virtual Parition Map
			 * first check for the appropriate
			 * table and then return the converted
			 * block number
			 */
			for (i = 0; i < map->udm_nent; i++) {
				if (blkno < map->udm_count[i]) {
					addr = map->udm_addr[i];
					lblkno = SWAP_32(addr[blkno]);
					*count = 1;
					break;
				} else {
					blkno -= map->udm_count[i];
				}
			}
		} else if (map->udm_flags == UDM_MAP_SPM) {
			struct stbl *stbl;
			struct stbl_entry *te;
			int32_t entry_count;

			/*
			 * Map type is Sparable Parition Map
			 * if the block is in the map
			 * return the translated block
			 * other wise use the regular
			 * partition stuff
			 */
			begin_req = blkno;
			end_req = begin_req + nblks;

			stbl = (struct stbl *)map->udm_spaddr[0];
			te = (struct stbl_entry *)&stbl->stbl_entry;
			entry_count = SWAP_16(stbl->stbl_len);

			for (i = 0; i < entry_count; i++, te++) {
				begin_bad = SWAP_32(te->sent_ol);
				end_bad = begin_bad + map->udm_plen;

				/*
				 * Either unmapped or reserved
				 * or defective. need not consider
				 */
				if (begin_bad >= (uint32_t)0xFFFFFFF0) {
					continue;
				}
				if ((end_req < begin_bad) ||
				    (begin_req >= end_bad)) {
					continue;
				}

				if (begin_req < begin_bad) {
					ASSERT(end_req >= begin_bad);
					end_req = begin_bad;
				} else {
					retblkno = SWAP_32(te->sent_ml) +
					    begin_req - begin_bad;
					if (end_req < end_bad) {
						*count = end_req - begin_req;
					} else {
						*count = end_bad - begin_req;
					}
					goto end;
				}
			}

			lblkno = blkno;
			*count = end_req - begin_req;
		} else {
			/*
			 * regular partition
			 */
			lblkno = blkno;
			*count = nblks;
		}
		ud_parts = udf_vfsp->udf_parts;
		for (i = 0; i < udf_vfsp->udf_npart; i++) {
			if (map->udm_pn == ud_parts->udp_number) {
				/*
				 * Check if the block is inside
				 * the partition or not
				 */
				if (lblkno >= ud_parts->udp_length) {
					retblkno = 0;
				} else {
					retblkno = ud_parts->udp_start + lblkno;
				}
				goto end;
			}
			ud_parts ++;
		}
	}

end:
	return (retblkno);
}
Example #24
0
int main(int argc, char **argv)
{
  unsigned long long i,j,k;
  unsigned int red_var,green_var,blue_var,alpha_var,timestep;
  color_t colors[257]; /* one extra for error handling */
  size_t num_colors = 0;

  atexit(cleanup);

  if(argc != 2 && argc != 8)
    {
      printf("Every color in the input RawVRGBA file (RawV with 4 variables: red, green, blue, and alpha)\n"
	     "will be mapped to some voxel value range within [0-255] in the output rawiv file (unsigned char volume).\n"
	     "The number of values in each color's range is dependent on the number of different voxel colors in the\n"
	     "RawVRGBA volume. The input voxel's alpha value will determine which value within each color's selected\n"
	     "range the output voxel will take.  If the input voxel's alpha value is 0, then the value in the output volume\n"
	     "will be 0. Due to the fact that the output volume voxels are of unsigned char\n"
	     "type, the maximum number of different colors that can be represented in the output volume are 256.  If\n"
	     "there are more than 256 colors, those colors will cause their corresponding output voxel to take the value\n"
	     "0.\n\n");
      printf("Usage: %s <input rawv with >=4 variables> <red var> <green var> <blue var> <alpha var> <timestep> <output rawiv>\n\n",argv[0]);
      printf("Example: %s heart.rawv 0 1 2 3 0 heart.rawiv\n"
	     "Most RawVRGBA files have the RGBA variables in order, thus the above example should work in most cases.\n"
	     "To produce a rendering similar to the RGBA rendering of the input RawV file, make sure to map each voxel\n"
	     "value range to the color used in the RawV file.",argv[0]);
      return 0;
    }

  vol = new MappedRawVFile(argv[1],true,true);
  if(!vol->isValid())
    {
      printf("Error loading %s!\n",argv[1]);
      return 1;
    }

  printf("File: %s\n",argv[1]);
  printf("Num Vars: %d\n",vol->numVariables());
  printf("Vars: ");
  for(i=0; i<vol->numVariables(); i++) printf("%s ",vol->get(i,0)->name());
  printf("\n");
  printf("Num Timesteps: %d\n",vol->numTimesteps());
  printf("Dimensions: %d x %d x %d\n",vol->XDim(),vol->YDim(),vol->ZDim());
  printf("Span: %lf x %lf x %lf\n",vol->XSpan(),vol->YSpan(),vol->ZSpan());
  printf("TSpan: %lf\n",vol->TSpan());

  if(argc == 2) { return 0; } /* only need to print out volume info */

  red_var = atoi(argv[2]);
  green_var = atoi(argv[3]);
  blue_var = atoi(argv[4]);
  alpha_var = atoi(argv[5]);
  timestep = atoi(argv[6]);

  outvol = fopen(argv[7],"wb+");
  if(outvol == NULL)
    {
      char err_str[512];
      sprintf(err_str,"Error opening %s",argv[7]);
      perror(err_str);
      return 1;
    }

  unsigned long long len = vol->XDim()*vol->YDim()*vol->ZDim()*sizeof(unsigned char)+68;

  /* create the header for the new file */
  RawIVHeader header;
  header.min[0] = 0.0; header.min[1] = 0.0; header.min[2] = 0.0;
  header.max[0] = (vol->XDim()-1)*vol->XSpan();
  header.max[1] = (vol->YDim()-1)*vol->YSpan();
  header.max[2] = (vol->ZDim()-1)*vol->ZSpan();
  header.numVerts = vol->XDim()*vol->YDim()*vol->ZDim();
  header.numCells = (vol->XDim()-1)*(vol->YDim()-1)*(vol->ZDim()-1);
  header.dim[0] = vol->XDim(); header.dim[1] = vol->YDim(); header.dim[2] = vol->ZDim();
  header.origin[0] = 0.0; header.origin[1] = 0.0; header.origin[2] = 0.0;
  header.span[0] = vol->XSpan(); header.span[1] = vol->YSpan(); header.span[2] = vol->ZSpan();
	
  if(!big_endian())
    {
      for(i=0; i<3; i++) SWAP_32(&(header.min[i]));
      for(i=0; i<3; i++) SWAP_32(&(header.max[i]));
      SWAP_32(&(header.numVerts));
      SWAP_32(&(header.numCells));
      for(i=0; i<3; i++) SWAP_32(&(header.dim[i]));
      for(i=0; i<3; i++) SWAP_32(&(header.origin[i]));
      for(i=0; i<3; i++) SWAP_32(&(header.span[i]));
    }

  fwrite(&header,sizeof(RawIVHeader),1,outvol);
	
  /* get a slice at a time because it's quicker */
  unsigned char *slice[5]; /* [0-3] == rgba slices, [4] == output slice */
  for(i=0; i<5; i++) slice[i] = (unsigned char *)malloc(vol->XDim()*vol->YDim()*sizeof(unsigned char));
	
  for(k=0; k<vol->ZDim(); k++)
    {
      /* get the colors for this slice (ignoring alpha for now) */
      vol->get(red_var,timestep)->getMapped(0,0,k,vol->XDim(),vol->YDim(),1,slice[0]);
      vol->get(green_var,timestep)->getMapped(0,0,k,vol->XDim(),vol->YDim(),1,slice[1]);
      vol->get(blue_var,timestep)->getMapped(0,0,k,vol->XDim(),vol->YDim(),1,slice[2]);
	  
      /* check each colored voxel and add all new colors to the list to determine output voxel ranges */
      color_t color;
      for(i=0; i<vol->XDim(); i++)
	for(j=0; j<vol->YDim(); j++)
	  {
	    if(num_colors > 256)
	      {
		printf("Warning: more than 256 colors! Any color not in the list will result in a zero output voxel.\n");
		num_colors = 256;
		goto docalc;
	      }
		
	    color.r = slice[0][i+j*vol->XDim()];
	    color.g = slice[1][i+j*vol->XDim()];
	    color.b = slice[2][i+j*vol->XDim()];
		  
	    if(lsearch(&color,colors,&num_colors,sizeof(color_t),color_cmp) == NULL)
	      {
		printf("Error in lsearch()!\n");
		return 1;
	      }
	  }
		
      fprintf(stderr,"Determining color list... %5.2f %%   \r",(((float)k)/((float)((int)(vol->ZDim()-1))))*100.0);
    }
  printf("\n");
	
 docalc:;

  printf("Number of colors: %d\n",num_colors);
  printf("Colors: ");
  for(i=0; i<num_colors; i++)
    printf("(%d,%d,%d) ",colors[i].r,colors[i].g,colors[i].b);
  printf("\n");
  unsigned int range_size = 256/num_colors; /* range size == the whole space divided by the number of found colors */
  printf("Range size: %d\n",range_size);
	
  /* now write the output volume */
  for(k=0; k<vol->ZDim(); k++)
    {
      /* get the colors for this slice */
      vol->get(red_var,timestep)->getMapped(0,0,k,vol->XDim(),vol->YDim(),1,slice[0]);
      vol->get(green_var,timestep)->getMapped(0,0,k,vol->XDim(),vol->YDim(),1,slice[1]);
      vol->get(blue_var,timestep)->getMapped(0,0,k,vol->XDim(),vol->YDim(),1,slice[2]);
      vol->get(alpha_var,timestep)->getMapped(0,0,k,vol->XDim(),vol->YDim(),1,slice[3]);
	  
      /* lookup each color to determine it's output voxel value */
      /* check each colored voxel and add all new colors to the list to determine output voxel ranges */
      color_t color,*cur;
      unsigned int index, min, max;
      for(i=0; i<vol->XDim(); i++)
	for(j=0; j<vol->YDim(); j++)
	  {
	    color.r = slice[0][i+j*vol->XDim()];
	    color.g = slice[1][i+j*vol->XDim()];
	    color.b = slice[2][i+j*vol->XDim()];
		  
	    cur = (color_t *)lfind(&color,colors,&num_colors,sizeof(color_t),color_cmp);
	    if(cur == NULL)
	      {
		slice[4][i+j*vol->XDim()] = 0;
		continue;
	      }
	    index = ((unsigned int)(cur - colors)); /* determine the color's index */
	    min = index*range_size; /* find the start of this color's range */
	    max = min+range_size-1; /* find the end of this color's range */ /* Note: due to the discreet nature of unsigned char,
										we may not use the entire available 256 voxel values.
									     */
	    /* now use the color's alpha value to determine where on the range the output voxel is */
	    slice[4][i+j*vol->XDim()] = slice[3][i+j*vol->XDim()] == 0 ? 0 : (unsigned char)(min + float(range_size-1)*(float(slice[3][i+j*vol->XDim()])/255.0));
	  }
	
      fwrite(slice[4],sizeof(unsigned char),vol->XDim()*vol->YDim(),outvol);
	
      fprintf(stderr,"Writing output volume... %5.2f %%   \r",(((float)k)/((float)((int)(vol->ZDim()-1))))*100.0);
    }
  printf("\n");
	
  for(i=0; i<5; i++) free(slice[i]);
	
  return 0;
}
Example #25
0
static int cmd_display_mem(int argc, const cmd_args *argv, uint32_t flags) {
    /* save the last address and len so we can continue where we left off */
    static unsigned long address;
    static size_t len;

    if (argc < 3 && len == 0) {
        printf("not enough arguments\n");
        printf("%s [-l] [-b] [address] [length]\n", argv[0].str);
        return -1;
    }

    int size;
    if (strcmp(argv[0].str, "dw") == 0) {
        size = 4;
    } else if (strcmp(argv[0].str, "dh") == 0) {
        size = 2;
    } else {
        size = 1;
    }

    uint byte_order = BYTE_ORDER;
    int argindex = 1;
    bool read_address = false;
    while (argc > argindex) {
        if (!strcmp(argv[argindex].str, "-l")) {
            byte_order = LITTLE_ENDIAN;
        } else if (!strcmp(argv[argindex].str, "-b")) {
            byte_order = BIG_ENDIAN;
        } else if (!read_address) {
            address = argv[argindex].u;
            read_address = true;
        } else {
            len = argv[argindex].u;
        }

        argindex++;
    }

    unsigned long stop = address + len;
    int count = 0;

    if ((address & (size - 1)) != 0) {
        printf("unaligned address, cannot display\n");
        return -1;
    }

    /* preflight the start address to see if it's mapped */
    if (vaddr_to_paddr((void *)address) == 0) {
        printf("ERROR: address 0x%lx is unmapped\n", address);
        return -1;
    }

    for ( ; address < stop; address += size) {
        if (count == 0)
            printf("0x%08lx: ", address);
        switch (size) {
            case 4: {
                uint32_t val = (byte_order != BYTE_ORDER) ?
                               SWAP_32(*(uint32_t *)address) :
                               *(uint32_t *)address;
                printf("%08x ", val);
                break;
            }
            case 2: {
                uint16_t val = (byte_order != BYTE_ORDER) ?
                               SWAP_16(*(uint16_t *)address) :
                               *(uint16_t *)address;
                printf("%04hx ", val);
                break;
            }
            case 1:
                printf("%02hhx ", *(uint8_t *)address);
                break;
        }
        count += size;
        if (count == 16) {
            printf("\n");
            count = 0;
        }
    }

    if (count != 0)
        printf("\n");

    return 0;
}
Example #26
0
File: ctf.c Project: DataIX/src
caddr_t
ctf_gen(iiburst_t *iiburst, size_t *resszp, int do_compress)
{
	ctf_buf_t *buf = ctf_buf_new();
	ctf_header_t h;
	caddr_t outbuf;

	int i;

	target_requires_swap = do_compress & CTF_SWAP_BYTES;
	do_compress &= ~CTF_SWAP_BYTES;

	/*
	 * Prepare the header, and create the CTF output buffers.  The data
	 * object section and function section are both lists of 2-byte
	 * integers; we pad these out to the next 4-byte boundary if needed.
	 */
	h.cth_magic = CTF_MAGIC;
	h.cth_version = CTF_VERSION;
	h.cth_flags = do_compress ? CTF_F_COMPRESS : 0;
	h.cth_parlabel = strtab_insert(&buf->ctb_strtab,
	    iiburst->iib_td->td_parlabel);
	h.cth_parname = strtab_insert(&buf->ctb_strtab,
	    iiburst->iib_td->td_parname);

	h.cth_lbloff = 0;
	(void) list_iter(iiburst->iib_td->td_labels, write_label,
	    buf);

	pad_buffer(buf, 2);
	h.cth_objtoff = ctf_buf_cur(buf);
	for (i = 0; i < iiburst->iib_nobjts; i++)
		write_objects(iiburst->iib_objts[i], buf);

	pad_buffer(buf, 2);
	h.cth_funcoff = ctf_buf_cur(buf);
	for (i = 0; i < iiburst->iib_nfuncs; i++)
		write_functions(iiburst->iib_funcs[i], buf);

	pad_buffer(buf, 4);
	h.cth_typeoff = ctf_buf_cur(buf);
	(void) list_iter(iiburst->iib_types, write_type, buf);

	debug(2, "CTF wrote %d types\n", list_count(iiburst->iib_types));

	h.cth_stroff = ctf_buf_cur(buf);
	h.cth_strlen = strtab_size(&buf->ctb_strtab);

	if (target_requires_swap) {
		SWAP_16(h.cth_preamble.ctp_magic);
		SWAP_32(h.cth_parlabel);
		SWAP_32(h.cth_parname);
		SWAP_32(h.cth_lbloff);
		SWAP_32(h.cth_objtoff);
		SWAP_32(h.cth_funcoff);
		SWAP_32(h.cth_typeoff);
		SWAP_32(h.cth_stroff);
		SWAP_32(h.cth_strlen);
	}

	/*
	 * We only do compression for ctfmerge, as ctfconvert is only
	 * supposed to be used on intermediary build objects. This is
	 * significantly faster.
	 */
	if (do_compress)
		outbuf = write_compressed_buffer(&h, buf, resszp);
	else
		outbuf = write_buffer(&h, buf, resszp);

	ctf_buf_free(buf);
	return (outbuf);
}
Example #27
0
File: ctf.c Project: DataIX/src
static int
write_type(void *arg1, void *arg2)
{
	tdesc_t *tp = arg1;
	ctf_buf_t *b = arg2;
	elist_t *ep;
	mlist_t *mp;
	intr_t *ip;

	size_t offset;
	uint_t encoding;
	uint_t data;
	int isroot = tp->t_flags & TDESC_F_ISROOT;
	int i;

	ctf_type_t ctt;
	ctf_array_t cta;
	ctf_member_t ctm;
	ctf_lmember_t ctlm;
	ctf_enum_t cte;
	ushort_t id;

	ctlm.ctlm_pad = 0;

	/*
	 * There shouldn't be any holes in the type list (where a hole is
	 * defined as two consecutive tdescs without consecutive ids), but
	 * check for them just in case.  If we do find holes, we need to make
	 * fake entries to fill the holes, or we won't be able to reconstruct
	 * the tree from the written data.
	 */
	if (++b->nptent < CTF_TYPE_TO_INDEX(tp->t_id)) {
		debug(2, "genctf: type hole from %d < x < %d\n",
		    b->nptent - 1, CTF_TYPE_TO_INDEX(tp->t_id));

		ctt.ctt_name = CTF_TYPE_NAME(CTF_STRTAB_0, 0);
		ctt.ctt_info = CTF_TYPE_INFO(0, 0, 0);
		while (b->nptent < CTF_TYPE_TO_INDEX(tp->t_id)) {
			write_sized_type_rec(b, &ctt, 0);
			b->nptent++;
		}
	}

	offset = strtab_insert(&b->ctb_strtab, tp->t_name);
	ctt.ctt_name = CTF_TYPE_NAME(CTF_STRTAB_0, offset);

	switch (tp->t_type) {
	case INTRINSIC:
		ip = tp->t_intr;
		if (ip->intr_type == INTR_INT)
			ctt.ctt_info = CTF_TYPE_INFO(CTF_K_INTEGER,
			    isroot, 1);
		else
			ctt.ctt_info = CTF_TYPE_INFO(CTF_K_FLOAT, isroot, 1);
		write_sized_type_rec(b, &ctt, tp->t_size);

		encoding = 0;

		if (ip->intr_type == INTR_INT) {
			if (ip->intr_signed)
				encoding |= CTF_INT_SIGNED;
			if (ip->intr_iformat == 'c')
				encoding |= CTF_INT_CHAR;
			else if (ip->intr_iformat == 'b')
				encoding |= CTF_INT_BOOL;
			else if (ip->intr_iformat == 'v')
				encoding |= CTF_INT_VARARGS;
		} else
			encoding = ip->intr_fformat;

		data = CTF_INT_DATA(encoding, ip->intr_offset, ip->intr_nbits);
		if (target_requires_swap) {
			SWAP_32(data);
		}
		ctf_buf_write(b, &data, sizeof (data));
		break;

	case POINTER:
		ctt.ctt_info = CTF_TYPE_INFO(CTF_K_POINTER, isroot, 0);
		ctt.ctt_type = tp->t_tdesc->t_id;
		write_unsized_type_rec(b, &ctt);
		break;

	case ARRAY:
		ctt.ctt_info = CTF_TYPE_INFO(CTF_K_ARRAY, isroot, 1);
		write_sized_type_rec(b, &ctt, tp->t_size);

		cta.cta_contents = tp->t_ardef->ad_contents->t_id;
		cta.cta_index = tp->t_ardef->ad_idxtype->t_id;
		cta.cta_nelems = tp->t_ardef->ad_nelems;
		if (target_requires_swap) {
			SWAP_16(cta.cta_contents);
			SWAP_16(cta.cta_index);
			SWAP_32(cta.cta_nelems);
		}
		ctf_buf_write(b, &cta, sizeof (cta));
		break;

	case STRUCT:
	case UNION:
		for (i = 0, mp = tp->t_members; mp != NULL; mp = mp->ml_next)
			i++; /* count up struct or union members */

		if (i > CTF_MAX_VLEN) {
			terminate("sou %s has too many members: %d > %d\n",
			    tdesc_name(tp), i, CTF_MAX_VLEN);
		}

		if (tp->t_type == STRUCT)
			ctt.ctt_info = CTF_TYPE_INFO(CTF_K_STRUCT, isroot, i);
		else
			ctt.ctt_info = CTF_TYPE_INFO(CTF_K_UNION, isroot, i);

		write_sized_type_rec(b, &ctt, tp->t_size);

		if (tp->t_size < CTF_LSTRUCT_THRESH) {
			for (mp = tp->t_members; mp != NULL; mp = mp->ml_next) {
				offset = strtab_insert(&b->ctb_strtab,
				    mp->ml_name);

				ctm.ctm_name = CTF_TYPE_NAME(CTF_STRTAB_0,
				    offset);
				ctm.ctm_type = mp->ml_type->t_id;
				ctm.ctm_offset = mp->ml_offset;
				if (target_requires_swap) {
					SWAP_32(ctm.ctm_name);
					SWAP_16(ctm.ctm_type);
					SWAP_16(ctm.ctm_offset);
				}
				ctf_buf_write(b, &ctm, sizeof (ctm));
			}
		} else {
			for (mp = tp->t_members; mp != NULL; mp = mp->ml_next) {
				offset = strtab_insert(&b->ctb_strtab,
				    mp->ml_name);

				ctlm.ctlm_name = CTF_TYPE_NAME(CTF_STRTAB_0,
				    offset);
				ctlm.ctlm_type = mp->ml_type->t_id;
				ctlm.ctlm_offsethi =
				    CTF_OFFSET_TO_LMEMHI(mp->ml_offset);
				ctlm.ctlm_offsetlo =
				    CTF_OFFSET_TO_LMEMLO(mp->ml_offset);

				if (target_requires_swap) {
					SWAP_32(ctlm.ctlm_name);
					SWAP_16(ctlm.ctlm_type);
					SWAP_32(ctlm.ctlm_offsethi);
					SWAP_32(ctlm.ctlm_offsetlo);
				}

				ctf_buf_write(b, &ctlm, sizeof (ctlm));
			}
		}
		break;

	case ENUM:
		for (i = 0, ep = tp->t_emem; ep != NULL; ep = ep->el_next)
			i++; /* count up enum members */

		if (i > CTF_MAX_VLEN) {
			warning("enum %s has too many values: %d > %d\n",
			    tdesc_name(tp), i, CTF_MAX_VLEN);
			i = CTF_MAX_VLEN;
		}

		ctt.ctt_info = CTF_TYPE_INFO(CTF_K_ENUM, isroot, i);
		write_sized_type_rec(b, &ctt, tp->t_size);

		for (ep = tp->t_emem; ep != NULL && i > 0; ep = ep->el_next) {
			offset = strtab_insert(&b->ctb_strtab, ep->el_name);
			cte.cte_name = CTF_TYPE_NAME(CTF_STRTAB_0, offset);
			cte.cte_value = ep->el_number;

			if (target_requires_swap) {
				SWAP_32(cte.cte_name);
				SWAP_32(cte.cte_value);
			}

			ctf_buf_write(b, &cte, sizeof (cte));
			i--;
		}
		break;

	case FORWARD:
		ctt.ctt_info = CTF_TYPE_INFO(CTF_K_FORWARD, isroot, 0);
		ctt.ctt_type = 0;
		write_unsized_type_rec(b, &ctt);
		break;

	case TYPEDEF:
		ctt.ctt_info = CTF_TYPE_INFO(CTF_K_TYPEDEF, isroot, 0);
		ctt.ctt_type = tp->t_tdesc->t_id;
		write_unsized_type_rec(b, &ctt);
		break;

	case VOLATILE:
		ctt.ctt_info = CTF_TYPE_INFO(CTF_K_VOLATILE, isroot, 0);
		ctt.ctt_type = tp->t_tdesc->t_id;
		write_unsized_type_rec(b, &ctt);
		break;

	case CONST:
		ctt.ctt_info = CTF_TYPE_INFO(CTF_K_CONST, isroot, 0);
		ctt.ctt_type = tp->t_tdesc->t_id;
		write_unsized_type_rec(b, &ctt);
		break;

	case FUNCTION:
		i = tp->t_fndef->fn_nargs + tp->t_fndef->fn_vargs;

		if (i > CTF_MAX_VLEN) {
			terminate("function %s has too many args: %d > %d\n",
			    tdesc_name(tp), i, CTF_MAX_VLEN);
		}

		ctt.ctt_info = CTF_TYPE_INFO(CTF_K_FUNCTION, isroot, i);
		ctt.ctt_type = tp->t_fndef->fn_ret->t_id;
		write_unsized_type_rec(b, &ctt);

		for (i = 0; i < (int) tp->t_fndef->fn_nargs; i++) {
			id = tp->t_fndef->fn_args[i]->t_id;

			if (target_requires_swap) {
				SWAP_16(id);
			}

			ctf_buf_write(b, &id, sizeof (id));
		}

		if (tp->t_fndef->fn_vargs) {
			id = 0;
			ctf_buf_write(b, &id, sizeof (id));
			i++;
		}

		if (i & 1) {
			id = 0;
			ctf_buf_write(b, &id, sizeof (id));
		}
		break;

	case RESTRICT:
		ctt.ctt_info = CTF_TYPE_INFO(CTF_K_RESTRICT, isroot, 0);
		ctt.ctt_type = tp->t_tdesc->t_id;
		write_unsized_type_rec(b, &ctt);
		break;

	default:
		warning("Can't write unknown type %d\n", tp->t_type);
	}

	debug(3, "Wrote type %d %s\n", tp->t_id, tdesc_name(tp));

	return (1);
}
Example #28
0
int32_t
ud_fill_udfs_info(ud_handle_t h)
{
	struct	anch_vol_desc_ptr	*avdp = NULL;
	uint32_t			offset = 0;

	if (ioctl(h->fd, CDROMREADOFFSET, &offset) == -1) {
		offset = 0;
	}

	h->udfs.flags = INVALID_UDFS;

	h->udfs.ecma_version = ud_get_ecma_ver(h, offset);
	if (h->udfs.ecma_version == UD_ECMA_UNKN) {
		return (1);
	}

	h->udfs.lbsize = ud_get_fs_bsize(h, offset, &h->udfs.avdp_loc);
	if (h->udfs.lbsize == 0) {
		return (2);
	}

	h->udfs.avdp_len = lb_roundup(512, h->udfs.lbsize);


	if ((avdp = (struct anch_vol_desc_ptr *)
			malloc(h->udfs.lbsize)) == NULL) {
		return (3);
	}
	if (ud_read_dev(h, h->udfs.avdp_loc * h->udfs.lbsize,
			(uint8_t *)avdp, h->udfs.lbsize) != 0) {
		free(avdp);
		return (4);
	}
	if (ud_verify_tag(h, &avdp->avd_tag, UD_ANCH_VOL_DESC,
			h->udfs.avdp_loc, 1, 0) != 0) {
		free(avdp);
		return (5);
	}

	h->udfs.mvds_loc = SWAP_32(avdp->avd_main_vdse.ext_loc);
	h->udfs.mvds_len = SWAP_32(avdp->avd_main_vdse.ext_len);

	h->udfs.rvds_loc = SWAP_32(avdp->avd_res_vdse.ext_loc);
	h->udfs.rvds_len = SWAP_32(avdp->avd_res_vdse.ext_len);

	free(avdp);

	/*
	 * get information from mvds and rvds
	 */
	if (ud_parse_fill_vds(h, &h->udfs.mvds,
			h->udfs.mvds_loc, h->udfs.mvds_len) == 0) {
		h->udfs.flags |= VALID_MVDS;
	}
	if (ud_parse_fill_vds(h, &h->udfs.rvds,
			h->udfs.rvds_loc, h->udfs.rvds_len) == 0) {
		h->udfs.flags |= VALID_RVDS;
	}

	if ((h->udfs.flags & (VALID_MVDS | VALID_RVDS)) == 0) {
		return (6);
	}

	/*
	 * If we are here we have
	 * a valid Volume Descriptor Seqence
	 * Read and understand lvd
	 */
	if (h->udfs.flags & VALID_MVDS) {
		if (ud_read_and_translate_lvd(h, h->udfs.mvds.lvd_loc,
				h->udfs.mvds.lvd_len) != 0) {
			return (7);
		}
	} else {
		if (ud_read_and_translate_lvd(h, h->udfs.rvds.lvd_loc,
				h->udfs.rvds.lvd_len) != 0) {
			return (8);
		}
	}

	h->udfs.flags |= VALID_UDFS;

	return (0);
}
Example #29
0
/* ARGSUSED */
static void
label_vds(struct vds *v, uint32_t set_flags, ud_handle_t udh)
{

	if (((set_flags & (SET_FSNAME | SET_VOLNAME)) ==
		(SET_FSNAME | SET_VOLNAME)) &&
		(v->pvd_len)) {

		off = v->pvd_loc * udh->udfs.lbsize;
		if (ud_read_dev(udh, off, buf,
			sizeof (struct pri_vol_desc)) == 0) {

			struct pri_vol_desc *pvd;

			/* LINTED */
			pvd = (struct pri_vol_desc *)buf;
			bzero((int8_t *)&pvd->pvd_vsi[9], 119);
			(void) strncpy((int8_t *)&pvd->pvd_vsi[9],
					&fsname[1], fsname_len - 1);

			set_dstring(pvd->pvd_vol_id,
				volname, sizeof (pvd->pvd_vol_id));

			ud_make_tag(udh, &pvd->pvd_tag,
				SWAP_16(pvd->pvd_tag.tag_id),
				SWAP_32(pvd->pvd_tag.tag_loc),
				SWAP_16(pvd->pvd_tag.tag_crc_len));

			(void) ud_write_dev(udh, off, buf,
				sizeof (struct pri_vol_desc));
		}
	}

	if (set_flags && v->iud_len) {

		off = v->iud_loc * udh->udfs.lbsize;
		if (ud_read_dev(udh, off, buf,
			sizeof (struct iuvd_desc)) == 0) {

			struct iuvd_desc *iuvd;

			/* LINTED */
			iuvd = (struct iuvd_desc *)buf;

			if ((set_flags & SET_VOLNAME) == SET_VOLNAME) {
				set_dstring(iuvd->iuvd_lvi,
					volname, sizeof (iuvd->iuvd_lvi));
			}
			if ((set_flags & SET_LVINFO1) == SET_LVINFO1) {
				set_dstring(iuvd->iuvd_ifo1,
					lvinfo1_buf, sizeof (iuvd->iuvd_ifo1));
			}
			if ((set_flags & SET_LVINFO2) == SET_LVINFO2) {
				set_dstring(iuvd->iuvd_ifo2,
					lvinfo2_buf, sizeof (iuvd->iuvd_ifo2));
			}
			if ((set_flags & SET_LVINFO3) == SET_LVINFO3) {
				set_dstring(iuvd->iuvd_ifo3,
					lvinfo3_buf, sizeof (iuvd->iuvd_ifo3));
			}

			ud_make_tag(udh, &iuvd->iuvd_tag,
				SWAP_16(iuvd->iuvd_tag.tag_id),
				SWAP_32(iuvd->iuvd_tag.tag_loc),
				SWAP_16(iuvd->iuvd_tag.tag_crc_len));

			(void) ud_write_dev(udh, off, buf,
				sizeof (struct iuvd_desc));
		}
	}

	if (((set_flags & (SET_FSNAME | SET_VOLNAME)) ==
		(SET_FSNAME | SET_VOLNAME)) &&
		(v->lvd_len)) {

		off = v->lvd_loc * udh->udfs.lbsize;
		if (ud_read_dev(udh, off, buf,
			sizeof (struct log_vol_desc)) == 0) {

			struct log_vol_desc *lvd;

			/* LINTED */
			lvd = (struct log_vol_desc *)buf;
			set_dstring(lvd->lvd_lvid,
				volname, sizeof (lvd->lvd_lvid));

			ud_make_tag(udh, &lvd->lvd_tag,
				SWAP_16(lvd->lvd_tag.tag_id),
				SWAP_32(lvd->lvd_tag.tag_loc),
				SWAP_16(lvd->lvd_tag.tag_crc_len));

			(void) ud_write_dev(udh, off, buf,
				sizeof (struct log_vol_desc));
		}
	}
}
Example #30
0
int main( int argc, char **argv )
{
    char                quiet;
    FILE                *fp;
    size_t              wanted;
    unsigned            i, j, k, l;
    int                 length = 0;
    char *              record_type;
    samp_block *        data;
    auto samp_header    head;
    cgraph_sample *     sptr;
    auto struct stat    file_stat;
    time_t              stamp;
    count_info          *count;
    bool                byte_swap = false;


    puts( banner1w( "Sample File Dump Utility", _WSAMP_VERSION_ ) );
    puts( banner2 );
    puts( banner2a( 1989 ) );
    puts( banner3 );
    puts( banner3a );

    if( argc != 2 && argc != 3 ) {
        puts( "usage: smpdump <sample_file> [-q]" );
        exit( 1 );
    }
    data = malloc( 63L * 1024 + 512 );
    quiet = 0;
    if( argc == 3 && strcmp( argv[2], "-q" ) == 0 ) {
        quiet = 1;
    }
    _splitpath( argv[1], drv, dir, name, ext );
    if( ext[0] == '\0' ) {
        strcpy( ext, ".smp" );
    }
    _makepath( path, drv, dir, name, ext );
    fp = fopen( path, "rb" );
    if( fp == NULL )
        return( 1 );
    if( fseek( fp, -(long)SIZE_HEADER, SEEK_END ) ) {
        fclose( fp );
        return( 1 );
    }
    fread( &head, 1, SIZE_HEADER, fp );
    if( head.signature != SAMP_SIGNATURE ) {
        SWAP_16( head.signature );
        if( head.signature == SAMP_SIGNATURE ) {
            byte_swap = true;
            SWAP_32( head.sample_start );
        } else {
            fclose( fp );
            return( 1 );
        }
    }
    printf( "Sample file version: %u.%u\n", head.major_ver, head.minor_ver );
    fseek( fp, head.sample_start, SEEK_SET );
    for( ;; ) {
        /* read the prefix of record */
        wanted = sizeof( data->pref );
        if( fread( &data->pref, 1, wanted, fp ) != wanted )
            break;
        COND_SWAP_32( data->pref.tick );
        COND_SWAP_16( data->pref.length );
        COND_SWAP_16( data->pref.kind );

        /* read the rest of the record */
        wanted = data->pref.length - sizeof( data->pref );
        if( fread( &data->d, 1, wanted, fp ) != wanted )
            break;

        /* dump common record data */
        record_type = "** UNKNOWN **";
        if( data->pref.kind < NUM_BLOCK_KINDS ) {
            record_type = Types[data->pref.kind];
        }
        printf( "%s  tick %lu length %u\n", record_type,
                data->pref.tick, data->pref.length );

        /* dump specific record data */
        switch( data->pref.kind ) {
        case SAMP_INFO:
            COND_SWAP_32( data->d.info.timer_rate );
            printf( "  timer rate %ld ms\n", data->d.info.timer_rate / 1000 );
            l = data->pref.length;
            if( head.major_ver == 2 && head.minor_ver <= 1 ) {
                count = &data->d.old_info.count[0];
                l -= offsetof( samp_block, d.old_info.count );
            } else {
                COND_SWAP_16( data->d.info.config.mad );
                printf( "  cpu=%d, fpu=%d, os_maj=%d, os_min=%d, os=%d, mad=%d\n",
                        data->d.info.config.cpu, data->d.info.config.fpu,
                        data->d.info.config.osmajor, data->d.info.config.osminor,
                        data->d.info.config.os, data->d.info.config.mad );
                count = &data->d.info.count[0];
                l -= offsetof( samp_block, d.info.count );
            }
            l /= sizeof( count_info );
            for( i = 0; i < l; ++i ) {
                COND_SWAP_32( count[i].number );
                COND_SWAP_32( count[i].size );
                printf( "    %s number %lu size %lu\n", Types[i],
                        count[i].number, count[i].size );
            }
            break;
        case SAMP_SAMPLES:
            j = data->pref.length;
            j -= offsetof( samp_block, d.sample.sample );
            j /= sizeof( samp_address );
            COND_SWAP_16( data->d.sample.thread_id );
            printf( "  thread id %u  #samples %u\n",
                    data->d.sample.thread_id, j );
            if( quiet ) {
                printf( "    ....\n    ....\n    ....\n" );
            } else {
                for( i = 0; i < j; ++i ) {
                    COND_SWAP_16( data->d.sample.sample[i].segment );
                    COND_SWAP_32( data->d.sample.sample[i].offset );
                    printf( "  - %.4x:%.8lx\n",
                            data->d.sample.sample[i].segment,
                            data->d.sample.sample[i].offset );
                }
            }
            break;
        case SAMP_MARK:
            COND_SWAP_16( data->d.sample.thread_id );
            COND_SWAP_16( data->d.mark.addr.segment );
            COND_SWAP_32( data->d.mark.addr.offset );
            printf( "  thread %u - %.4x:%.8lx  \"%s\"\n",
                    data->d.mark.thread_id, data->d.mark.addr.segment,
                    data->d.mark.addr.offset, data->d.mark.mark_string );
            break;
        case SAMP_OVL_LOAD:
            if( data->d.ovl.req_section & OVL_RETURN ) {
                printf( "  section %u (RETURN)\n",
                        data->d.ovl.req_section & (~ OVL_RETURN) );
            } else {
                printf( "  section %u\n", data->d.ovl.req_section );
            }
            printf( "    - requesting address = %.4x:%.8lx\n",
                    data->d.ovl.addr.segment, data->d.ovl.addr.offset );
            j = data->pref.length;
            j -= offsetof( samp_block, d.ovl.ovl_map );
            j /= sizeof( uint_8 );
            printf( "    - loaded overlay sections = " );
//            printf( "%.2x", data->d.ovl.ovl_map[0] );
            for( i = 0; i < j; ++i ) {
                printf( "%.2x", data->d.ovl.ovl_map[i] );
            }
            printf( "\n" );
            break;
        case SAMP_CODE_LOAD:
        case SAMP_MAIN_LOAD:
            stamp = data->d.code.time_stamp;
            COND_SWAP_32( stamp );
            COND_SWAP_16( data->d.code.ovl_tab.segment );
            COND_SWAP_32( data->d.code.ovl_tab.offset );
            printf( "  name = \"%s\"\n", data->d.code.name );
            printf( "  overlay table = %.4x:%.8lx\n",
                    data->d.code.ovl_tab.segment, data->d.code.ovl_tab.offset );
            printf( "  time stamp %lx -> %s", stamp,
                    ctime( &stamp ) );
            if( stat( data->d.code.name, &file_stat ) == 0 ) {
                printf( "  actual time stamp %lx -> %s", file_stat.st_mtime,
                        ctime( &(file_stat.st_mtime) ) );
            }
            break;
        case SAMP_ADDR_MAP:
            j = data->pref.length;
            j -= offsetof( samp_block, d.map );
            j /= sizeof( data->d.map );
            for( i = 0; i < j; ++i ) {
                COND_SWAP_16( data->d.map.data[i].map.segment );
                COND_SWAP_32( data->d.map.data[i].map.offset );
                COND_SWAP_16( data->d.map.data[i].actual.segment );
                COND_SWAP_32( data->d.map.data[i].actual.offset );
                printf( "  - %.4x:%.8lx -> %.4x:%.8lx\n",
                        data->d.map.data[i].map.segment,
                        data->d.map.data[i].map.offset,
                        data->d.map.data[i].actual.segment,
                        data->d.map.data[i].actual.offset );
            }
            break;
        case SAMP_LAST:
            break;
        case SAMP_REMAP_SECTION:
            j = data->pref.length;
            j -= offsetof( samp_block, d.remap );
            j /= sizeof( data->d.remap );
            for( i = 0; i < j; ++i ) {
                COND_SWAP_16( data->d.remap.data[i].section );
                COND_SWAP_16( data->d.remap.data[i].segment );
                printf( "  - %.4x -> %.4x\n",
                        data->d.remap.data[i].section,
                        data->d.remap.data[i].segment );
            }
            break;
        case SAMP_CALLGRAPH:
            j = data->d.cgraph.number;
            printf( "  thread id %u  #samples %u\n",
                                 data->d.cgraph.thread_id, j );
            if( quiet ) {
                printf( "    ....\n    ....\n    ....\n" );
            } else {
                sptr = &data->d.cgraph.sample[0];
                for( i = 0; i < j; i++ ) {
                    if( sptr->push_n != (uint_16)-1 || sptr->pop_n != (uint_16)-1 ) {
                        length -= sptr->pop_n;
                        if( length < 0 ) {
                            printf( "\n** Error: stack exhausted!\n\n" );
                        } else {
                            for( k = 0; k < length; k++ ) {
                                printf( " -  " );
                            }
                        }
                        for( k = sptr->push_n; k > 0; k-- ) {
                            printf( "%.4x:%.8lx    ",
                                sptr->addr[k - 1].segment,
                                sptr->addr[k - 1].offset );
                        }
                        length += sptr->push_n;
                        printf( "\n" );
                        sptr = (cgraph_sample *)&(sptr->addr[sptr->push_n]);
                    } else {
                        printf( "** Unknown callgraph info\n" );
                        sptr = (cgraph_sample *)&(sptr->addr[0]);
                    }
                }
            }
            break;
        }
        if( data->pref.kind == SAMP_LAST ) {
            break;
        }
    }
    fclose( fp );
    return( 0 );
}