/*
 * EwfSize
 */
static int EwfSize(void *p_handle, uint64_t *p_size) {
  pts_EwfHandle p_ewf_handle=(pts_EwfHandle)p_handle;

#ifdef HAVE_LIBEWF_V2_API
  if(libewf_handle_get_media_size(p_ewf_handle->h_ewf,p_size,NULL)!=1) {
#else
  if(libewf_get_media_size(p_ewf_handle->h_ewf,p_size)!=1) {
#endif
    return EWF_GET_SIZE_FAILED;
  }

  return EWF_OK;
}

/*
 * EwfRead
 */
static int EwfRead(void *p_handle,
                   char *p_buf,
                   off_t offset,
                   size_t count,
                   size_t *p_read,
                   int *p_errno)
{
  pts_EwfHandle p_ewf_handle=(pts_EwfHandle)p_handle;
  // TODO: Return value of libewf_handle_read_buffer is ssize_t with -1 on error
  size_t bytes_read;

#ifdef HAVE_LIBEWF_V2_API
  if(libewf_handle_seek_offset(p_ewf_handle->h_ewf,
                               offset,
                               SEEK_SET,
                               NULL)!=-1)
#else
  if(libewf_seek_offset(p_ewf_handle->h_ewf,offset)!=-1)
#endif
  {
#ifdef HAVE_LIBEWF_V2_API
    bytes_read=libewf_handle_read_buffer(p_ewf_handle->h_ewf,
                                         p_buf,
                                         count,
                                         NULL);
#else
    bytes_read=libewf_read_buffer(p_ewf_handle->h_ewf,p_buf,count);
#endif
    if(bytes_read!=count) return EWF_READ_FAILED;
  } else {
    return EWF_SEEK_FAILED;
  }

  *p_read=bytes_read;
  return EWF_OK;
}
Exemple #2
0
/* Reads media data from an offset into a buffer
 * This function swaps byte pairs if specified
 * Returns the amount of bytes read, or -1 on error
 */
ssize_t libewf_read_random( LIBEWF_HANDLE *handle, void *buffer, size_t size, off_t offset )
{
	ssize_t read_count = 0;

	if( libewf_seek_offset( handle, offset ) == -1 )
	{
		LIBEWF_WARNING_PRINT( "libewf_read_random: unable to seek offset.\n" );

		return( -1 );
	}
	read_count = libewf_read_buffer( handle, buffer, size );

	if( read_count <= -1 )
	{
		LIBEWF_WARNING_PRINT( "libewf_read_random: unable to read buffer.\n" );

		return( -1 );
	}
	return( read_count );
}
Exemple #3
0
static ut64 ewf__lseek(RIO *io, RIODesc *fd, ut64 offset, int whence) {
	if (RIOEWF_IS_VALID (fd)) {
		size64_t media_size;
		switch (whence) {
		case SEEK_SET:
			/* ignore */
			break;
		case SEEK_CUR:
			offset += io->seek;
			break;
		case SEEK_END:
			libewf_get_media_size (RIOEWF_HANDLE (fd), &media_size);
			offset = media_size - offset;
			break;
		}
		libewf_seek_offset (RIOEWF_HANDLE (fd), offset);
		return offset;
	}
	return (ut64)-1;
}
Exemple #4
0
ut64 ewf_lseek(int fildes, ut64 offset, int whence)
{
	size64_t media_size;

	if (fildes == ewf_fd) {
		switch(whence) {
			case SEEK_SET:
				/* ignore */
				break;
			case SEEK_CUR:
				offset += config.seek;
				break;
			case SEEK_END:
				libewf_get_media_size(ewf_h, &media_size);
				offset = media_size - offset;
				break;
		}
		libewf_seek_offset(ewf_h, offset);
		return offset;
	}

	return lseek(fildes, offset, whence);
}