Skip to content

Commit

Permalink
Memfs - Use the new mount async API
Browse files Browse the repository at this point in the history
  • Loading branch information
Liryna committed Jan 8, 2022
1 parent 97b6323 commit cea3ea6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
5 changes: 3 additions & 2 deletions samples/dokan_memfs/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ BOOL WINAPI ctrl_handler(DWORD dw_ctrl_type) {
case CTRL_LOGOFF_EVENT:
case CTRL_SHUTDOWN_EVENT:
SetConsoleCtrlHandler(ctrl_handler, FALSE);
DokanRemoveMountPoint(dokan_memfs->mount_point);
dokan_memfs->stop();
return TRUE;
default:
return FALSE;
Expand Down Expand Up @@ -115,7 +115,8 @@ int __cdecl wmain(ULONG argc, PWCHAR argv[]) {
}
DokanInit();
// Start the memory filesystem
dokan_memfs->run();
dokan_memfs->start();
dokan_memfs->wait();
DokanShutdown();
} catch (const std::exception& ex) {
spdlog::error("dokan_memfs failure: {}", ex.what());
Expand Down
12 changes: 8 additions & 4 deletions samples/dokan_memfs/memfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ THE SOFTWARE.
#include <spdlog/spdlog.h>

namespace memfs {
void memfs::run() {
void memfs::start() {
fs_filenodes = std::make_unique<::memfs::fs_filenodes>();

DOKAN_OPTIONS dokan_options;
Expand Down Expand Up @@ -69,7 +69,8 @@ void memfs::run() {
dokan_options.Timeout = timeout;
dokan_options.GlobalContext = reinterpret_cast<ULONG64>(this);

NTSTATUS status = DokanMain(&dokan_options, &memfs_operations);
NTSTATUS status =
DokanCreateFileSystem(&dokan_options, &memfs_operations, &instance);
switch (status) {
case DOKAN_SUCCESS:
break;
Expand All @@ -93,5 +94,8 @@ void memfs::run() {
}
}

memfs::~memfs() { DokanRemoveMountPoint(mount_point); }
} // namespace memfs
void memfs::wait() { DokanWaitForFileSystemClosed(instance, INFINITE); }

void memfs::stop() { DokanCloseHandle(instance); }

} // namespace memfs
8 changes: 5 additions & 3 deletions samples/dokan_memfs/memfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ class memfs {
public:
memfs() = default;
// Start the memory filesystem and block until unmount.
void run();
// Unmount the device when destructor is called.
virtual ~memfs();
void start();
void wait();
void stop();

DOKAN_HANDLE instance = nullptr;

// FileSystem mount options
WCHAR mount_point[MAX_PATH] = L"M:\\";
Expand Down

0 comments on commit cea3ea6

Please sign in to comment.