Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 101 additions & 9 deletions libcfile/libcfile_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,13 @@ int libcfile_file_open_with_error_code(
#if ( WINVER >= 0x0600 )
FILE_ALIGNMENT_INFO file_alignment_information;

BOOL result = 0;
#else
DISK_GEOMETRY_EX disk_geom;
DWORD bytes_returned = 0;
#endif

BOOL result = 0;
size_t sector_size = 0;
libcfile_internal_file_t *internal_file = NULL;
static char *function = "libcfile_file_open_with_error_code";
DWORD file_io_access_flags = 0;
Expand Down Expand Up @@ -542,12 +546,55 @@ int libcfile_file_open_with_error_code(
#endif
libcerror_error_free(
error );
} else if(file_alignment_information.AlignmentRequirement != 0) {
sector_size = 512;
}
else if( file_alignment_information.AlignmentRequirement != 0 )
#else
result = DeviceIoControl(
internal_file->handle,
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
NULL,
0,
&disk_geom,
sizeof(disk_geom),
&bytes_returned,
NULL);

if( result == FALSE && GetLastError() != ERROR_MORE_DATA )
{
*error_code = (uint32_t) GetLastError();

libcerror_system_set_error(
error,
LIBCERROR_ERROR_DOMAIN_IO,
LIBCERROR_IO_ERROR_IOCTL_FAILED,
*error_code,
"%s: unable to retrieve file alignment information.",
function );

#if defined( HAVE_DEBUG_OUTPUT )
if( libcnotify_verbose != 0 )
{
if( ( error != NULL )
&& ( *error != NULL ) )
{
libcnotify_print_error_backtrace(
*error );
}
}
#endif
libcerror_error_free(
error );
} else {
sector_size = disk_geom.Geometry.BytesPerSector;
}
#endif /* ( WINVER >= 0x0600 ) */

if( sector_size != 0 )
{
if( libcfile_internal_file_set_block_size(
internal_file,
(size_t) 512,
sector_size,
error ) != 1 )
{
libcerror_error_set(
Expand All @@ -560,7 +607,7 @@ int libcfile_file_open_with_error_code(
return( -1 );
}
}
#endif /* ( WINVER >= 0x0600 ) */

}
if( libcfile_internal_file_get_size(
internal_file,
Expand Down Expand Up @@ -806,10 +853,13 @@ int libcfile_file_open_wide_with_error_code(
{
#if ( WINVER >= 0x0600 )
FILE_ALIGNMENT_INFO file_alignment_information;

BOOL result = 0;
#else
DISK_GEOMETRY_EX disk_geom;
DWORD bytes_returned = 0;
#endif

BOOL result = 0;
size_t sector_size = 0;
libcfile_internal_file_t *internal_file = NULL;
static char *function = "libcfile_file_open_wide_with_error_code";
DWORD file_io_access_flags = 0;
Expand Down Expand Up @@ -1062,11 +1112,54 @@ int libcfile_file_open_wide_with_error_code(
libcerror_error_free(
error );
}
else if( file_alignment_information.AlignmentRequirement != 0 )
else if(file_alignment_information.AlignmentRequirement != 0) {
sector_size = 512;
}
#else
result = DeviceIoControl(
internal_file->handle,
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX,
NULL,
0,
&disk_geom,
sizeof(disk_geom),
&bytes_returned,
NULL);

if( result == FALSE && GetLastError() != ERROR_MORE_DATA )
{
*error_code = (uint32_t) GetLastError();

libcerror_system_set_error(
error,
LIBCERROR_ERROR_DOMAIN_IO,
LIBCERROR_IO_ERROR_IOCTL_FAILED,
*error_code,
"%s: unable to retrieve file alignment information.",
function );

#if defined( HAVE_DEBUG_OUTPUT )
if( libcnotify_verbose != 0 )
{
if( ( error != NULL )
&& ( *error != NULL ) )
{
libcnotify_print_error_backtrace(
*error );
}
}
#endif
libcerror_error_free(
error );
} else {
sector_size = disk_geom.Geometry.BytesPerSector;
}
#endif /* ( WINVER >= 0x0600 ) */
if( sector_size != 0 )
{
if( libcfile_internal_file_set_block_size(
internal_file,
(size_t) 512,
sector_size,
error ) != 1 )
{
libcerror_error_set(
Expand All @@ -1079,7 +1172,6 @@ int libcfile_file_open_wide_with_error_code(
return( -1 );
}
}
#endif /* ( WINVER >= 0x0600 ) */
}
if( libcfile_internal_file_get_size(
internal_file,
Expand Down