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 21, 2024
1 parent c503b7c commit 7b925d0
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 105 deletions.
24 changes: 12 additions & 12 deletions fsntfstools/fsntfsinfo.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Shows information obtained from a Windows NT File System (NTFS) volume
* Shows information obtained from a New Technology File System (NTFS) volume.
*
* Copyright (C) 2010-2024, Joachim Metz <joachim.metz@gmail.com>
*
Expand Down Expand Up @@ -33,14 +33,14 @@
#include <io.h>
#endif

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

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

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

#include "fsntfstools_getopt.h"
#include "fsntfstools_libcerror.h"
#include "fsntfstools_libclocale.h"
Expand All @@ -63,7 +63,7 @@ enum FSNTFSINFO_MODES
info_handle_t *fsntfsinfo_info_handle = NULL;
int fsntfsinfo_abort = 0;

/* Prints the executable usage information
/* Prints usage information
*/
void usage_fprint(
FILE *stream )
Expand All @@ -72,8 +72,8 @@ void usage_fprint(
{
return;
}
fprintf( stream, "Use fsntfsinfo to determine information about a Windows NT\n"
" File System (NTFS) volume.\n\n" );
fprintf( stream, "Use fsntfsinfo to determine information about a New\n"
" Technology File System (NTFS) volume.\n\n" );

fprintf( stream, "Usage: fsntfsinfo [ -B bodyfile ] [ -E mft_entry_index ] [ -F path ]\n"
" [ -o offset ] [ -dhHUvV ] source\n\n" );
Expand Down Expand Up @@ -167,7 +167,7 @@ int main( int argc, char * const argv[] )
1 );

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

goto on_error;
}
if( fsntfstools_output_initialize(
_IONBF,
&error ) != 1 )
if( fsntfstools_output_initialize(
_IONBF,
&error ) != 1 )
{
fprintf(
stderr,
Expand Down
72 changes: 60 additions & 12 deletions fsntfstools/fsntfsmount.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Mounts a Windows New Technology File System (NTFS) volume
* Mounts a New Technology File System (NTFS) volume.
*
* Copyright (C) 2010-2024, Joachim Metz <joachim.metz@gmail.com>
*
Expand Down Expand Up @@ -142,12 +142,20 @@ 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 fsntfsmount_fuse_operations;

struct fuse_args fsntfsmount_fuse_arguments = FUSE_ARGS_INIT(0, NULL);
struct fuse_chan *fsntfsmount_fuse_channel = NULL;
struct fuse *fsntfsmount_fuse_handle = NULL;
#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 fsntfsmount_fuse_arguments = FUSE_ARGS_INIT(1, fuse_argv);
#else
struct fuse_args fsntfsmount_fuse_arguments = FUSE_ARGS_INIT(0, NULL);
struct fuse_chan *fsntfsmount_fuse_channel = NULL;
#endif
struct fuse *fsntfsmount_fuse_handle = NULL;

#elif defined( HAVE_LIBDOKAN )
DOKAN_OPERATIONS fsntfsmount_dokan_operations;
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 @@ -357,6 +365,34 @@ int main( int argc, char * const argv[] )
fsntfsmount_fuse_operations.readlink = &mount_fuse_readlink;
fsntfsmount_fuse_operations.destroy = &mount_fuse_destroy;

#if defined( HAVE_LIBFUSE3 )
fsntfsmount_fuse_handle = fuse_new(
&fsntfsmount_fuse_arguments,
&fsntfsmount_fuse_operations,
sizeof( struct fuse_operations ),
fsntfsmount_mount_handle );

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

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

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

goto on_error;
}
#else
fsntfsmount_fuse_channel = fuse_mount(
mount_point,
&fsntfsmount_fuse_arguments );
Expand Down Expand Up @@ -384,6 +420,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 @@ -438,10 +476,14 @@ int main( int argc, char * const argv[] )

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

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

#if DOKAN_MINIMUM_COMPATIBLE_VERSION >= 200
DokanShutdown();
#endif
switch( result )
{
case DOKAN_SUCCESS:
Expand Down Expand Up @@ -568,11 +616,11 @@ int main( int argc, char * const argv[] )
#else
fprintf(
stderr,
"No sub system to mount FSNTFS format.\n" );
"No sub system to mount New Technology File System (NTFS) 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 @@ -582,7 +630,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( fsntfsmount_fuse_handle != NULL )
{
fuse_destroy(
Expand Down
8 changes: 4 additions & 4 deletions fsntfstools/info_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -8116,7 +8116,7 @@ int info_handle_file_entry_fprint_by_path(
{
fprintf(
info_handle->notify_stream,
"Windows NT File System information:\n\n" );
"New Technology File System information:\n\n" );

fprintf(
info_handle->notify_stream,
Expand Down Expand Up @@ -8201,7 +8201,7 @@ int info_handle_file_system_hierarchy_fprint(
{
fprintf(
info_handle->notify_stream,
"Windows NT File System information:\n\n" );
"New Technology File System information:\n\n" );

fprintf(
info_handle->notify_stream,
Expand Down Expand Up @@ -8779,7 +8779,7 @@ int info_handle_usn_change_journal_fprint(
}
fprintf(
info_handle->notify_stream,
"Windows NT File System information:\n\n" );
"New Technology File System information:\n\n" );

result = libfsntfs_volume_get_usn_change_journal(
info_handle->input_volume,
Expand Down Expand Up @@ -9010,7 +9010,7 @@ int info_handle_volume_fprint(
}
fprintf(
info_handle->notify_stream,
"Windows NT File System information:\n\n" );
"New Technology File System information:\n\n" );

fprintf(
info_handle->notify_stream,
Expand Down
28 changes: 17 additions & 11 deletions fsntfstools/mount_dokan.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ extern mount_handle_t *fsntfsmount_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
Loading

0 comments on commit 7b925d0

Please sign in to comment.