Beispiel #1
0
Cardinal 
UrmResizeResourceContext (URMResourceContextPtr	context_id,
			  int			size)

{

  /*
   *  Local variables
   */
  char			*newbuf ;	/* new buffer */


  if ( ! UrmRCValid(context_id) )
    return Urm__UT_Error ("UrmResizeResourceContext", _MrmMMsg_0028,
			  NULL, context_id, MrmBAD_CONTEXT) ;

  if ( size > MrmMaxResourceSize)
    return Urm__UT_Error ("MrmResizeResourceContext", _MrmMMsg_0029,
			  NULL, context_id, MrmTOO_MANY) ;

  /*
   * CR 8391: buffer will eventually be passed to
   * Urm__CW_EvaluateValOrOffset which is expecting a long.  Make sure to
   * allocate at least a long so that we don't get array bounds read
   * violations.  Ideally Urm__CW_EvaluateValOrOffset and the code that
   * calls it should be rewritten, but we don't have time for that now.
   */
  if (size < sizeof(long)) size = sizeof(long);

  /*
   * Resize unless buffer is bigger than requested size.
   */
  if ( context_id->buffer_size > size ) return MrmSUCCESS ;

  /*
   * Allocate the new buffer, copy the old buffer contents, and
   * update the context.
   */
  if ( context_id->alloc_func == XtMalloc )
    {
      context_id->data_buffer = XtRealloc (context_id->data_buffer, size) ;
      context_id->buffer_size = size ;
    }
  else
    {
      newbuf = (char *) (*(context_id->alloc_func)) (size) ;
      if ( newbuf == NULL )
        return Urm__UT_Error ("UrmResizeResourceContext", _MrmMMsg_0001,
			      NULL, context_id, MrmFAILURE) ;
      if ( context_id->data_buffer != NULL )
        {
	  UrmBCopy (context_id->data_buffer, newbuf, context_id->buffer_size) ;
	  (*(context_id->free_func)) (context_id->data_buffer) ;
        }
      context_id->data_buffer = newbuf ;
      context_id->buffer_size = size ;
    }

  /*
   * Resize succeeded
   */
  return MrmSUCCESS ;

}
Beispiel #2
0
Cardinal 
Idb__BM_GetRecord (IDBFile                     file_id,
		   IDBRecordNumber             record,
		   IDBRecordBufferPtr          *buffer_return)
{

  /*
   *  Local variables
   */
  Cardinal		result ;  /* function results */
  int			ndx ;	  /* loop index */
  IDBRecordBufferPtr	curbuf ;  /* current buffer being examined */
  unsigned char		*buf_src; /* tmp pointer to location in uid buffer */

  /*
   * If buffer pool is unallocated, get a buffer (which WILL allocate it),
   * and read the record into that. Else see if the record is already in
   * memory, and return it if so. If the record is not found, get a buffer
   * to read it into. We exit this if statement with a buffer ready for
   * the read operation.
   */
  if ( idb__buffer_pool_vec == NULL )
    {
      result = Idb__BM_GetBuffer (file_id, buffer_return) ;
      if ( result != MrmSUCCESS ) return result ;
    }
  else
    {
      for ( ndx=0,curbuf=idb__buffer_pool_vec ;
            ndx<idb__buffer_pool_size ;
            ndx++,curbuf++ )
        {
	  if ( (curbuf->cur_file==file_id) &&
	       (curbuf->IDB_record->header.record_num==record) )
            {
	      *buffer_return = curbuf ;
	      Idb__BM_MarkActivity (*buffer_return) ;
	      return MrmSUCCESS ;
            }
        }
      result = Idb__BM_GetBuffer (file_id, buffer_return) ;
      if ( result != MrmSUCCESS ) return result ;
    }

  /*
   * Read the record into the buffer.
   */
  if ( file_id->in_memory ) {
    buf_src = file_id->uid_buffer + (record-1)*IDBRecordSize;
    UrmBCopy(buf_src, (*buffer_return)->IDB_record, IDBRecordSize);
    result = MrmSUCCESS;
  }
  else
    result = Idb__FU_GetBlock(file_id->lowlevel_id, record, 
			      (char*)(*buffer_return)->IDB_record) ;


  if ( result != MrmSUCCESS )
    return Urm__UT_Error ("Idb__BM_GetRecord", _MrmMMsg_0003,
			  file_id, NULL, result) ;
  file_id->get_count++ ;

  /*
   * Validate the record, this is the first routine that is called to read
   * from a newly opened file.  If the byte order is different, we find it
   * here.  
   */


  if ( (*buffer_return)->IDB_record->header.validation != 
       IDBRecordHeaderValid ) {
    swapbytes( (*buffer_return)->IDB_record->header.validation );
    if ((*buffer_return)->IDB_record->header.validation == IDBRecordHeaderValid)
      {
	/* must be a file needing byte swapping */
	file_id->byte_swapped = TRUE;
	Idb__BM_SwapRecordBytes (*buffer_return);
	Idb__BM_MarkActivity (*buffer_return);
	return MrmSUCCESS ;
      }
    /* byte swapping has done no good, return error */
    return Urm__UT_Error("Idb__BM_GetRecord", _MrmMMsg_0005,
			 file_id, NULL, MrmNOT_VALID) ;
  }

  /*
   * Record successfully read
   */
  Idb__BM_MarkActivity (*buffer_return) ;
  return MrmSUCCESS ;

}