Skip to content

Commit

Permalink
Changes for cygfuse, fuse3 and Dokan support
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed May 28, 2024
1 parent 7019942 commit 07deb70
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 86 deletions.
28 changes: 17 additions & 11 deletions smrawtools/mount_dokan.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ extern mount_handle_t *smrawmount_mount_handle;

#endif /* ( DOKAN_VERSION >= 600 ) && ( DOKAN_VERSION < 800 ) */

#if defined( HAVE_DOKAN_LONG_PATHS )
#define DOKAN_MAX_PATH 32768
#else
#define DOKAN_MAX_PATH MAX_PATH
#endif

/* Sets the values in a file information structure
* The time values contain an unsigned 64-bit FILETIME timestamp
* Returns 1 if successful or -1 on error
Expand Down Expand Up @@ -193,7 +199,7 @@ int mount_dokan_filldir(

return( -1 );
}
if( name_size > (size_t) MAX_PATH )
if( name_size > (size_t) DOKAN_MAX_PATH )
{
libcerror_error_set(
error,
Expand Down Expand Up @@ -695,7 +701,7 @@ int __stdcall mount_dokan_OpenDirectory(

#endif /* ( DOKAN_VERSION >= 600 ) && ( DOKAN_VERSION < 800 ) */

/* Closes a file or direcotry
/* Closes a file or directory
* Returns 0 if successful or an error code otherwise
*/
#if ( DOKAN_VERSION >= 600 ) && ( DOKAN_VERSION < 800 )
Expand Down Expand Up @@ -879,19 +885,19 @@ NTSTATUS __stdcall mount_dokan_ReadFile(
goto on_error;
}
read_count = mount_file_entry_read_buffer_at_offset(
(mount_file_entry_t *) file_info->Context,
buffer,
(size_t) number_of_bytes_to_read,
(off64_t) offset,
&error );
(mount_file_entry_t *) file_info->Context,
buffer,
(size_t) number_of_bytes_to_read,
(off64_t) offset,
&error );

if( read_count < 0 )
{
libcerror_error_set(
&error,
LIBCERROR_ERROR_DOMAIN_IO,
LIBCERROR_IO_ERROR_READ_FAILED,
"%s: unable to read from mount handle.",
"%s: unable to read from file entry.",
function );

result = MOUNT_DOKAN_ERROR_READ_FAULT;
Expand Down Expand Up @@ -1009,7 +1015,7 @@ NTSTATUS __stdcall mount_dokan_FindFiles(
&error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set find data.",
"%s: unable to set self find data.",
function );

result = MOUNT_DOKAN_ERROR_GENERIC_FAILURE;
Expand Down Expand Up @@ -1047,7 +1053,7 @@ NTSTATUS __stdcall mount_dokan_FindFiles(
&error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set find data.",
"%s: unable to set parent find data.",
function );

result = MOUNT_DOKAN_ERROR_GENERIC_FAILURE;
Expand Down Expand Up @@ -1171,7 +1177,7 @@ NTSTATUS __stdcall mount_dokan_FindFiles(
&error,
LIBCERROR_ERROR_DOMAIN_RUNTIME,
LIBCERROR_RUNTIME_ERROR_SET_FAILED,
"%s: unable to set find data for sub file entry: %d.",
"%s: unable to set sub file entry: %d find data.",
function,
sub_file_entry_index );

Expand Down
88 changes: 49 additions & 39 deletions smrawtools/mount_dokan.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,41 +67,84 @@ int mount_dokan_filldir(
libcerror_error_t **error );

#if ( DOKAN_VERSION >= 600 ) && ( DOKAN_VERSION < 800 )

int __stdcall mount_dokan_CreateFile(
const wchar_t *path,
DWORD desired_access,
DWORD share_mode,
DWORD creation_disposition,
DWORD attribute_flags,
DOKAN_FILE_INFO *file_info );
#else
NTSTATUS __stdcall mount_dokan_ZwCreateFile(
const wchar_t *path,
DOKAN_IO_SECURITY_CONTEXT *security_context,
ACCESS_MASK desired_access,
ULONG file_attributes,
ULONG share_access,
ULONG creation_disposition,
ULONG creation_options,
DOKAN_FILE_INFO *file_info );
#endif

#if ( DOKAN_VERSION >= 600 ) && ( DOKAN_VERSION < 800 )
int __stdcall mount_dokan_OpenDirectory(
const wchar_t *path,
DOKAN_FILE_INFO *file_info );
#endif

#if ( DOKAN_VERSION >= 600 ) && ( DOKAN_VERSION < 800 )
int __stdcall mount_dokan_CloseFile(
const wchar_t *path,
DOKAN_FILE_INFO *file_info );
#else
NTSTATUS __stdcall mount_dokan_CloseFile(
const wchar_t *path,
DOKAN_FILE_INFO *file_info );
#endif

#if ( DOKAN_VERSION >= 600 ) && ( DOKAN_VERSION < 800 )
int __stdcall mount_dokan_ReadFile(
const wchar_t *path,
void *buffer,
DWORD number_of_bytes_to_read,
DWORD *number_of_bytes_read,
LONGLONG offset,
DOKAN_FILE_INFO *file_info );
#else
NTSTATUS __stdcall mount_dokan_ReadFile(
const wchar_t *path,
void *buffer,
DWORD number_of_bytes_to_read,
DWORD *number_of_bytes_read,
LONGLONG offset,
DOKAN_FILE_INFO *file_info );
#endif

#if ( DOKAN_VERSION >= 600 ) && ( DOKAN_VERSION < 800 )
int __stdcall mount_dokan_FindFiles(
const wchar_t *path,
PFillFindData fill_find_data,
DOKAN_FILE_INFO *file_info );
#else
NTSTATUS __stdcall mount_dokan_FindFiles(
const wchar_t *path,
PFillFindData fill_find_data,
DOKAN_FILE_INFO *file_info );
#endif

#if ( DOKAN_VERSION >= 600 ) && ( DOKAN_VERSION < 800 )
int __stdcall mount_dokan_GetFileInformation(
const wchar_t *path,
BY_HANDLE_FILE_INFORMATION *file_information,
DOKAN_FILE_INFO *file_info );
#else
NTSTATUS __stdcall mount_dokan_GetFileInformation(
const wchar_t *path,
BY_HANDLE_FILE_INFORMATION *file_information,
DOKAN_FILE_INFO *file_info );
#endif

#if ( DOKAN_VERSION >= 600 ) && ( DOKAN_VERSION < 800 )
int __stdcall mount_dokan_GetVolumeInformation(
wchar_t *volume_name,
DWORD volume_name_size,
Expand All @@ -111,44 +154,7 @@ int __stdcall mount_dokan_GetVolumeInformation(
wchar_t *file_system_name,
DWORD file_system_name_size,
DOKAN_FILE_INFO *file_info );

int __stdcall mount_dokan_Unmount(
DOKAN_FILE_INFO *file_info );

#else

NTSTATUS __stdcall mount_dokan_ZwCreateFile(
const wchar_t *path,
DOKAN_IO_SECURITY_CONTEXT *security_context,
ACCESS_MASK desired_access,
ULONG file_attributes,
ULONG share_access,
ULONG creation_disposition,
ULONG creation_options,
DOKAN_FILE_INFO *file_info );

NTSTATUS __stdcall mount_dokan_CloseFile(
const wchar_t *path,
DOKAN_FILE_INFO *file_info );

NTSTATUS __stdcall mount_dokan_ReadFile(
const wchar_t *path,
void *buffer,
DWORD number_of_bytes_to_read,
DWORD *number_of_bytes_read,
LONGLONG offset,
DOKAN_FILE_INFO *file_info );

NTSTATUS __stdcall mount_dokan_FindFiles(
const wchar_t *path,
PFillFindData fill_find_data,
DOKAN_FILE_INFO *file_info );

NTSTATUS __stdcall mount_dokan_GetFileInformation(
const wchar_t *path,
BY_HANDLE_FILE_INFORMATION *file_information,
DOKAN_FILE_INFO *file_info );

NTSTATUS __stdcall mount_dokan_GetVolumeInformation(
wchar_t *volume_name,
DWORD volume_name_size,
Expand All @@ -158,8 +164,12 @@ NTSTATUS __stdcall mount_dokan_GetVolumeInformation(
wchar_t *file_system_name,
DWORD file_system_name_size,
DOKAN_FILE_INFO *file_info );
#endif

#endif /* ( DOKAN_VERSION >= 600 ) && ( DOKAN_VERSION < 800 ) */
#if ( DOKAN_VERSION >= 600 ) && ( DOKAN_VERSION < 800 )
int __stdcall mount_dokan_Unmount(
DOKAN_FILE_INFO *file_info );
#endif

#endif /* defined( HAVE_LIBDOKAN ) */

Expand Down
2 changes: 1 addition & 1 deletion smrawtools/mount_file_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ int mount_file_entry_get_number_of_sub_file_entries(
return( -1 );
}
if( ( number_of_handles < 0 )
|| ( number_of_handles > 99 ) )
|| ( number_of_handles > 999 ) )
{
libcerror_error_set(
error,
Expand Down
38 changes: 36 additions & 2 deletions smrawtools/mount_fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

extern mount_handle_t *smrawmount_mount_handle;

#if defined( HAVE_LIBFUSE ) || defined( HAVE_LIBOSXFUSE )
#if defined( HAVE_LIBFUSE ) || defined( HAVE_LIBFUSE3 ) || defined( HAVE_LIBOSXFUSE )

#if ( SIZEOF_OFF_T != 8 ) && ( SIZEOF_OFF_T != 4 )
#error Size of off_t not supported
Expand Down Expand Up @@ -255,11 +255,20 @@ int mount_fuse_filldir(

return( -1 );
}
#if defined( HAVE_LIBFUSE3 )
if( filler(
buffer,
name,
stat_info,
0,
0 ) == 1 )
#else
if( filler(
buffer,
name,
stat_info,
0 ) == 1 )
#endif
{
libcerror_error_set(
error,
Expand Down Expand Up @@ -655,12 +664,22 @@ int mount_fuse_opendir(
/* Reads a directory
* Returns 0 if successful or a negative errno value otherwise
*/
#if defined( HAVE_LIBFUSE3 )
int mount_fuse_readdir(
const char *path,
void *buffer,
fuse_fill_dir_t filler,
off_t offset SMRAWTOOLS_ATTRIBUTE_UNUSED,
struct fuse_file_info *file_info SMRAWTOOLS_ATTRIBUTE_UNUSED,
enum fuse_readdir_flags flags SMRAWTOOLS_ATTRIBUTE_UNUSED )
#else
int mount_fuse_readdir(
const char *path,
void *buffer,
fuse_fill_dir_t filler,
off_t offset SMRAWTOOLS_ATTRIBUTE_UNUSED,
struct fuse_file_info *file_info SMRAWTOOLS_ATTRIBUTE_UNUSED )
#endif
{
struct stat *stat_info = NULL;
libcerror_error_t *error = NULL;
Expand All @@ -675,6 +694,10 @@ int mount_fuse_readdir(

SMRAWTOOLS_UNREFERENCED_PARAMETER( offset )

#if defined( HAVE_LIBFUSE3 )
SMRAWTOOLS_UNREFERENCED_PARAMETER( flags )
#endif

#if defined( HAVE_DEBUG_OUTPUT )
if( libcnotify_verbose != 0 )
{
Expand Down Expand Up @@ -1044,9 +1067,16 @@ int mount_fuse_releasedir(
/* Retrieves the file stat info
* Returns 0 if successful or a negative errno value otherwise
*/
#if defined( HAVE_LIBFUSE3 )
int mount_fuse_getattr(
const char *path,
struct stat *stat_info,
struct fuse_file_info *file_info SMRAWTOOLS_ATTRIBUTE_UNUSED )
#else
int mount_fuse_getattr(
const char *path,
struct stat *stat_info )
#endif
{
libcerror_error_t *error = NULL;
mount_file_entry_t *file_entry = NULL;
Expand All @@ -1058,6 +1088,10 @@ int mount_fuse_getattr(
uint16_t file_mode = 0;
int result = 0;

#if defined( HAVE_LIBFUSE3 )
SMRAWTOOLS_UNREFERENCED_PARAMETER( file_info )
#endif

#if defined( HAVE_DEBUG_OUTPUT )
if( libcnotify_verbose != 0 )
{
Expand Down Expand Up @@ -1314,5 +1348,5 @@ void mount_fuse_destroy(
return;
}

#endif /* defined( HAVE_LIBFUSE ) || defined( HAVE_LIBOSXFUSE ) */
#endif /* defined( HAVE_LIBFUSE ) || defined( HAVE_LIBFUSE3 ) || defined( HAVE_LIBOSXFUSE ) */

Loading

0 comments on commit 07deb70

Please sign in to comment.