1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
/*
* Metadata functions for the Python object definition of the libsmdev handle
*
* Copyright (C) 2010-2016, Joachim Metz <joachim.metz@gmail.com>
*
* Refer to AUTHORS for acknowledgements.
*
* This software is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this software. If not, see <http://www.gnu.org/licenses/>.
*/
#include <common.h>
#include <types.h>
#include "pysmdev_error.h"
#include "pysmdev_handle.h"
#include "pysmdev_integer.h"
#include "pysmdev_libcerror.h"
#include "pysmdev_libcstring.h"
#include "pysmdev_libsmdev.h"
#include "pysmdev_metadata.h"
#include "pysmdev_python.h"
#include "pysmdev_unused.h"
/* Retrieves the size of the media data
* Returns a Python object holding the offset if successful or NULL on error
*/
PyObject *pysmdev_handle_get_media_size(
pysmdev_handle_t *pysmdev_handle,
PyObject *arguments PYSMDEV_ATTRIBUTE_UNUSED )
{
libcerror_error_t *error = NULL;
PyObject *integer_object = NULL;
static char *function = "pysmdev_handle_get_media_size";
size64_t media_size = 0;
int result = 0;
PYSMDEV_UNREFERENCED_PARAMETER( arguments )
if( pysmdev_handle == NULL )
{
PyErr_Format(
PyExc_TypeError,
"%s: invalid handle.",
function );
return( NULL );
}
Py_BEGIN_ALLOW_THREADS
result = libsmdev_handle_get_media_size(
pysmdev_handle->handle,
&media_size,
&error );
Py_END_ALLOW_THREADS
if( result != 1 )
{
pysmdev_error_raise(
error,
PyExc_IOError,
"%s: unable to retrieve media size.",
function );
libcerror_error_free(
&error );
return( NULL );
}
integer_object = pysmdev_integer_unsigned_new_from_64bit(
(uint64_t) media_size );
return( integer_object );
}
/* Retrieves the number of bytes per sector
* Returns a Python object holding the offset if successful or NULL on error
*/
PyObject *pysmdev_handle_get_bytes_per_sector(
pysmdev_handle_t *pysmdev_handle,
PyObject *arguments PYSMDEV_ATTRIBUTE_UNUSED )
{
libcerror_error_t *error = NULL;
PyObject *integer_object = NULL;
static char *function = "pysmdev_handle_get_bytes_per_sector";
uint32_t bytes_per_sector = 0;
int result = 0;
PYSMDEV_UNREFERENCED_PARAMETER( arguments )
if( pysmdev_handle == NULL )
{
PyErr_Format(
PyExc_TypeError,
"%s: invalid handle.",
function );
return( NULL );
}
Py_BEGIN_ALLOW_THREADS
result = libsmdev_handle_get_bytes_per_sector(
pysmdev_handle->handle,
&bytes_per_sector,
&error );
Py_END_ALLOW_THREADS
if( result == -1 )
{
pysmdev_error_raise(
error,
PyExc_IOError,
"%s: unable to retrieve bytes per sector.",
function );
libcerror_error_free(
&error );
return( NULL );
}
else if( result == 0 )
{
Py_IncRef(
Py_None );
return( Py_None );
}
integer_object = pysmdev_integer_unsigned_new_from_64bit(
(uint64_t) bytes_per_sector );
return( integer_object );
}
|