/* Frees the mount handle and its elements * Returns 1 if successful or -1 on error */ int mount_handle_free( mount_handle_t **mount_handle, libcerror_error_t **error ) { static char *function = "mount_handle_free"; int result = 1; if( mount_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid mount handle.", function ); return( -1 ); } if( *mount_handle != NULL ) { if( ( *mount_handle )->root_file_entry != NULL ) { if( libewf_file_entry_free( &( ( *mount_handle )->root_file_entry ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free root file entry.", function ); result = -1; } } if( libewf_handle_free( &( ( *mount_handle )->input_handle ), error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_FINALIZE_FAILED, "%s: unable to free input handle.", function ); result = -1; } memory_free( *mount_handle ); *mount_handle = NULL; } return( result ); }
/* Retrieves the root file entry * Returns a Python object if successful or NULL on error */ PyObject *pyewf_handle_get_root_file_entry( pyewf_handle_t *pyewf_handle ) { char error_string[ PYEWF_ERROR_STRING_SIZE ]; libcerror_error_t *error = NULL; libewf_file_entry_t *root_file_entry = NULL; PyObject *file_entry_object = NULL; static char *function = "pyewf_handle_get_root_file_entry"; int result = 0; if( pyewf_handle == NULL ) { PyErr_Format( PyExc_TypeError, "%s: invalid handle.", function ); return( NULL ); } Py_BEGIN_ALLOW_THREADS result = libewf_handle_get_root_file_entry( pyewf_handle->handle, &root_file_entry, &error ); Py_END_ALLOW_THREADS if( result != 1 ) { if( libcerror_error_backtrace_sprint( error, error_string, PYEWF_ERROR_STRING_SIZE ) == -1 ) { PyErr_Format( PyExc_IOError, "%s: unable to retrieve root file entry.", function ); } else { PyErr_Format( PyExc_IOError, "%s: unable to retrieve root file entry.\n%s", function, error_string ); } libcerror_error_free( &error ); goto on_error; } file_entry_object = pyewf_file_entry_new( root_file_entry, pyewf_handle ); if( file_entry_object == NULL ) { PyErr_Format( PyExc_MemoryError, "%s: unable to create file entry object.", function ); goto on_error; } return( file_entry_object ); on_error: if( root_file_entry != NULL ) { libewf_file_entry_free( &root_file_entry, NULL ); } return( NULL ); }
/* Frees a file_entry object */ void pyewf_file_entry_free( pyewf_file_entry_t *pyewf_file_entry ) { libcerror_error_t *error = NULL; struct _typeobject *ob_type = NULL; static char *function = "pyewf_file_entry_free"; int result = 0; if( pyewf_file_entry == NULL ) { PyErr_Format( PyExc_TypeError, "%s: invalid file_entry.", function ); return; } if( pyewf_file_entry->file_entry == NULL ) { PyErr_Format( PyExc_TypeError, "%s: invalid file_entry - missing libewf file_entry.", function ); return; } ob_type = Py_TYPE( pyewf_file_entry ); if( ob_type == NULL ) { PyErr_Format( PyExc_ValueError, "%s: missing ob_type.", function ); return; } if( ob_type->tp_free == NULL ) { PyErr_Format( PyExc_ValueError, "%s: invalid ob_type - missing tp_free.", function ); return; } Py_BEGIN_ALLOW_THREADS result = libewf_file_entry_free( &( pyewf_file_entry->file_entry ), &error ); Py_END_ALLOW_THREADS if( result != 1 ) { pyewf_error_raise( error, PyExc_MemoryError, "%s: unable to free file_entry.", function ); libcerror_error_free( &error ); } if( pyewf_file_entry->handle_object != NULL ) { Py_DecRef( (PyObject *) pyewf_file_entry->handle_object ); } ob_type->tp_free( (PyObject*) pyewf_file_entry ); }
/* Retrieves a file entry for a specific path * Returns 1 if successful, 0 if no such file entry or -1 on error */ int mount_handle_get_file_entry_by_path( mount_handle_t *mount_handle, const system_character_t *path, mount_file_entry_t **file_entry, libcerror_error_t **error ) { libewf_file_entry_t *ewf_file_entry = NULL; libewf_handle_t *ewf_handle = NULL; const system_character_t *filename = NULL; static char *function = "mount_handle_get_file_entry_by_path"; size_t filename_length = 0; size_t path_index = 0; size_t path_length = 0; int file_entry_type = 0; int result = 0; if( mount_handle == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid mount handle.", function ); return( -1 ); } if( path == NULL ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid path.", function ); return( -1 ); } path_length = system_string_length( path ); if( path_length == 0 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_VALUE_OUT_OF_BOUNDS, "%s: invalid path length value out of bounds.", function ); goto on_error; } if( ( path_length >= 2 ) && ( path[ path_length - 1 ] == LIBCPATH_SEPARATOR ) ) { path_length--; } path_index = path_length; while( path_index > 0 ) { if( path[ path_index ] == LIBCPATH_SEPARATOR ) { break; } path_index--; } /* Ignore the name of the root item */ if( path_length == 0 ) { filename = _SYSTEM_STRING( "" ); filename_length = 0; } else { filename = &( path[ path_index + 1 ] ); filename_length = path_length - ( path_index + 1 ); } if( mount_handle->input_format == MOUNT_HANDLE_INPUT_FORMAT_FILES ) { result = mount_file_system_get_file_entry_by_path( mount_handle->file_system, path, path_length, &ewf_file_entry, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve file entry.", function ); goto on_error; } file_entry_type = MOUNT_FILE_ENTRY_TYPE_FILE_ENTRY; } else { result = mount_file_system_get_handle_by_path( mount_handle->file_system, path, path_length, &ewf_handle, error ); if( result == -1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_GET_FAILED, "%s: unable to retrieve handle.", function ); goto on_error; } file_entry_type = MOUNT_FILE_ENTRY_TYPE_HANDLE; } if( result != 0 ) { if( mount_file_entry_initialize( file_entry, mount_handle->file_system, filename, filename_length, file_entry_type, ewf_handle, ewf_file_entry, error ) != 1 ) { libcerror_error_set( error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_INITIALIZE_FAILED, "%s: unable to initialize file entry.", function ); goto on_error; } } return( result ); on_error: if( ewf_file_entry != NULL ) { libewf_file_entry_free( &ewf_file_entry, NULL ); } return( -1 ); }
/* Frees a file_entry object */ void pyewf_file_entry_free( pyewf_file_entry_t *pyewf_file_entry ) { char error_string[ PYEWF_ERROR_STRING_SIZE ]; libcerror_error_t *error = NULL; static char *function = "pyewf_file_entry_free"; int result = 0; if( pyewf_file_entry == NULL ) { PyErr_Format( PyExc_TypeError, "%s: invalid file_entry.", function ); return; } if( pyewf_file_entry->ob_type == NULL ) { PyErr_Format( PyExc_TypeError, "%s: invalid file_entry - missing ob_type.", function ); return; } if( pyewf_file_entry->ob_type->tp_free == NULL ) { PyErr_Format( PyExc_TypeError, "%s: invalid file_entry - invalid ob_type - missing tp_free.", function ); return; } if( pyewf_file_entry->file_entry == NULL ) { PyErr_Format( PyExc_TypeError, "%s: invalid file_entry - missing libewf file_entry.", function ); return; } Py_BEGIN_ALLOW_THREADS result = libewf_file_entry_free( &( pyewf_file_entry->file_entry ), &error ); Py_END_ALLOW_THREADS if( result != 1 ) { if( libcerror_error_backtrace_sprint( error, error_string, PYEWF_ERROR_STRING_SIZE ) == -1 ) { PyErr_Format( PyExc_MemoryError, "%s: unable to free file_entry.", function ); } else { PyErr_Format( PyExc_MemoryError, "%s: unable to free file_entry.\n%s", function, error_string ); } libcerror_error_free( &error ); } if( pyewf_file_entry->handle_object != NULL ) { Py_DecRef( (PyObject *) pyewf_file_entry->handle_object ); } pyewf_file_entry->ob_type->tp_free( (PyObject*) pyewf_file_entry ); }