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 12, 2024
1 parent 99cc66b commit ba0ad4e
Show file tree
Hide file tree
Showing 6 changed files with 159 additions and 19 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
}

74 changes: 62 additions & 12 deletions m4/libfuse.m4
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dnl Checks for libfuse required headers and functions
dnl
dnl Version: 20220118
dnl Version: 20240412

dnl Function to detect if libfuse is available
dnl ac_libfuse_dummy is used to prevent AC_CHECK_LIB adding unnecessary -l<library> arguments
Expand All @@ -22,31 +22,59 @@ AC_DEFUN([AX_LIBFUSE_CHECK_LIB],
[dnl Check for a pkg-config file
AS_IF(
[test "x$cross_compiling" != "xyes" && test "x$PKGCONFIG" != "x"],
[PKG_CHECK_MODULES(
[fuse3],
[fuse3 >= 3.0],
[ac_cv_libfuse=libfuse3],
[ac_cv_libfuse=no])
])
AS_IF(
[test "x$cross_compiling" != "xyes" && test "x$PKGCONFIG" != "x" && test "x$ac_cv_libfuse" = xno],
[PKG_CHECK_MODULES(
[fuse],
[fuse >= 2.6],
[ac_cv_libfuse=libfuse],
[ac_cv_libfuse=no])
])
AS_IF(
[test "x$ac_cv_libfuse" = xlibfuse3],
[dnl libfuse3 requires -D_FILE_OFFSET_BITS=64 to be set
CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=30"
ac_cv_libfuse_CPPFLAGS="$pkg_cv_fuse3_CFLAGS"
ac_cv_libfuse_LIBADD="$pkg_cv_fuse3_LIBS"])
AS_IF(
[test "x$ac_cv_libfuse" = xlibfuse],
[ac_cv_libfuse_CPPFLAGS="$pkg_cv_fuse_CFLAGS"
ac_cv_libfuse_LIBADD="$pkg_cv_fuse_LIBS"],
ac_cv_libfuse_LIBADD="$pkg_cv_fuse_LIBS"])
dnl Check for libfuse and libfuse3
AS_IF(
[test "x$ac_cv_libfuse" != xlibfuse && test "x$ac_cv_libfuse" != xlibfuse3],
[dnl Check for headers
AC_CHECK_HEADERS(
[fuse.h],
[ac_cv_header_fuse_h=yes],
[ac_cv_header_fuse_h=no])
dnl libfuse sometimes requires -D_FILE_OFFSET_BITS=64 to be set
dnl macFuse requires -DFUSE_USE_VERSION=26 to be set
AS_IF(
[test "x$ac_cv_header_fuse_h" = xno],
[AS_UNSET([ac_cv_header_fuse_h])
CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=26"
[test "x$ac_cv_libfuse" = xlibfuse3],
[dnl libfuse3 requires -D_FILE_OFFSET_BITS=64 to be set
CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64 -DFUSE_USE_VERSION=30"
AC_CHECK_HEADERS([fuse.h])
])
])
AS_IF(
[test "x$ac_cv_libfuse" = xlibfuse],
[CPPFLAGS="$CPPFLAGS -DFUSE_USE_VERSION=26"
AC_CHECK_HEADERS([fuse.h])
dnl libfuse sometimes requires -D_FILE_OFFSET_BITS=64 to be set
AS_IF(
[test "x$ac_cv_header_fuse_h" = xno],
[AS_UNSET([ac_cv_header_fuse_h])
CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
AC_CHECK_HEADERS([fuse.h])
])
])
AS_IF(
[test "x$ac_cv_header_fuse_h" = xno],
Expand Down Expand Up @@ -132,6 +160,13 @@ AC_DEFUN([AX_LIBFUSE_CHECK_LIB],
[1],
[Define to 1 if you have the 'fuse' library (-lfuse).])
])
AS_IF(
[test "x$ac_cv_libfuse" = xlibfuse3],
[AC_DEFINE(
[HAVE_LIBFUSE],
[1],
[Define to 1 if you have the 'fuse3' library (-lfuse3).])
])
AS_IF(
[test "x$ac_cv_libfuse" = xlibosxfuse],
[AC_DEFINE(
Expand Down Expand Up @@ -182,6 +217,12 @@ AC_DEFUN([AX_LIBFUSE_CHECK_ENABLE],
[ax_libfuse_pc_libs_private],
[-lfuse])
])
AS_IF(
[test "x$ac_cv_libfuse" = xlibfuse3],
[AC_SUBST(
[ax_libfuse_pc_libs_private],
[-lfuse3])
])
AS_IF(
[test "x$ac_cv_libfuse" = xlibosxfuse],
[AC_SUBST(
Expand All @@ -198,5 +239,14 @@ AC_DEFUN([AX_LIBFUSE_CHECK_ENABLE],
[ax_libfuse_spec_build_requires],
[fuse-devel])
])
AS_IF(
[test "x$ac_cv_libfuse" = xlibfuse3],
[AC_SUBST(
[ax_libfuse_spec_requires],
[fuse3-libs])
AC_SUBST(
[ax_libfuse_spec_build_requires],
[fuse3-devel])
])
])

0 comments on commit ba0ad4e

Please sign in to comment.