-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from CESNET/appFs
appFs - introduce appFs library
- Loading branch information
Showing
7 changed files
with
535 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Project dependencies | ||
find_package(PkgConfig REQUIRED) | ||
find_package(Threads REQUIRED) | ||
|
||
pkg_check_modules(fuse REQUIRED IMPORTED_TARGET fuse3>=3.2.1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* @file | ||
* @brief Definition of the AppFsFuse class for managing FUSE filesystem | ||
* @author Pavel Siska <siska@cesnet.cz> | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <fuse3/fuse.h> | ||
#include <memory> | ||
#include <string> | ||
#include <telemetry.hpp> | ||
#include <thread> | ||
|
||
namespace telemetry::appFs { | ||
|
||
/** | ||
* @brief The AppFsFuse class for managing FUSE filesystem. | ||
*/ | ||
class AppFsFuse { | ||
public: | ||
/** | ||
* @brief Sets up and mount the FUSE filesystem. | ||
* | ||
* This method sets up the FUSE filesystem with the provided mount point directory path. | ||
* | ||
* @param rootDirectory A shared pointer to the telemetry root directory. | ||
* @param mountPoint The mount point directory path. | ||
* @param tryToUnmountOnStart Whether to attempt unmounting the mount point if it's already | ||
* | ||
* @throws std::runtime_error if rootDirectory is nullptr. | ||
* @throws std::runtime_error if setup and mount process fails. | ||
*/ | ||
AppFsFuse( | ||
std::shared_ptr<Directory> rootDirectory, | ||
const std::string& mountPoint, | ||
bool tryToUnmountOnStart = true); | ||
|
||
/** | ||
* @brief Creates a new thread to run the FUSE event loop. | ||
* | ||
* After the thread is created, you can access the FUSE filesystem through the mount point. | ||
* | ||
* @throws std::runtime_error if the FUSE thread is already running. | ||
*/ | ||
void start(); | ||
|
||
/** | ||
* @brief Unmount the FUSE filesystem and join the FUSE thread. | ||
* | ||
* @note It's not possible to start the FUSE filesystem again after calling this method. | ||
* If needed, a new instance of the class must be created. | ||
*/ | ||
void stop(); | ||
|
||
/** | ||
* @brief Destructor for AppFsFuse. | ||
*/ | ||
~AppFsFuse(); | ||
|
||
private: | ||
void unmount(); | ||
|
||
std::unique_ptr<struct fuse, decltype(&fuse_destroy)> m_fuse {nullptr, &fuse_destroy}; | ||
std::shared_ptr<Directory> m_rootDirectory; | ||
bool m_isStarted = false; | ||
std::thread m_fuseThread; | ||
}; | ||
|
||
} // namespace telemetry::appFs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
add_subdirectory(telemetry) | ||
add_subdirectory(appFs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
list(APPEND APPFS_SOURCE_FILES | ||
appFs.cpp | ||
) | ||
|
||
if (TELEMETRY_BUILD_SHARED) | ||
add_library(appFs SHARED ${APPFS_SOURCE_FILES}) | ||
else() | ||
add_library(appFs STATIC ${APPFS_SOURCE_FILES}) | ||
endif() | ||
|
||
add_library(telemetry::appFs ALIAS appFs) | ||
|
||
target_compile_definitions(appFs PUBLIC FUSE_USE_VERSION=30 _FILE_OFFSET_BITS=64) | ||
target_link_libraries(appFs PUBLIC telemetry PkgConfig::fuse) | ||
target_include_directories(appFs PUBLIC ${CMAKE_SOURCE_DIR}/include) | ||
|
||
if (TELEMETRY_INSTALL_TARGETS) | ||
install(TARGETS appFs LIBRARY DESTINATION ${INSTALL_DIR_LIB}) | ||
install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ DESTINATION ${INSTALL_DIR_INCLUDE}) | ||
endif() |
Oops, something went wrong.