2015-08-06 17:24:38 +00:00
|
|
|
#include "abstractions.h"
|
|
|
|
|
2016-10-17 11:50:38 +00:00
|
|
|
#ifndef _WIN32
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
int execute_command_and_wait (char* argv[]) {
|
|
|
|
// Fork our running process.
|
|
|
|
pid_t cpid = vfork();
|
|
|
|
|
|
|
|
// Check if we are the observer or the new process.
|
|
|
|
if (cpid > 0) {
|
|
|
|
int status = 0;
|
|
|
|
waitpid(cpid, &status, 0);
|
|
|
|
return WIFEXITED(status) ? WEXITSTATUS(status) : -1;
|
|
|
|
} else {
|
|
|
|
// At this point we are on our child process.
|
|
|
|
execvp(argv[0], argv);
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
// Something failed.
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2015-08-06 19:33:27 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
|
2015-08-06 17:24:38 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
2015-08-07 01:51:38 +00:00
|
|
|
void thread_create (abstr_thread_t* thread, thread_fn fn, void* data) {
|
2015-08-06 17:24:38 +00:00
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_create(thread, &attr, fn, data);
|
|
|
|
}
|
|
|
|
|
2015-08-07 01:51:38 +00:00
|
|
|
void thread_join (abstr_thread_t thread) {
|
2015-08-06 17:24:38 +00:00
|
|
|
pthread_join(thread, NULL);
|
|
|
|
}
|
|
|
|
|
2016-10-17 11:50:38 +00:00
|
|
|
int fusermount (char *path) {
|
2015-08-06 17:24:38 +00:00
|
|
|
char *argv[] = {(char *) "umount", path, NULL};
|
|
|
|
|
2016-10-17 11:50:38 +00:00
|
|
|
return execute_command_and_wait(argv);
|
2015-08-06 17:24:38 +00:00
|
|
|
}
|
|
|
|
|
2015-08-06 19:33:27 +00:00
|
|
|
#elif defined(_WIN32)
|
|
|
|
|
|
|
|
HANDLE mutex = CreateMutex(NULL, false, NULL);
|
|
|
|
|
|
|
|
void thread_create (HANDLE* thread, thread_fn fn, void* data) {
|
|
|
|
*thread = CreateThread(NULL, 0, fn, data, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void thread_join (HANDLE thread) {
|
|
|
|
WaitForSingleObject(thread, INFINITE);
|
|
|
|
}
|
|
|
|
|
2016-10-17 11:50:38 +00:00
|
|
|
int fusermount (char *path) {
|
2015-08-07 18:39:18 +00:00
|
|
|
char* dokanPath = getenv("DOKAN_INSTALL_DIR");
|
2015-08-06 22:46:14 +00:00
|
|
|
char cmdLine[MAX_PATH];
|
2015-08-07 18:39:18 +00:00
|
|
|
|
|
|
|
if(dokanPath) sprintf(cmdLine, "\"%s/dokanctl.exe\" /u %s", dokanPath, path);
|
|
|
|
else sprintf(cmdLine, "dokanctl.exe /u %s", path);
|
2015-08-06 22:46:14 +00:00
|
|
|
|
|
|
|
STARTUPINFO info = {sizeof(info)};
|
|
|
|
PROCESS_INFORMATION procInfo;
|
|
|
|
CreateProcess(NULL, cmdLine, NULL, NULL, false, CREATE_NO_WINDOW, NULL, NULL, &info, &procInfo);
|
|
|
|
|
|
|
|
WaitForSingleObject(procInfo.hProcess, INFINITE);
|
2016-10-17 11:50:38 +00:00
|
|
|
|
|
|
|
DWORD exitCode = -1;
|
|
|
|
GetExitCodeProcess(procInfo.hProcess, &exitCode);
|
|
|
|
|
2015-08-06 22:46:14 +00:00
|
|
|
CloseHandle(procInfo.hProcess);
|
|
|
|
CloseHandle(procInfo.hThread);
|
|
|
|
|
2016-10-17 11:50:38 +00:00
|
|
|
return exitCode;
|
|
|
|
|
2015-08-06 22:46:14 +00:00
|
|
|
// dokanctl.exe requires admin permissions for some reason, so if node is not run as admin,
|
|
|
|
// it'll fail to create the process for unmounting. The path will be unmounted once
|
|
|
|
// the process is killed, however, so there's that!
|
2015-08-06 19:33:27 +00:00
|
|
|
}
|
|
|
|
|
2015-08-06 17:24:38 +00:00
|
|
|
#else
|
|
|
|
|
2015-08-06 19:33:27 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
2015-08-06 17:24:38 +00:00
|
|
|
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
2015-08-07 01:51:38 +00:00
|
|
|
void thread_create (abstr_thread_t* thread, thread_fn fn, void* data) {
|
2015-08-06 17:24:38 +00:00
|
|
|
pthread_attr_t attr;
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
pthread_create(thread, &attr, fn, data);
|
|
|
|
}
|
|
|
|
|
2015-08-07 01:51:38 +00:00
|
|
|
void thread_join (abstr_thread_t thread) {
|
2015-08-06 17:24:38 +00:00
|
|
|
pthread_join(thread, NULL);
|
|
|
|
}
|
|
|
|
|
2016-10-17 11:50:38 +00:00
|
|
|
int fusermount (char *path) {
|
2015-08-06 17:24:38 +00:00
|
|
|
char *argv[] = {(char *) "fusermount", (char *) "-q", (char *) "-u", path, NULL};
|
|
|
|
|
2016-10-17 11:50:38 +00:00
|
|
|
return execute_command_and_wait(argv);
|
2015-08-06 17:24:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|