Skip to content

Commit

Permalink
Changes for fuse3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed May 20, 2024
1 parent 6f04796 commit 707ceb3
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 22 deletions.
54 changes: 46 additions & 8 deletions ewftools/ewfmount.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Mounts an Expert Witness Compression Format (EWF) image file
* Mounts an Expert Witness Compression Format (EWF) image file.
*
* Copyright (C) 2006-2024, Joachim Metz <joachim.metz@gmail.com>
*
Expand Down Expand Up @@ -158,12 +158,20 @@ int main( int argc, char * const argv[] )
ewftools_glob_t *glob = NULL;
#endif

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

struct fuse_args ewfmount_fuse_arguments = FUSE_ARGS_INIT(0, NULL);
struct fuse_chan *ewfmount_fuse_channel = NULL;
struct fuse *ewfmount_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 ewfmount_fuse_arguments = FUSE_ARGS_INIT(1, fuse_argv);
#else
struct fuse_args ewfmount_fuse_arguments = FUSE_ARGS_INIT(0, NULL);
struct fuse_chan *ewfmount_fuse_channel = NULL;
#endif
struct fuse *ewfmount_fuse_handle = NULL;

#elif defined( HAVE_LIBDOKAN )
DOKAN_OPERATIONS ewfmount_dokan_operations;
Expand Down Expand Up @@ -425,7 +433,7 @@ int main( int argc, char * const argv[] )
goto on_error;
}
#endif
#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 @@ -481,6 +489,34 @@ int main( int argc, char * const argv[] )
ewfmount_fuse_operations.getattr = &mount_fuse_getattr;
ewfmount_fuse_operations.destroy = &mount_fuse_destroy;

#if defined( HAVE_LIBFUSE3 )
ewfmount_fuse_handle = fuse_new(
&ewfmount_fuse_arguments,
&ewfmount_fuse_operations,
sizeof( struct fuse_operations ),
ewfmount_mount_handle );

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

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

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

goto on_error;
}
#else
ewfmount_fuse_channel = fuse_mount(
mount_point,
&ewfmount_fuse_arguments );
Expand Down Expand Up @@ -508,6 +544,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 @@ -706,7 +744,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 @@ -716,7 +754,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( ewfmount_fuse_handle != NULL )
{
fuse_destroy(
Expand Down
12 changes: 6 additions & 6 deletions ewftools/mount_dokan.c
Original file line number Diff line number Diff line change
Expand Up @@ -885,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
38 changes: 36 additions & 2 deletions ewftools/mount_fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

extern mount_handle_t *ewfmount_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 EWFTOOLS_ATTRIBUTE_UNUSED,
struct fuse_file_info *file_info EWFTOOLS_ATTRIBUTE_UNUSED,
enum fuse_readdir_flags flags EWFTOOLS_ATTRIBUTE_UNUSED )
#else
int mount_fuse_readdir(
const char *path,
void *buffer,
fuse_fill_dir_t filler,
off_t offset EWFTOOLS_ATTRIBUTE_UNUSED,
struct fuse_file_info *file_info EWFTOOLS_ATTRIBUTE_UNUSED )
#endif
{
struct stat *stat_info = NULL;
libcerror_error_t *error = NULL;
Expand All @@ -675,6 +694,10 @@ int mount_fuse_readdir(

EWFTOOLS_UNREFERENCED_PARAMETER( offset )

#if defined( HAVE_LIBFUSE3 )
EWFTOOLS_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 EWFTOOLS_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 )
EWFTOOLS_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 ) */

39 changes: 33 additions & 6 deletions ewftools/mount_fuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,27 @@
#include <common.h>
#include <types.h>

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

#if !defined( FUSE_USE_VERSION ) && !defined( CYGFUSE )

/* Ensure FUSE_USE_VERSION is defined before including fuse.h
*/
#if defined( HAVE_LIBFUSE3 )
#define FUSE_USE_VERSION 30
#else
#define FUSE_USE_VERSION 26
#endif

#if defined( HAVE_LIBFUSE )
#include <fuse.h>
#endif /* !defined( FUSE_USE_VERSION ) && !defined( CYGFUSE ) */

#if defined( HAVE_LIBFUSE ) || defined( HAVE_LIBFUSE3 )
#include <fuse.h>
#elif defined( HAVE_LIBOSXFUSE )
#include <osxfuse/fuse.h>
#endif

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

#include "ewftools_libcerror.h"
#include "ewftools_libewf.h"
Expand All @@ -46,7 +56,7 @@
extern "C" {
#endif

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

int mount_fuse_set_stat_info(
struct stat *stat_info,
Expand Down Expand Up @@ -84,25 +94,42 @@ int mount_fuse_opendir(
const char *path,
struct fuse_file_info *file_info );

#if defined( HAVE_LIBFUSE3 )
int mount_fuse_readdir(
const char *path,
void *buffer,
fuse_fill_dir_t filler,
off_t offset,
struct fuse_file_info *file_info,
enum fuse_readdir_flags flags );
#else
int mount_fuse_readdir(
const char *path,
void *buffer,
fuse_fill_dir_t filler,
off_t offset,
struct fuse_file_info *file_info );
#endif

int mount_fuse_releasedir(
const char *path,
struct fuse_file_info *file_info );

#if defined( HAVE_LIBFUSE3 )
int mount_fuse_getattr(
const char *path,
struct stat *stat_info,
struct fuse_file_info *file_info );
#else
int mount_fuse_getattr(
const char *path,
struct stat *stat_info );
#endif

void mount_fuse_destroy(
void *private_data );

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

#if defined( __cplusplus )
}
Expand Down

0 comments on commit 707ceb3

Please sign in to comment.