static int fewf_pwrite(disk_t *disk, const void *buffer, const unsigned int count, const uint64_t offset) { struct info_fewf_struct *data=(struct info_fewf_struct *)disk->data; int64_t taille; #if defined( HAVE_LIBEWF_V2_API ) taille = libewf_handle_write_random( data->handle, buffer, count, offset, NULL ); #else taille=libewf_write_random(data->handle, buffer, count, offset); #endif if(taille!=count) { log_error("fewf_pwrite(xxx,%u,buffer,%lu(%u/%u/%u)) write err: ", (unsigned)(count/disk->sector_size), (long unsigned)(offset/disk->sector_size), offset2cylinder(disk,offset), offset2head(disk,offset), offset2sector(disk,offset)); log_error("%s\n", strerror(errno)); return -1; } return taille; }
/* Writes a buffer of media data at a specific offset to EWF file(s) * Returns a Python object holding the data if successful or NULL on error */ PyObject *pyewf_handle_write_random( pyewf_handle_t *pyewf_handle, PyObject *arguments, PyObject *keywords ) { char error_string[ PYEWF_ERROR_STRING_SIZE ]; liberror_error_t *error = NULL; PyObject *result_data = NULL; static char *function = "pyewf_handle_write_random"; static char *keyword_list[] = { "size", "offset", NULL }; off64_t write_offset = 0; ssize_t write_count = 0; int write_size = -1; if( pyewf_handle == NULL ) { PyErr_Format( PyExc_TypeError, "%s: invalid pyewf handle.", function ); return( NULL ); } if( pyewf_handle->handle == NULL ) { PyErr_Format( PyExc_TypeError, "%s: invalid pyewf handle - missing libewf handle.", function ); return( NULL ); } if( PyArg_ParseTupleAndKeywords( arguments, keywords, "i|L", keyword_list, &write_size, &write_offset ) == 0 ) { return( NULL ); } if( write_size < 0 ) { PyErr_Format( PyExc_ValueError, "%s: invalid argument read size value less than zero.", function ); return( NULL ); } /* Make sure the data fits into a memory buffer */ if( write_size > INT_MAX ) { PyErr_Format( PyExc_ValueError, "%s: invalid argument read size value exceeds maximum.", function ); return( NULL ); } if( write_offset < 0 ) { PyErr_Format( PyExc_ValueError, "%s: invalid argument write offset value less than zero.", function ); return( NULL ); } result_data = PyString_FromStringAndSize( NULL, write_size ); write_count = libewf_handle_write_random( pyewf_handle->handle, PyString_AsString( result_data ), (size_t) write_size, write_offset, &error ); if( write_count != (ssize_t) write_size ) { if( liberror_error_backtrace_sprint( error, error_string, PYEWF_ERROR_STRING_SIZE ) == -1 ) { PyErr_Format( PyExc_IOError, "%s: unable to write data.", function ); } else { PyErr_Format( PyExc_IOError, "%s: unable to write data.\n%s", function, error_string ); } liberror_error_free( &error ); return( NULL ); } return( result_data ); }