Compare commits

...

2 Commits

Author SHA1 Message Date
Matéo Duparc 267fb40fe7
Clean JNI library 2022-06-25 21:32:28 +02:00
Matéo Duparc f03d39433c
Cleaning 2022-06-25 16:57:50 +02:00
15 changed files with 35 additions and 159 deletions

View File

@ -7,20 +7,6 @@ cmake_policy(SET CMP0065 OLD)
# - try if setting CRYPTOPP_NATIVE_ARCH=ON and adding -march=native to the compile commands for cryfs source files makes a difference
# -> if yes, offer a cmake option to enable both of these
#set(ANDROID_ABI arm64-v8a)
#set(ANDROID_NDK /ndk/23.1.7779620/)
#set(ANDROID_PLATFORM android-21)
#set(ANDROID_TOOLCHAIN clang)
#
#set(CMAKE_SYSTEM_NAME Android)
#set(CMAKE_SYSTEM_VERSION 21)
#set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
#set(CMAKE_ANDROID_NDK ${ANDROID_NDK})
#set(CMAKE_ANDROID_STL_TYPE c++_static)
#
#set(CMAKE_TOOLCHAIN_FILE ${CMAKE_ANDROID_NDK}/build/cmake/android.toolchain.cmake)
#set(ANDROID TRUE) # Current toolchain file doesn't set this variable which is needed by spdlog
project(cryfs)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake-utils)
@ -56,7 +42,5 @@ if(MSVC)
add_definitions(/bigobj)
endif()
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_subdirectory(vendor EXCLUDE_FROM_ALL)
add_subdirectory(src)

View File

@ -1,11 +0,0 @@
image:
- Visual Studio 2019
platform:
- x64
configuration:
- Release
build_script:
- cmd: echo Appveyor CI is disabled since we now have Github Actions

View File

@ -1,10 +0,0 @@
#!/usr/bin/env bash
TAG=$1
GPGHOMEDIR=$2
git archive --format=tgz "$1" > "cryfs-$1.tar.gz"
gpg --homedir "$GPGHOMEDIR" --armor --detach-sign "cryfs-$1.tar.gz"
git archive --format=tar "$1" | xz -9 > "cryfs-$1.tar.xz"
gpg --homedir "$GPGHOMEDIR" --armor --detach-sign "cryfs-$1.tar.xz"

View File

@ -1,46 +0,0 @@
from conans import ConanFile, CMake
class CryFSConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
requires = [
"range-v3/0.11.0",
"spdlog/1.8.5",
"boost/1.75.0",
]
generators = "cmake"
default_options = {
"boost:system_no_deprecated": True,
"boost:asio_no_deprecated": True,
"boost:filesystem_no_deprecated": True,
"boost:without_atomic": False, # needed by boost thread
"boost:without_chrono": False, # needed by CryFS
"boost:without_container": False, # needed by boost thread
"boost:without_context": True,
"boost:without_contract": True,
"boost:without_coroutine": True,
"boost:without_date_time": False, # needed by boost thread
"boost:without_exception": False, # needed by boost thread
"boost:without_fiber": True,
"boost:without_filesystem": False, # needed by CryFS
"boost:without_graph": True,
"boost:without_graph_parallel": True,
"boost:without_iostreams": True,
"boost:without_json": True,
"boost:without_locale": True,
"boost:without_log": True,
"boost:without_math": True,
"boost:without_mpi": True,
"boost:without_nowide": True,
"boost:without_program_options": False, # needed by CryFS
"boost:without_python": True,
"boost:without_random": True,
"boost:without_regex": True,
"boost:without_serialization": False, # needed by boost date_time
"boost:without_stacktrace": True,
"boost:without_system": False, # needed by CryFS
"boost:without_test": True,
"boost:without_thread": False, # needed by CryFS
"boost:without_timer": True,
"boost:without_type_erasure": True,
"boost:without_wave": True,
}

View File

@ -1,26 +0,0 @@
#!/bin/bash
# Note: Call this from a cmake build directory (e.g. cmake/) for out-of-source builds
# Examples:
# mkdir cmake && cd cmake && ../run-clang-tidy.sh
# mkdir cmake && cd cmake && ../run-clang-tidy.sh -fix
# mkdir cmake && cd cmake && ../run-clang-tidy.sh -export-fixes fixes.yaml
set -e
CXX=clang++-11
CC=clang-11
SCRIPT=run-clang-tidy-11.py
export NUMCORES=`nproc` && if [ ! -n "$NUMCORES" ]; then export NUMCORES=`sysctl -n hw.ncpu`; fi
echo Using ${NUMCORES} cores
# Run cmake in current working directory, but on source that is in the same directory as this script file
cmake -DBUILD_TESTING=on -DCMAKE_CXX_COMPILER=${CXX} -DCMAKE_C_COMPILER=${CC} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON "${0%/*}"
# Filter all third party code from the compilation database
cat compile_commands.json|jq "map(select(.file | test(\"^$(realpath ${0%/*})/(src|test)/.*$\")))" > compile_commands2.json
rm compile_commands.json
mv compile_commands2.json compile_commands.json
${SCRIPT} -j${NUMCORES} -quiet -header-filter "$(realpath ${0%/*})/(src|test)/.*" $@

View File

@ -1,33 +0,0 @@
#!/bin/bash
# Note: Call this from a cmake build directory (e.g. cmake/) for out-of-source builds
# Examples:
# mkdir cmake && cd cmake && ../run-iwqu.sh
# mkdir cmake && cd cmake && ../run-iwqu.sh -fix
set -e
export NUMCORES=`nproc` && if [ ! -n "$NUMCORES" ]; then export NUMCORES=`sysctl -n hw.ncpu`; fi
echo Using ${NUMCORES} cores
# Run cmake in current working directory, but on source that is in the same directory as this script file
cmake -DBUILD_TESTING=on -DCMAKE_EXPORT_COMPILE_COMMANDS=ON "${0%/*}"
# Filter all third party code from the compilation database
cat compile_commands.json|jq "map(select(.file | test(\"^$(realpath ${0%/*})/(src|test)/.*$\")))" > compile_commands2.json
rm compile_commands.json
mv compile_commands2.json compile_commands.json
if [ "$1" = "-fix" ]; then
TMPFILE=/tmp/iwyu.`cat /dev/urandom | tr -cd 'a-f0-9' | head -c 8`.out
function cleanup {
rm ${TMPFILE}
}
trap cleanup EXIT
iwyu_tool -j${NUMCORES} -p. ${@:2} | tee ${TMPFILE}
fix_include < ${TMPFILE}
else
iwyu_tool -j${NUMCORES} -p. $@
fi

View File

@ -3,6 +3,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_subdirectory(gitversion)
add_subdirectory(cpp-utils)
add_subdirectory(fspp)
add_subdirectory(jni)
add_subdirectory(parallelaccessstore)
add_subdirectory(blockstore)
add_subdirectory(blobstore)

View File

@ -72,7 +72,6 @@ else()
endif()
endif()
add_dependencies(${PROJECT_NAME} spdlog)
find_package(Threads REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC ${CMAKE_THREAD_LIBS_INIT})

View File

@ -11,7 +11,7 @@ namespace bf = boost::filesystem;
ProgramOptions::ProgramOptions(bf::path baseDir, optional<bf::path> configFile,
boost::filesystem::path localStateDir,
bool allowFilesystemUpgrade, bool allowReplacedFilesystem,
bool allowFilesystemUpgrade, bool allowReplacedFilesystem,
bool createMissingBasedir,
optional<string> cipher,
optional<uint32_t> blocksizeBytes,

View File

@ -4,7 +4,6 @@ set(SOURCES
../impl/FilesystemImpl.cpp
../impl/Profiler.cpp
../fuse/Fuse.cpp
jni.cpp
)
add_library(${PROJECT_NAME} STATIC ${SOURCES})
@ -35,9 +34,6 @@ if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
install(FILES "${DOKAN_LIB_PATH}/dokan1.dll" "${DOKAN_LIB_PATH}/dokanfuse1.dll"
DESTINATION "${CMAKE_INSTALL_BINDIR}"
)
else() # Linux and macOS
find_package(PkgConfig REQUIRED)
endif()
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")

View File

@ -56,7 +56,7 @@ public:
}
// Remove the following line, if you don't want to output each fuse operation on the console
#define FSPP_LOG 1
//#define FSPP_LOG 1
Fuse::~Fuse() {
for(char *arg : _argv) {
@ -67,7 +67,7 @@ Fuse::~Fuse() {
}
Fuse::Fuse(std::function<shared_ptr<Filesystem> ()> init, std::string fstype, boost::optional<std::string> fsname)
:_init(std::move(init)), _fs(make_shared<InvalidFilesystem>()), _mountdir(), _running(false), _fstype(std::move(fstype)), _fsname(std::move(fsname)) {
:_init(std::move(init)), _fs(make_shared<InvalidFilesystem>()), _running(false), _fstype(std::move(fstype)), _fsname(std::move(fsname)) {
ASSERT(static_cast<bool>(_init), "Invalid init given");
}

View File

@ -28,13 +28,9 @@ public:
explicit Fuse(std::function<std::shared_ptr<Filesystem> ()> init, std::string fstype, boost::optional<std::string> fsname);
~Fuse();
void runInBackground(const boost::filesystem::path &mountdir, std::vector<std::string> fuseOptions);
void runInForeground(const boost::filesystem::path &mountdir, std::vector<std::string> fuseOptions);
bool running() const;
void stop();
static void unmount(const boost::filesystem::path &mountdir, bool force = false);
int getattr(const boost::filesystem::path &path, fspp::fuse::STAT *stbuf);
int fgetattr(const boost::filesystem::path &path, fspp::fuse::STAT *stbuf, uint64_t fh);
int readlink(const boost::filesystem::path &path, char *buf, size_t size);
@ -68,16 +64,13 @@ private:
static void _logUnknownException();
static char *_create_c_string(const std::string &str);
static void _removeAndWarnIfExists(std::vector<std::string> *fuseOptions, const std::string &option);
void _run(const boost::filesystem::path &mountdir, std::vector<std::string> fuseOptions);
static bool _has_option(const std::vector<char *> &vec, const std::string &key);
static bool _has_entry_with_prefix(const std::string &prefix, const std::vector<char *> &vec);
std::vector<char *> _build_argv(const boost::filesystem::path &mountdir, const std::vector<std::string> &fuseOptions);
void _add_fuse_option_if_not_exists(std::vector<char *> *argv, const std::string &key, const std::string &value);
void _createContext(const std::vector<std::string> &fuseOptions);
std::function<std::shared_ptr<Filesystem> ()> _init;
std::shared_ptr<Filesystem> _fs;
boost::filesystem::path _mountdir;
std::vector<char*> _argv;
std::atomic<bool> _running;
std::string _fstype;

12
src/jni/CMakeLists.txt Normal file
View File

@ -0,0 +1,12 @@
project (libcryfs-jni)
add_library(${PROJECT_NAME} STATIC libcryfs-jni.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC fspp-fuse)
target_enable_style_warnings(${PROJECT_NAME})
target_activate_cpp14(${PROJECT_NAME})
set_target_properties(${PROJECT_NAME} PROPERTIES PUBLIC_HEADER include/libcryfs-jni.h)
target_include_directories(${PROJECT_NAME} PUBLIC include)

View File

@ -0,0 +1,17 @@
#include <jni.h>
jlong cryfs_init(JNIEnv* env, jstring jbaseDir, jstring jlocalSateDir, jbyteArray jpassword, jboolean createBaseDir, jstring jcipher);
jlong cryfs_create(JNIEnv* env, jlong fusePtr, jstring jpath, mode_t mode);
jlong cryfs_open(JNIEnv* env, jlong fusePtr, jstring jpath, jint flags);
jint cryfs_read(JNIEnv* env, jlong fusePtr, jlong fileHandle, jbyteArray jbuffer, jlong offset);
jint cryfs_write(JNIEnv* env, jlong fusePtr, jlong fileHandle, jlong offset, jbyteArray jbuffer, jint size);
jint cryfs_truncate(JNIEnv* env, jlong fusePtr, jstring jpath, jlong size);
jint cryfs_unlink(JNIEnv* env, jlong fusePtr, jstring jpath);
jint cryfs_release(jlong fusePtr, jlong fileHandle);
jlong cryfs_readdir(JNIEnv* env, jlong fusePtr, jstring jpath ,void* data, int(void*, const char*, const struct stat*));
jint cryfs_mkdir(JNIEnv* env, jlong fusePtr, jstring jpath, mode_t mode);
jint cryfs_rmdir(JNIEnv* env, jlong fusePtr, jstring jpath);
jint cryfs_getattr(JNIEnv* env, jlong fusePtr, jstring jpath, struct stat* stat);
jint cryfs_rename(JNIEnv* env, jlong fusePtr, jstring jsrcPath, jstring jdstPath);
void cryfs_destroy(jlong fusePtr);
jboolean cryfs_is_closed(jlong fusePtr);

View File

@ -1,6 +1,6 @@
#include <jni.h>
#include <cryfs-cli/Cli.h>
#include "Fuse.h"
#include <fspp/fuse/Fuse.h>
using std::unique_ptr;
using std::make_unique;
@ -141,7 +141,7 @@ extern "C" jint cryfs_readdir(JNIEnv* env, jlong fusePtr, jstring jpath, void* d
helper.path = boost::filesystem::path(path);
helper.data = data;
helper.filler = filler;
int result = fuse->readdir(path, &helper, readDir);
env->ReleaseStringUTFChars(jpath, path);