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 23, 2024
1 parent 970b539 commit b21bd62
Show file tree
Hide file tree
Showing 10 changed files with 472 additions and 297 deletions.
22 changes: 14 additions & 8 deletions fvdetools/fvdeinfo.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Shows information obtained from a FileVault Drive Encryption (FVDE) encrypted volume
* Shows information obtained from a FileVault Drive Encryption (FVDE) encrypted volume.
*
* Copyright (C) 2011-2024, Omar Choudary <[email protected]>
* Joachim Metz <[email protected]>
Expand All @@ -26,14 +26,20 @@
#include <system_string.h>
#include <types.h>

#if defined( HAVE_UNISTD_H )
#include <unistd.h>
#include <stdio.h>

#if defined( HAVE_IO_H ) || defined( WINAPI )
#include <io.h>
#endif

#if defined( HAVE_STDLIB_H ) || defined( WINAPI )
#include <stdlib.h>
#endif

#if defined( HAVE_UNISTD_H )
#include <unistd.h>
#endif

#include "fvdetools_getopt.h"
#include "fvdetools_i18n.h"
#include "fvdetools_input.h"
Expand All @@ -49,7 +55,7 @@
info_handle_t *fvdeinfo_info_handle = NULL;
int fvdeinfo_abort = 0;

/* Prints the executable usage information
/* Prints usage information
*/
void usage_fprint(
FILE *stream )
Expand Down Expand Up @@ -150,7 +156,7 @@ int main( int argc, char * const argv[] )
1 );

if( libclocale_initialize(
"fvdetools",
"fvdetools",
&error ) != 1 )
{
fprintf(
Expand All @@ -159,9 +165,9 @@ int main( int argc, char * const argv[] )

goto on_error;
}
if( fvdetools_output_initialize(
_IONBF,
&error ) != 1 )
if( fvdetools_output_initialize(
_IONBF,
&error ) != 1 )
{
fprintf(
stderr,
Expand Down
64 changes: 56 additions & 8 deletions fvdetools/fvdemount.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Mounts a FileVault Drive Encrypted (FVDE) volume
* Mounts a FileVault Drive Encrypted (FVDE) volume.
*
* Copyright (C) 2011-2024, Omar Choudary <[email protected]>,
* Joachim Metz <[email protected]>
Expand Down Expand Up @@ -158,11 +158,19 @@ int main( int argc, char * const argv[] )
int unattended_mode = 0;
int verbose = 0;

#if defined( HAVE_LIBFUSE ) || defined( HAVE_LIBOSXFUSE )
#if defined( HAVE_LIBFUSE ) || defined( HAVE_LIBFUSE3 ) || defined( HAVE_LIBOSXFUSE )
struct fuse_operations fvdemount_fuse_operations;

#if defined( HAVE_LIBFUSE3 )
/* Need to set this to 1 even if there no arguments, otherwise this causes
* fuse: empty argv passed to fuse_session_new()
*/
char *fuse_argv[ 2 ] = { program, NULL };
struct fuse_args fvdemount_fuse_arguments = FUSE_ARGS_INIT(1, fuse_argv);
#else
struct fuse_args fvdemount_fuse_arguments = FUSE_ARGS_INIT(0, NULL);
struct fuse_chan *fvdemount_fuse_channel = NULL;
#endif
struct fuse *fvdemount_fuse_handle = NULL;

#elif defined( HAVE_LIBDOKAN )
Expand Down Expand Up @@ -421,7 +429,7 @@ int main( int argc, char * const argv[] )

goto on_error;
}
#if defined( HAVE_LIBFUSE ) || defined( HAVE_LIBOSXFUSE )
#if defined( HAVE_LIBFUSE ) || defined( HAVE_LIBFUSE3 ) || defined( HAVE_LIBOSXFUSE )
if( option_extended_options != NULL )
{
/* This argument is required but ignored
Expand Down Expand Up @@ -477,6 +485,34 @@ int main( int argc, char * const argv[] )
fvdemount_fuse_operations.getattr = &mount_fuse_getattr;
fvdemount_fuse_operations.destroy = &mount_fuse_destroy;

#if defined( HAVE_LIBFUSE3 )
fvdemount_fuse_handle = fuse_new(
&fvdemount_fuse_arguments,
&fvdemount_fuse_operations,
sizeof( struct fuse_operations ),
fvdemount_mount_handle );

if( fvdemount_fuse_handle == NULL )
{
fprintf(
stderr,
"Unable to create fuse handle.\n" );

goto on_error;
}
result = fuse_mount(
fvdemount_fuse_handle,
mount_point );

if( result != 0 )
{
fprintf(
stderr,
"Unable to fuse mount file system.\n" );

goto on_error;
}
#else
fvdemount_fuse_channel = fuse_mount(
mount_point,
&fvdemount_fuse_arguments );
Expand Down Expand Up @@ -504,6 +540,8 @@ int main( int argc, char * const argv[] )

goto on_error;
}
#endif /* defined( HAVE_LIBFUSE3 ) */

if( verbose == 0 )
{
if( fuse_daemonize(
Expand Down Expand Up @@ -558,10 +596,14 @@ int main( int argc, char * const argv[] )

goto on_error;
}
fvdemount_dokan_options.Version = DOKAN_VERSION;
fvdemount_dokan_options.ThreadCount = 0;
fvdemount_dokan_options.MountPoint = mount_point;
fvdemount_dokan_options.Version = DOKAN_VERSION;
fvdemount_dokan_options.MountPoint = mount_point;

#if DOKAN_MINIMUM_COMPATIBLE_VERSION >= 200
fvdemount_dokan_options.SingleThread = TRUE;
#else
fvdemount_dokan_options.ThreadCount = 0;
#endif
if( verbose != 0 )
{
fvdemount_dokan_options.Options |= DOKAN_OPTION_STDERR;
Expand Down Expand Up @@ -631,10 +673,16 @@ int main( int argc, char * const argv[] )

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

#if DOKAN_MINIMUM_COMPATIBLE_VERSION >= 200
DokanInit();
#endif
result = DokanMain(
&fvdemount_dokan_options,
&fvdemount_dokan_operations );

#if DOKAN_MINIMUM_COMPATIBLE_VERSION >= 200
DokanShutdown();
#endif
switch( result )
{
case DOKAN_SUCCESS:
Expand Down Expand Up @@ -692,7 +740,7 @@ int main( int argc, char * const argv[] )

return( EXIT_FAILURE );

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

on_error:
if( error != NULL )
Expand All @@ -702,7 +750,7 @@ int main( int argc, char * const argv[] )
libcerror_error_free(
&error );
}
#if defined( HAVE_LIBFUSE ) || defined( HAVE_LIBOSXFUSE )
#if defined( HAVE_LIBFUSE ) || defined( HAVE_LIBFUSE3 ) || defined( HAVE_LIBOSXFUSE )
if( fvdemount_fuse_handle != NULL )
{
fuse_destroy(
Expand Down
28 changes: 17 additions & 11 deletions fvdetools/mount_dokan.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ extern mount_handle_t *fvdemount_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 @@ -194,7 +200,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 @@ -696,7 +702,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 @@ -880,19 +886,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 @@ -1010,7 +1016,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 @@ -1048,7 +1054,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 @@ -1172,7 +1178,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
Loading

0 comments on commit b21bd62

Please sign in to comment.