Skip to content

Commit

Permalink
Worked on Python 3 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Nov 8, 2015
1 parent 3bc9668 commit 4970706
Show file tree
Hide file tree
Showing 25 changed files with 2,049 additions and 1,008 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ language: c
os:
- linux
- osx
osx_image: xcode61
compiler:
- clang
- gcc
before_install:
- if test `uname -s` = 'Darwin'; then brew update && brew install gettext && brew link --force gettext; fi
- if test `uname -s` = 'Linux'; then sudo apt-get update && sudo apt-get -o Dpkg::Options::="--force-confnew" -y upgrade && sudo apt-get install autopoint; fi
- if test `uname -s` = 'Linux'; then sudo apt-get update && sudo apt-mark hold postgresql-9.3 postgresql-client-9.3 postgresql-client-common postgresql-common postgresql-contrib-9.3 postgresql-doc-9.3 && sudo apt-get -o Dpkg::Options::="--force-confold" -y upgrade && sudo apt-get install autopoint; fi
install:
- ./synclibs.sh && ./autogen.sh
script:
- ./configure --enable-python && make && make check
- if test -f tests/test-suite.log; then cat tests/test-suite.log; fi
- ./runtests.sh
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ Tests:
- compressed (done)
- (compressed) with parent (done)

20141221
* worked on Python 3 support
* worked on tests

20141205
* worked on test scripts

20141129
* code clean up

Expand Down
4 changes: 1 addition & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ VMDK format features not supported at the moment:

Work in progress:
* Dokan library support
* Thread-safety in handle API functions

Planned:
* Python 3 support
* Thread-safety in handle API functions

For more information see:
* Project documentation: https://github.com/libyal/libvmdk/wiki/Home
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AC_PREREQ( 2.59 )

AC_INIT(
[libvmdk],
[20141129],
[20141221],
[joachim.metz@gmail.com])

AC_CONFIG_SRCDIR(
Expand Down
34 changes: 34 additions & 0 deletions libvmdk-wiki.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,42 @@ url: "https://github.com/libyal/libvmdk.git"
build_dependencies: []

[development]
features: ["pytsk3"]
main_object: "handle"
main_object_filename: "image.vmdk"
main_object_post_open_python: [
"vmdk_handle.open_extent_data_files()"]
main_object_post_open_file_object_python: [
"base_directory = os.path.dirname(filename)",
"",
"extent_data_files = []",
"for extent_descriptor in vmdk_handle.extent_descriptors:",
" extent_data_filename = extent_descriptor.filename",
"",
" _, path_separator, filename = extent_data_filename.rpartition(\"/\")",
" if not path_separator:",
" _, path_separator, filename = extent_data_filename.rpartition(\"\\\\\")",
"",
" if not path_separator:",
" filename = extent_data_filename",
"",
" extent_data_file_path = os.path.join(base_directory, filename)",
"",
" if not os.path.exists(extent_data_file_path):",
" break",
"",
" extent_data_files.append(extent_data_file_path)",
"",
"if len(extent_data_files) != vmdk_handle.number_of_extents:",
" raise RuntimeError(\"Unable to locate all extent data files.\")",
"",
"file_objects = []",
"for extent_data_file_path in extent_data_files:",
" file_object = open(extent_data_file_path, \"rb\")",
" file_objects.append(file_object)",
"",
"vmdk_handle.open_extent_data_files_file_objects(file_objects)"]
main_object_size: "media_size"

[tests]
features: ["profiles", "valgrind"]
Expand Down
196 changes: 173 additions & 23 deletions libvmdk/libvmdk_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -3110,6 +3110,17 @@ ssize_t libvmdk_handle_read_buffer(
}
internal_handle = (libvmdk_internal_handle_t *) handle;

if( internal_handle->extent_data_file_io_pool == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid handle - missing extent data file IO pool.",
function );

return( -1 );
}
#if defined( HAVE_LIBVMDK_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_grab_for_write(
internal_handle->read_write_lock,
Expand Down Expand Up @@ -3188,6 +3199,17 @@ ssize_t libvmdk_handle_read_buffer_at_offset(
}
internal_handle = (libvmdk_internal_handle_t *) handle;

if( internal_handle->extent_data_file_io_pool == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid handle - missing extent data file IO pool.",
function );

return( -1 );
}
#if defined( HAVE_LIBVMDK_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_grab_for_write(
internal_handle->read_write_lock,
Expand Down Expand Up @@ -3264,6 +3286,23 @@ ssize_t libvmdk_handle_read_buffer_at_offset(

#ifdef TODO_WRITE_SUPPORT

/* Writes (media) data at the current offset from a buffer using a Basic File IO (bfio) pool
* the necessary settings of the write values must have been made
* Will initialize write if necessary
* This function is not multi-thread safe acquire write lock before call
* Returns the number of input bytes written, 0 when no longer bytes can be written or -1 on error
*/
ssize_t libvmdk_internal_handle_write_buffer_to_file_io_pool(
libvmdk_internal_handle_t *internal_handle,
libbfio_pool_t *file_io_pool,
void *buffer,
size_t buffer_size,
libcerror_error_t **error )
{
/* TODO implement */
return( -1 );
}

/* Writes (media) data at the current offset
* the necessary settings of the write values must have been made
* Will initialize write if necessary
Expand All @@ -3277,6 +3316,7 @@ ssize_t libvmdk_handle_write_buffer(
{
libvmdk_internal_handle_t *internal_handle = NULL;
static char *function = "libvmdk_handle_write_buffer";
ssize_t write_count = 0;

if( handle == NULL )
{
Expand All @@ -3291,45 +3331,69 @@ ssize_t libvmdk_handle_write_buffer(
}
internal_handle = (libvmdk_internal_handle_t *) handle;

if( internal_handle->io_handle == NULL )
if( internal_handle->extent_data_file_io_pool == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid handle - missing IO handle.",
"%s: invalid handle - missing extent data file IO pool.",
function );

return( -1 );
}
if( buffer == NULL )
#if defined( HAVE_LIBVMDK_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_grab_for_write(
internal_handle->read_write_lock,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid buffer.",
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to grab read/write lock for writing.",
function );

return( -1 );
}
if( buffer_size > (size_t) SSIZE_MAX )
#endif
write_count = libvmdk_internal_handle_write_buffer_to_file_io_pool(
internal_handle,
internal_handle->extent_data_file_io_pool,
buffer,
buffer_size,
error );

if( write_count == -1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM,
"%s: invalid element data size value exceeds maximum.",
LIBCERROR_ERROR_DOMAIN_IO,
LIBCERROR_IO_ERROR_READ_FAILED,
"%s: unable to write buffer.",
function );

return( -1 );
write_count = -1;
}
/* TODO */
#if defined( HAVE_LIBVMDK_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_release_for_write(
internal_handle->read_write_lock,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to release read/write lock for writing.",
function );

return( -1 );
return( -1 );
}
#endif
return( write_count );
}

/* Writes (media) data in VMDK format at a specific offset,
/* Writes (media) data at a specific offset,
* the necessary settings of the write values must have been made
* Will initialize write if necessary
* Returns the number of input bytes written, 0 when no longer bytes can be written or -1 on error
Expand All @@ -3341,11 +3405,51 @@ ssize_t libvmdk_handle_write_buffer_at_offset(
off64_t offset,
libcerror_error_t **error )
{
static char *function = "libvmdk_handle_write_buffer_at_offset";
ssize_t write_count = 0;
libvmdk_internal_handle_t *internal_handle = NULL;
static char *function = "libvmdk_handle_write_buffer_at_offset";
ssize_t write_count = 0;

if( libvmdk_handle_seek_offset(
handle,
if( handle == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
"%s: invalid handle.",
function );

return( -1 );
}
internal_handle = (libvmdk_internal_handle_t *) handle;

if( internal_handle->extent_data_file_io_pool == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid handle - missing extent data file IO pool.",
function );

return( -1 );
}
#if defined( HAVE_LIBVMDK_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_grab_for_write(
internal_handle->read_write_lock,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to grab read/write lock for writing.",
function );

return( -1 );
}
#endif
if( libvmdk_internal_handle_seek_offset(
internal_handle,
offset,
SEEK_SET,
error ) == -1 )
Expand All @@ -3357,26 +3461,50 @@ ssize_t libvmdk_handle_write_buffer_at_offset(
"%s: unable to seek offset.",
function );

return( -1 );
goto on_error;
}
write_count = libvmdk_handle_write_buffer(
handle,
write_count = libvmdk_internal_handle_write_buffer_to_file_io_pool(
internal_handle,
internal_handle->extent_data_file_io_pool,
buffer,
buffer_size,
error );

if( write_count <= -1 )
if( write_count == -1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_IO,
LIBCERROR_IO_ERROR_WRITE_FAILED,
LIBCERROR_IO_ERROR_READ_FAILED,
"%s: unable to write buffer.",
function );

goto on_error;
}
#if defined( HAVE_LIBVMDK_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_release_for_write(
internal_handle->read_write_lock,
error ) != 1 )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to release read/write lock for writing.",
function );

return( -1 );
}
#endif
return( write_count );

on_error:
#if defined( HAVE_LIBVMDK_MULTI_THREAD_SUPPORT )
libcthreads_read_write_lock_release_for_write(
internal_handle->read_write_lock,
NULL );
#endif
return( -1 );
}

#endif /* TODO_WRITE_SUPPORT */
Expand Down Expand Up @@ -3477,6 +3605,17 @@ off64_t libvmdk_handle_seek_offset(
}
internal_handle = (libvmdk_internal_handle_t *) handle;

if( internal_handle->extent_data_file_io_pool == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid handle - missing extent data file IO pool.",
function );

return( -1 );
}
#if defined( HAVE_LIBVMDK_MULTI_THREAD_SUPPORT )
if( libcthreads_read_write_lock_grab_for_write(
internal_handle->read_write_lock,
Expand Down Expand Up @@ -3562,6 +3701,17 @@ int libvmdk_handle_get_offset(

return( -1 );
}
if( internal_handle->extent_data_file_io_pool == NULL )
{
libcerror_error_set(
error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_VALUE_MISSING,
"%s: invalid handle - missing extent data file IO pool.",
function );

return( -1 );
}
if( offset == NULL )
{
libcerror_error_set(
Expand Down
Loading

0 comments on commit 4970706

Please sign in to comment.