/* Tests retrieving the library version * Returns 1 if successful or 0 if not */ int fusn_test_get_version( void ) { const char *version_string = NULL; int result = 0; version_string = libfusn_get_version(); result = libcstring_narrow_string_compare( version_string, LIBFUSN_VERSION_STRING, 9 ); if( result != 0 ) { return( 0 ); } return( 1 ); }
/* Determines and retrieves the bus type * Returns 1 if successful or -1 on error */ int libsmdev_scsi_get_bus_type( int file_descriptor, uint8_t *bus_type, liberror_error_t **error ) { #if defined( SCSI_IOCTL_PROBE_HOST ) union { int length; char buffer[ 128 ]; } sg_probe_host; size_t sg_probe_host_length = 0; #endif static char *function = "libsmdev_scsi_get_bus_type"; if( file_descriptor == -1 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_ARGUMENTS, LIBERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file descriptor.", function ); return( -1 ); } if( bus_type == NULL ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_ARGUMENTS, LIBERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid bus type.", function ); return( -1 ); } *bus_type = LIBSMDEV_BUS_TYPE_UNKNOWN; #if defined( SCSI_IOCTL_PROBE_HOST ) sg_probe_host.length = 127; if( ioctl( file_descriptor, SCSI_IOCTL_PROBE_HOST, &sg_probe_host ) == -1 ) { liberror_error_set( error, LIBERROR_ERROR_DOMAIN_IO, LIBERROR_IO_ERROR_IOCTL_FAILED, "%s: unable to query device for: SCSI_IOCTL_PROBE_HOST.", function ); return( -1 ); } sg_probe_host.buffer[ 127 ] = 0; sg_probe_host_length = libcstring_narrow_string_length( sg_probe_host.buffer ); #if defined( HAVE_DEBUG_OUTPUT ) if( libnotify_verbose != 0 ) { libnotify_printf( "%s: SCSI_IOCTL_PROBE_HOST (length: %d): %s\n", function, sg_probe_host_length, sg_probe_host.buffer ); libnotify_printf( "\n" ); } #endif if( sg_probe_host_length >= 4 ) { if( libcstring_narrow_string_compare( sg_probe_host.buffer, "ahci", 4 ) == 0 ) { *bus_type = LIBSMDEV_BUS_TYPE_ATA; } else if( libcstring_narrow_string_compare( sg_probe_host.buffer, "pata", 4 ) == 0 ) { *bus_type = LIBSMDEV_BUS_TYPE_ATA; } else if( libcstring_narrow_string_compare( sg_probe_host.buffer, "sata", 4 ) == 0 ) { *bus_type = LIBSMDEV_BUS_TYPE_ATA; } } /* Serial Bus Protocol (SBP-2) */ else if( ( sg_probe_host_length == 15 ) && ( libcstring_narrow_string_compare( sg_probe_host.buffer, "SBP-2 IEEE-1394", 15 ) == 0 ) ) { *bus_type = LIBSMDEV_BUS_TYPE_FIREWIRE; } else if( ( sg_probe_host_length == 43 ) && ( libcstring_narrow_string_compare( sg_probe_host.buffer, "SCSI emulation for USB Mass Storage devices", 43 ) == 0 ) ) { *bus_type = LIBSMDEV_BUS_TYPE_USB; } #endif return( 1 ); }
/* Opens a file * Returns 0 if successful or a negative errno value otherwise */ int vshadowmount_fuse_open( const char *path, struct fuse_file_info *file_info ) { libcerror_error_t *error = NULL; static char *function = "vshadowmount_fuse_open"; size_t path_length = 0; int result = 0; if( path == NULL ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid path.", function ); result = -EINVAL; goto on_error; } if( file_info == NULL ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file info.", function ); result = -EINVAL; goto on_error; } path_length = libcstring_narrow_string_length( path ); if( ( path_length <= vshadowmount_fuse_path_prefix_length ) || ( path_length > ( vshadowmount_fuse_path_prefix_length + 3 ) ) || ( libcstring_narrow_string_compare( path, vshadowmount_fuse_path_prefix, vshadowmount_fuse_path_prefix_length ) != 0 ) ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported path.", function ); result = -ENOENT; goto on_error; } if( ( file_info->flags & 0x03 ) != O_RDONLY ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_RUNTIME, LIBCERROR_RUNTIME_ERROR_UNSUPPORTED_VALUE, "%s: write access currently not supported.", function ); result = -EACCES; goto on_error; } return( 0 ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } return( result ); }
/* Reads a buffer of data at the specified offset * Returns number of bytes read if successful or a negative errno value otherwise */ int vshadowmount_fuse_read( const char *path, char *buffer, size_t size, off_t offset, struct fuse_file_info *file_info ) { libcerror_error_t *error = NULL; static char *function = "vshadowmount_fuse_read"; size_t path_length = 0; ssize_t read_count = 0; int result = 0; int store_index = 0; int string_index = 0; if( path == NULL ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid path.", function ); result = -EINVAL; goto on_error; } if( size > (size_t) INT_MAX ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, "%s: invalid size value exceeds maximum.", function ); result = -EINVAL; goto on_error; } if( file_info == NULL ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, "%s: invalid file info.", function ); result = -EINVAL; goto on_error; } path_length = libcstring_narrow_string_length( path ); if( ( path_length <= vshadowmount_fuse_path_prefix_length ) || ( path_length > ( vshadowmount_fuse_path_prefix_length + 3 ) ) || ( libcstring_narrow_string_compare( path, vshadowmount_fuse_path_prefix, vshadowmount_fuse_path_prefix_length ) != 0 ) ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_ARGUMENTS, LIBCERROR_ARGUMENT_ERROR_UNSUPPORTED_VALUE, "%s: unsupported path.", function ); result = -ENOENT; goto on_error; } string_index = vshadowmount_fuse_path_prefix_length; store_index = path[ string_index++ ] - '0'; if( string_index < (int) path_length ) { store_index *= 10; store_index += path[ string_index++ ] - '0'; } if( string_index < (int) path_length ) { store_index *= 10; store_index += path[ string_index++ ] - '0'; } store_index -= 1; if( mount_handle_seek_offset( vshadowmount_mount_handle, store_index, (off64_t) offset, SEEK_SET, &error ) == -1 ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_SEEK_FAILED, "%s: unable to seek offset in mount handle.", function ); result = -EIO; goto on_error; } read_count = mount_handle_read_buffer( vshadowmount_mount_handle, store_index, (uint8_t *) buffer, size, &error ); if( read_count == -1 ) { libcerror_error_set( &error, LIBCERROR_ERROR_DOMAIN_IO, LIBCERROR_IO_ERROR_READ_FAILED, "%s: unable to read from mount handle.", function ); result = -EIO; goto on_error; } return( (int) read_count ); on_error: if( error != NULL ) { libcnotify_print_error_backtrace( error ); libcerror_error_free( &error ); } return( result ); }
/* Retrieves the codepage for the locale character set * Returns the codepage or 0 if the character set is UTF-8 * The codepage will default to LIBCSTRING_CODEPAGE_ASCII the codepage cannot be determined */ int libcstring_locale_get_codepage( void ) { char *locale = NULL; char *charset = NULL; size_t charset_length = 0; size_t locale_length = 0; int codepage = 0; #if defined( HAVE_LANGINFO_CODESET ) charset = nl_langinfo( CODESET ); #endif if( ( charset != NULL ) && ( charset[ 0 ] != 0 ) ) { charset_length = libcstring_narrow_string_length( charset ); } else { #if defined( HAVE_SETLOCALE ) || ( defined( __BORLANDC__ ) && __BORLANDC__ <= 0x0520 ) locale = setlocale( LC_CTYPE, "" ); /* Check if the locale returned is not "C" */ if( ( locale != NULL ) && ( locale[ 0 ] != 0 ) ) { if( ( locale[ 0 ] == 'C' ) && ( locale[ 1 ] != 0 ) ) { locale = NULL; } } #endif #if defined( HAVE_GETENV ) || defined( WINAPI ) /* Check if the locale can be determined from the environment variables */ if( ( locale == NULL ) || ( locale[ 0 ] == 0 ) ) { locale = getenv( "LC_ALL" ); } if( ( locale == NULL ) || ( locale[ 0 ] == 0 ) ) { locale = getenv( "LC_TYPE" ); } if( ( locale == NULL ) || ( locale[ 0 ] == 0 ) ) { locale = getenv( "LANG" ); } #endif if( ( locale == NULL ) || ( locale[ 0 ] == 0 ) ) { return( LIBCSTRING_CODEPAGE_ASCII ); } locale_length = libcstring_narrow_string_length( locale ); charset = libcstring_narrow_string_search_character( locale, '.', locale_length + 1 ); if( charset == NULL ) { return( LIBCSTRING_CODEPAGE_ASCII ); } charset++; charset_length = locale_length - (size_t) ( charset - locale ); } /* Determine codepage */ codepage = LIBCSTRING_CODEPAGE_ASCII; if( codepage == LIBCSTRING_CODEPAGE_ASCII ) { if( charset_length == 5 ) { if( libcstring_narrow_string_compare( "UTF-8", charset, 5 ) == 0 ) { codepage = 0; } } } if( codepage == LIBCSTRING_CODEPAGE_ASCII ) { if( charset_length >= 3 ) { if( libcstring_narrow_string_compare( "874", charset, 3 ) == 0 ) { codepage = LIBCSTRING_CODEPAGE_WINDOWS_874; } } } if( codepage == LIBCSTRING_CODEPAGE_ASCII ) { if( charset_length >= 4 ) { if( libcstring_narrow_string_compare( "1250", charset, 4 ) == 0 ) { codepage = LIBCSTRING_CODEPAGE_WINDOWS_1250; } else if( libcstring_narrow_string_compare( "1251", charset, 4 ) == 0 ) { codepage = LIBCSTRING_CODEPAGE_WINDOWS_1251; } else if( libcstring_narrow_string_compare( "1252", charset, 4 ) == 0 ) { codepage = LIBCSTRING_CODEPAGE_WINDOWS_1252; } else if( libcstring_narrow_string_compare( "1253", charset, 4 ) == 0 ) { codepage = LIBCSTRING_CODEPAGE_WINDOWS_1253; } else if( libcstring_narrow_string_compare( "1254", charset, 4 ) == 0 ) { codepage = LIBCSTRING_CODEPAGE_WINDOWS_1254; } else if( libcstring_narrow_string_compare( "1255", charset, 4 ) == 0 ) { codepage = LIBCSTRING_CODEPAGE_WINDOWS_1255; } else if( libcstring_narrow_string_compare( "1256", charset, 4 ) == 0 ) { codepage = LIBCSTRING_CODEPAGE_WINDOWS_1256; } else if( libcstring_narrow_string_compare( "1257", charset, 4 ) == 0 ) { codepage = LIBCSTRING_CODEPAGE_WINDOWS_1257; } else if( libcstring_narrow_string_compare( "1258", charset, 4 ) == 0 ) { codepage = LIBCSTRING_CODEPAGE_WINDOWS_1258; } else if( libcstring_narrow_string_compare( "utf8", charset, 4 ) == 0 ) { codepage = 0; } } } return( codepage ); }