Merge pull request #7 from raymond-h/master
Windows support using Dokany (Dokan fork)
commit
e7f5308ee5
@ -0,0 +1,85 @@
|
||||
#include "abstractions.h"
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void thread_create (abstr_thread_t* thread, thread_fn fn, void* data) {
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_create(thread, &attr, fn, data);
|
||||
}
|
||||
|
||||
void thread_join (abstr_thread_t thread) {
|
||||
pthread_join(thread, NULL);
|
||||
}
|
||||
|
||||
void fusermount (char *path) {
|
||||
char *argv[] = {(char *) "umount", path, NULL};
|
||||
|
||||
pid_t cpid = vfork();
|
||||
if (cpid > 0) waitpid(cpid, NULL, 0);
|
||||
else execvp(argv[0], argv);
|
||||
}
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
void fusermount (char *path) {
|
||||
char* dokanPath = getenv("DOKAN_INSTALL_DIR");
|
||||
char cmdLine[MAX_PATH];
|
||||
|
||||
if(dokanPath) sprintf(cmdLine, "\"%s/dokanctl.exe\" /u %s", dokanPath, path);
|
||||
else sprintf(cmdLine, "dokanctl.exe /u %s", path);
|
||||
|
||||
STARTUPINFO info = {sizeof(info)};
|
||||
PROCESS_INFORMATION procInfo;
|
||||
CreateProcess(NULL, cmdLine, NULL, NULL, false, CREATE_NO_WINDOW, NULL, NULL, &info, &procInfo);
|
||||
|
||||
WaitForSingleObject(procInfo.hProcess, INFINITE);
|
||||
CloseHandle(procInfo.hProcess);
|
||||
CloseHandle(procInfo.hThread);
|
||||
|
||||
// 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!
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
void thread_create (abstr_thread_t* thread, thread_fn fn, void* data) {
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_init(&attr);
|
||||
pthread_create(thread, &attr, fn, data);
|
||||
}
|
||||
|
||||
void thread_join (abstr_thread_t thread) {
|
||||
pthread_join(thread, NULL);
|
||||
}
|
||||
|
||||
void fusermount (char *path) {
|
||||
char *argv[] = {(char *) "fusermount", (char *) "-q", (char *) "-u", path, NULL};
|
||||
|
||||
pid_t cpid = vfork();
|
||||
if (cpid > 0) waitpid(cpid, NULL, 0);
|
||||
else execvp(argv[0], argv);
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,126 @@
|
||||
#include <nan.h>
|
||||
|
||||
#define FUSE_USE_VERSION 29
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
// OS X
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include <semaphore.h>
|
||||
#include <dispatch/dispatch.h>
|
||||
|
||||
#include <fuse_lowlevel.h>
|
||||
|
||||
#define FUSE_OFF_T off_t
|
||||
|
||||
typedef dispatch_semaphore_t bindings_sem_t;
|
||||
|
||||
NAN_INLINE static int semaphore_init (dispatch_semaphore_t *sem) {
|
||||
*sem = dispatch_semaphore_create(0);
|
||||
return *sem == NULL ? -1 : 0;
|
||||
}
|
||||
|
||||
NAN_INLINE static void semaphore_wait (dispatch_semaphore_t *sem) {
|
||||
dispatch_semaphore_wait(*sem, DISPATCH_TIME_FOREVER);
|
||||
}
|
||||
|
||||
NAN_INLINE static void semaphore_signal (dispatch_semaphore_t *sem) {
|
||||
dispatch_semaphore_signal(*sem);
|
||||
}
|
||||
|
||||
extern pthread_mutex_t mutex;
|
||||
|
||||
NAN_INLINE static void mutex_lock (pthread_mutex_t *mutex) {
|
||||
pthread_mutex_lock(mutex);
|
||||
}
|
||||
|
||||
NAN_INLINE static void mutex_unlock (pthread_mutex_t *mutex) {
|
||||
pthread_mutex_unlock(mutex);
|
||||
}
|
||||
|
||||
typedef pthread_t abstr_thread_t;
|
||||
typedef void* thread_fn_rtn_t;
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
#include <windows.h>
|
||||
#include <io.h>
|
||||
#include <winsock2.h>
|
||||
|
||||
typedef HANDLE bindings_sem_t;
|
||||
|
||||
NAN_INLINE static int semaphore_init (HANDLE *sem) {
|
||||
*sem = CreateSemaphore(NULL, 0, 10, NULL);
|
||||
return *sem == NULL ? -1 : 0;
|
||||
}
|
||||
|
||||
NAN_INLINE static void semaphore_wait (HANDLE *sem) {
|
||||
WaitForSingleObject(*sem, INFINITE);
|
||||
}
|
||||
|
||||
NAN_INLINE static void semaphore_signal (HANDLE *sem) {
|
||||
ReleaseSemaphore(*sem, 1, NULL);
|
||||
}
|
||||
|
||||
extern HANDLE mutex;
|
||||
|
||||
NAN_INLINE static void mutex_lock (HANDLE *mutex) {
|
||||
WaitForSingleObject(*mutex, INFINITE);
|
||||
}
|
||||
|
||||
NAN_INLINE static void mutex_unlock (HANDLE *mutex) {
|
||||
ReleaseMutex(*mutex);
|
||||
}
|
||||
|
||||
typedef HANDLE abstr_thread_t;
|
||||
typedef DWORD thread_fn_rtn_t;
|
||||
|
||||
#define fuse_session_remove_chan(x)
|
||||
#define stat _stati64
|
||||
|
||||
#else
|
||||
|
||||
// Linux and whatnot
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include <semaphore.h>
|
||||
#include <fuse_lowlevel.h>
|
||||
|
||||
#define FUSE_OFF_T off_t
|
||||
|
||||
typedef sem_t bindings_sem_t;
|
||||
|
||||
NAN_INLINE static int semaphore_init (sem_t *sem) {
|
||||
return sem_init(sem, 0, 0);
|
||||
}
|
||||
|
||||
NAN_INLINE static void semaphore_wait (sem_t *sem) {
|
||||
sem_wait(sem);
|
||||
}
|
||||
|
||||
NAN_INLINE static void semaphore_signal (sem_t *sem) {
|
||||
sem_post(sem);
|
||||
}
|
||||
|
||||
extern pthread_mutex_t mutex;
|
||||
|
||||
NAN_INLINE static void mutex_lock (pthread_mutex_t *mutex) {
|
||||
pthread_mutex_lock(mutex);
|
||||
}
|
||||
|
||||
NAN_INLINE static void mutex_unlock (pthread_mutex_t *mutex) {
|
||||
pthread_mutex_unlock(mutex);
|
||||
}
|
||||
|
||||
typedef pthread_t abstr_thread_t;
|
||||
typedef void* thread_fn_rtn_t;
|
||||
|
||||
#endif
|
||||
|
||||
typedef thread_fn_rtn_t(*thread_fn)(void*);
|
||||
|
||||
void thread_create (abstr_thread_t*, thread_fn, void*);
|
||||
void thread_join (abstr_thread_t);
|
||||
|
||||
void fusermount (char*);
|
@ -1,17 +1,48 @@
|
||||
{
|
||||
"targets": [
|
||||
{
|
||||
"target_name": "fuse_bindings",
|
||||
"sources": [ "fuse-bindings.cc" ],
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('nan')\")",
|
||||
"<!@(pkg-config fuse --cflags-only-I | sed s/-I//g)"
|
||||
],
|
||||
"link_settings": {
|
||||
"libraries": [
|
||||
"<!@(pkg-config --libs-only-L --libs-only-l fuse)"
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
"targets": [{
|
||||
"target_name": "fuse_bindings",
|
||||
"sources": ["fuse-bindings.cc", "abstractions.cc"],
|
||||
"include_dirs": [
|
||||
"<!(node -e \"require('nan')\")"
|
||||
],
|
||||
"conditions": [
|
||||
['OS!="win"', {
|
||||
"include_dirs": [
|
||||
"<!@(pkg-config fuse --cflags-only-I | sed s/-I//g)"
|
||||
],
|
||||
"link_settings": {
|
||||
"libraries": [
|
||||
"<!@(pkg-config --libs-only-L --libs-only-l fuse)"
|
||||
]
|
||||
}
|
||||
}],
|
||||
['OS=="win"', {
|
||||
"include_dirs": [
|
||||
"$(DOKAN_FUSE_INCLUDE)",
|
||||
"$(INCLUDE)"
|
||||
],
|
||||
"link_settings": {
|
||||
"libraries": [
|
||||
"<!(echo %DOKAN_INSTALL_DIR%)/dokanfuse.lib"
|
||||
]
|
||||
}
|
||||
}]
|
||||
],
|
||||
"configurations": {
|
||||
"Debug": {
|
||||
"msvs_settings": {
|
||||
"VCCLCompilerTool": {
|
||||
"RuntimeLibrary": 2
|
||||
}
|
||||
}
|
||||
},
|
||||
"Release": {
|
||||
"msvs_settings": {
|
||||
"VCCLCompilerTool": {
|
||||
"RuntimeLibrary": 2
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
}
|
||||
|
Loading…
Reference in new issue