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 Apr 13, 2024
1 parent 99cc66b commit e71dedd
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 51 deletions.
38 changes: 38 additions & 0 deletions bdetools/bdemount.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,16 @@ int main( int argc, char * const argv[] )
#if defined( HAVE_LIBFUSE ) || defined( HAVE_LIBOSXFUSE )
struct fuse_operations bdemount_fuse_operations;

#if FUSE_USE_VERSION >= 30
/* 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 bdemount_fuse_arguments = FUSE_ARGS_INIT(1, fuse_argv);
#else
struct fuse_args bdemount_fuse_arguments = FUSE_ARGS_INIT(0, NULL);
struct fuse_chan *bdemount_fuse_channel = NULL;
#endif
struct fuse *bdemount_fuse_handle = NULL;

#elif defined( HAVE_LIBDOKAN )
Expand Down Expand Up @@ -483,6 +491,34 @@ int main( int argc, char * const argv[] )
bdemount_fuse_operations.getattr = &mount_fuse_getattr;
bdemount_fuse_operations.destroy = &mount_fuse_destroy;

#if FUSE_USE_VERSION >= 30
bdemount_fuse_handle = fuse_new(
&bdemount_fuse_arguments,
&bdemount_fuse_operations,
sizeof( struct fuse_operations ),
bdemount_mount_handle );

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

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

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

goto on_error;
}
#else
bdemount_fuse_channel = fuse_mount(
mount_point,
&bdemount_fuse_arguments );
Expand Down Expand Up @@ -510,6 +546,8 @@ int main( int argc, char * const argv[] )

goto on_error;
}
#endif /* FUSE_USE_VERSION >= 30 */

if( verbose == 0 )
{
if( fuse_daemonize(
Expand Down
34 changes: 34 additions & 0 deletions bdetools/mount_fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,20 @@ int mount_fuse_filldir(

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

BDETOOLS_UNREFERENCED_PARAMETER( offset )

#if FUSE_USE_VERSION >= 30
BDETOOLS_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 FUSE_USE_VERSION >= 30
int mount_fuse_getattr(
const char *path,
struct stat *stat_info,
struct fuse_file_info *file_info BDETOOLS_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 FUSE_USE_VERSION >= 30
BDETOOLS_UNREFERENCED_PARAMETER( file_info )
#endif

#if defined( HAVE_DEBUG_OUTPUT )
if( libcnotify_verbose != 0 )
{
Expand Down
26 changes: 22 additions & 4 deletions bdetools/mount_fuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@
#include <common.h>
#include <types.h>

#if defined( HAVE_LIBFUSE ) || defined( HAVE_LIBOSXFUSE )
/* Ensure FUSE_USE_VERSION is defined before including fuse.h
*/
#if !defined( FUSE_USE_VERSION )
#warning FUSE_USE_VERSION not set, defaulting to 26
#define FUSE_USE_VERSION 26
#endif

#if defined( HAVE_LIBFUSE )
#include <fuse.h>

#elif defined( HAVE_LIBOSXFUSE )
#include <osxfuse/fuse.h>
#endif

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

#include "bdetools_libbde.h"
#include "bdetools_libcerror.h"
#include "mount_file_entry.h"
Expand Down Expand Up @@ -84,20 +85,37 @@ int mount_fuse_opendir(
const char *path,
struct fuse_file_info *file_info );

#if FUSE_USE_VERSION >= 30
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 FUSE_USE_VERSION >= 30
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 );
Expand Down
2 changes: 1 addition & 1 deletion bdetools/mount_handle.c
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ int mount_handle_open(

if( bdetools_prompt_for_password(
stdout,
"Password",
_SYSTEM_STRING( "Password" ),
password,
64,
error ) != 1 )
Expand Down
4 changes: 2 additions & 2 deletions libbde/libbde_metadata_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,14 @@ int libbde_metadata_entry_read_string(

return( 1 );

on_error:
#if defined( HAVE_DEBUG_OUTPUT )
on_error:
if( value_string != NULL )
{
memory_free(
value_string );
}
#endif
return( -1 );
#endif
}

Loading

0 comments on commit e71dedd

Please sign in to comment.