Skip to content

Commit

Permalink
Changes for Dokan support
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed May 20, 2024
1 parent f62aede commit 6268bef
Show file tree
Hide file tree
Showing 24 changed files with 2,365 additions and 983 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ stamp-h[1-9]
/tests/fsext_test_superblock
/tests/fsext_test_support
/tests/fsext_test_tools_info_handle
/tests/fsext_test_tools_mount_path_string
/tests/fsext_test_tools_output
/tests/fsext_test_tools_signal
/tests/fsext_test_volume
Expand Down
3 changes: 2 additions & 1 deletion fsexttools/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ fsextmount_SOURCES = \
mount_file_entry.c mount_file_entry.h \
mount_file_system.c mount_file_system.h \
mount_fuse.c mount_fuse.h \
mount_handle.c mount_handle.h
mount_handle.c mount_handle.h \
mount_path_string.c mount_path_string.h

fsextmount_LDADD = \
@LIBFUSE_LIBADD@ \
Expand Down
12 changes: 6 additions & 6 deletions fsexttools/fsextinfo.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Shows information obtained from an Extended File System (ext) volume
* Shows information obtained from an Extended File System (ext) volume.
*
* Copyright (C) 2010-2024, Joachim Metz <joachim.metz@gmail.com>
*
Expand Down Expand Up @@ -61,7 +61,7 @@ enum FSEXTINFO_MODES
info_handle_t *fsextinfo_info_handle = NULL;
int fsextinfo_abort = 0;

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

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

goto on_error;
}
if( fsexttools_output_initialize(
_IONBF,
&error ) != 1 )
if( fsexttools_output_initialize(
_IONBF,
&error ) != 1 )
{
fprintf(
stderr,
Expand Down
80 changes: 64 additions & 16 deletions fsexttools/fsextmount.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Mounts an Extended File System (ext) volume
* Mounts an Extended File System (ext) volume.
*
* Copyright (C) 2010-2024, Joachim Metz <joachim.metz@gmail.com>
*
Expand Down Expand Up @@ -142,11 +142,19 @@ int main( int argc, char * const argv[] )
int result = 0;
int verbose = 0;

#if defined( HAVE_LIBFUSE ) || defined( HAVE_LIBOSXFUSE )
#if defined( HAVE_LIBFUSE ) || defined( HAVE_LIBFUSE3 ) || defined( HAVE_LIBOSXFUSE )
struct fuse_operations fsextmount_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 fsextmount_fuse_arguments = FUSE_ARGS_INIT(1, fuse_argv);
#else
struct fuse_args fsextmount_fuse_arguments = FUSE_ARGS_INIT(0, NULL);
struct fuse_chan *fsextmount_fuse_channel = NULL;
#endif
struct fuse *fsextmount_fuse_handle = NULL;

#elif defined( HAVE_LIBDOKAN )
Expand Down Expand Up @@ -300,7 +308,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 @@ -359,9 +367,37 @@ int main( int argc, char * const argv[] )
fsextmount_fuse_operations.readlink = &mount_fuse_readlink;
fsextmount_fuse_operations.destroy = &mount_fuse_destroy;

#if defined( HAVE_LIBFUSE3 )
fsextmount_fuse_handle = fuse_new(
&fsextmount_fuse_arguments,
&fsextmount_fuse_operations,
sizeof( struct fuse_operations ),
fsextmount_mount_handle );

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

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

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

goto on_error;
}
#else
fsextmount_fuse_channel = fuse_mount(
mount_point,
&fsextmount_fuse_arguments );
mount_point,
&fsextmount_fuse_arguments );

if( fsextmount_fuse_channel == NULL )
{
Expand All @@ -372,11 +408,11 @@ int main( int argc, char * const argv[] )
goto on_error;
}
fsextmount_fuse_handle = fuse_new(
fsextmount_fuse_channel,
&fsextmount_fuse_arguments,
&fsextmount_fuse_operations,
sizeof( struct fuse_operations ),
fsextmount_mount_handle );
fsextmount_fuse_channel,
&fsextmount_fuse_arguments,
&fsextmount_fuse_operations,
sizeof( struct fuse_operations ),
fsextmount_mount_handle );

if( fsextmount_fuse_handle == NULL )
{
Expand All @@ -386,6 +422,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 @@ -440,10 +478,14 @@ int main( int argc, char * const argv[] )

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

#if DOKAN_MINIMUM_COMPATIBLE_VERSION >= 200
fsextmount_dokan_options.SingleThread = TRUE;
#else
fsextmount_dokan_options.ThreadCount = 0;
#endif
if( verbose != 0 )
{
fsextmount_dokan_options.Options |= DOKAN_OPTION_STDERR;
Expand Down Expand Up @@ -513,10 +555,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(
&fsextmount_dokan_options,
&fsextmount_dokan_operations );

#if DOKAN_MINIMUM_COMPATIBLE_VERSION >= 200
DokanShutdown();
#endif
switch( result )
{
case DOKAN_SUCCESS:
Expand Down Expand Up @@ -570,11 +618,11 @@ int main( int argc, char * const argv[] )
#else
fprintf(
stderr,
"No sub system to mount APFS format.\n" );
"No sub system to mount EXT format.\n" );

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 @@ -584,7 +632,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( fsextmount_fuse_handle != NULL )
{
fuse_destroy(
Expand Down
22 changes: 14 additions & 8 deletions fsexttools/mount_dokan.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ extern mount_handle_t *fsextmount_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
Loading

0 comments on commit 6268bef

Please sign in to comment.