added Windows abstractions + dokany (still wip)

dokany found at `dokan-dev/dokany`
Raymond Hammarling 9 years ago
parent 7a87f2cea2
commit 4aa5a3da3a

@ -1,10 +1,10 @@
#include "abstractions.h"
#ifdef __APPLE__
#include <unistd.h>
#include <sys/wait.h>
#ifdef __APPLE__
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
void thread_create (thread_t* thread, thread_fn fn, void* data) {
@ -25,8 +25,27 @@ void fusermount (char *path) {
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) {
// TODO
}
#else
#include <unistd.h>
#include <sys/wait.h>
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
void thread_create (thread_t* thread, thread_fn fn, void* data) {

@ -1,10 +1,10 @@
#include <nan.h>
typedef void*(*thread_fn)(void*);
#ifdef __APPLE__
// OS X
#include <sys/mount.h>
#include <semaphore.h>
#include <dispatch/dispatch.h>
@ -34,13 +34,50 @@ NAN_INLINE static void mutex_unlock (pthread_mutex_t *mutex) {
}
typedef pthread_t thread_t;
typedef void* thread_fn_rtn_t;
void thread_create (thread_t*, thread_fn, void*);
void thread_join (thread_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 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>
typedef sem_t bindings_sem_t;
@ -68,10 +105,13 @@ NAN_INLINE static void mutex_unlock (pthread_mutex_t *mutex) {
}
typedef pthread_t thread_t;
typedef void* thread_fn_rtn_t;
#endif
typedef thread_fn_rtn_t(*thread_fn)(void*);
void thread_create (thread_t*, thread_fn, void*);
void thread_join (thread_t);
void fusermount (char*);
#endif

@ -1,8 +1,9 @@
{
"targets": [
{
"targets": [{
"target_name": "fuse_bindings",
"sources": [ "fuse-bindings.cc", "abstractions.cc" ],
"sources": ["fuse-bindings.cc", "abstractions.cc"],
"conditions": [
['OS!="win"', {
"include_dirs": [
"<!(node -e \"require('nan')\")",
"<!@(pkg-config fuse --cflags-only-I | sed s/-I//g)"
@ -12,6 +13,34 @@
"<!@(pkg-config --libs-only-L --libs-only-l fuse)"
]
}
}
}],
['OS=="win"', {
"include_dirs": [
"<!(node -e \"require('nan')\")",
"D:\\Git-Repos\\dokany\\dokan_fuse\\include"
],
"link_settings": {
"libraries": [
"C:\\Program Files\\Dokan\\DokanLibrary\\dokanfuse.lib"
]
}
}]
],
"configurations": {
"Debug": {
"msvs_settings": {
"VCCLCompilerTool": {
"RuntimeLibrary": 2
}
}
},
"Release": {
"msvs_settings": {
"VCCLCompilerTool": {
"RuntimeLibrary": 2
}
}
}
}
}]
}

@ -1,6 +1,8 @@
var fuse = require('./')
fuse.mount('./mnt', {
var mountPath = process.platform ? './mnt' : 'M:\\';
fuse.mount(mountPath, {
readdir: function (path, cb) {
console.log('readdir(%s)', path)
if (path === '/') return cb(0, ['test'])
@ -49,11 +51,11 @@ fuse.mount('./mnt', {
}
}, function (err) {
if (err) throw err
console.log('filesystem mounted on ./mnt')
console.log('filesystem mounted on ' + mountPath)
})
process.on('SIGINT', function () {
fuse.unmount('./mnt', function () {
fuse.unmount(mountPath, function () {
process.exit()
})
})

@ -4,13 +4,12 @@
#include <fuse.h>
#include <fuse_opt.h>
#include <fuse_lowlevel.h>
// #include <fuse_lowlevel.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/mount.h>
#include <sys/types.h>
#include "abstractions.h"
@ -116,8 +115,8 @@ struct bindings_t {
struct fuse_file_info *info;
char *path;
char *name;
off_t offset;
off_t length;
FUSE_OFF_T offset;
FUSE_OFF_T length;
void *data; // various structs
int mode;
int dev;
@ -194,7 +193,7 @@ static int bindings_mknod (const char *path, mode_t mode, dev_t dev) {
return bindings_call(b);
}
static int bindings_truncate (const char *path, off_t size) {
static int bindings_truncate (const char *path, FUSE_OFF_T size) {
bindings_t *b = bindings_get_context();
b->op = OP_TRUNCATE;
@ -204,7 +203,7 @@ static int bindings_truncate (const char *path, off_t size) {
return bindings_call(b);
}
static int bindings_ftruncate (const char *path, off_t size, struct fuse_file_info *info) {
static int bindings_ftruncate (const char *path, FUSE_OFF_T size, struct fuse_file_info *info) {
bindings_t *b = bindings_get_context();
b->op = OP_FTRUNCATE;
@ -268,7 +267,7 @@ static int bindings_fsyncdir (const char *path, int datasync, struct fuse_file_i
return bindings_call(b);
}
static int bindings_readdir (const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *info) {
static int bindings_readdir (const char *path, void *buf, fuse_fill_dir_t filler, FUSE_OFF_T offset, struct fuse_file_info *info) {
bindings_t *b = bindings_get_context();
b->op = OP_READDIR;
@ -399,7 +398,7 @@ static int bindings_opendir (const char *path, struct fuse_file_info *info) {
return bindings_call(b);
}
static int bindings_read (const char *path, char *buf, size_t len, off_t offset, struct fuse_file_info *info) {
static int bindings_read (const char *path, char *buf, size_t len, FUSE_OFF_T offset, struct fuse_file_info *info) {
bindings_t *b = bindings_get_context();
b->op = OP_READ;
@ -412,7 +411,7 @@ static int bindings_read (const char *path, char *buf, size_t len, off_t offset,
return bindings_call(b);
}
static int bindings_write (const char *path, const char *buf, size_t len, off_t offset, struct fuse_file_info * info) {
static int bindings_write (const char *path, const char *buf, size_t len, FUSE_OFF_T offset, struct fuse_file_info * info) {
bindings_t *b = bindings_get_context();
b->op = OP_WRITE;
@ -600,7 +599,7 @@ static void bindings_on_close (uv_handle_t *handle) {
mutex_unlock(&mutex);
}
static void *bindings_thread (void *data) {
static thread_fn_rtn_t bindings_thread (void *data) {
bindings_t *b = (bindings_t *) data;
struct fuse_operations ops = { };
@ -671,7 +670,7 @@ static void *bindings_thread (void *data) {
uv_close((uv_handle_t*) &(b->async), &bindings_on_close);
return NULL;
return 0;
}
NAN_INLINE static Local<Date> bindings_get_date (struct timespec *out) {
@ -697,6 +696,7 @@ NAN_INLINE static void bindings_set_stat (struct stat *stat, Local<Object> obj)
if (obj->Has(NanNew<String>("gid"))) stat->st_gid = obj->Get(NanNew<String>("gid"))->NumberValue();
if (obj->Has(NanNew<String>("rdev"))) stat->st_rdev = obj->Get(NanNew<String>("rdev"))->NumberValue();
if (obj->Has(NanNew<String>("size"))) stat->st_size = obj->Get(NanNew<String>("size"))->NumberValue();
#ifndef _WIN32
if (obj->Has(NanNew<String>("blksize"))) stat->st_blksize = obj->Get(NanNew<String>("blksize"))->NumberValue();
if (obj->Has(NanNew<String>("blocks"))) stat->st_blocks = obj->Get(NanNew<String>("blocks"))->NumberValue();
#ifdef __APPLE__
@ -708,6 +708,7 @@ NAN_INLINE static void bindings_set_stat (struct stat *stat, Local<Object> obj)
if (obj->Has(NanNew<String>("ctime"))) bindings_set_date(&stat->st_ctim, obj->Get(NanNew("ctime")).As<Date>());
if (obj->Has(NanNew<String>("atime"))) bindings_set_date(&stat->st_atim, obj->Get(NanNew("atime")).As<Date>());
#endif
#endif
}
NAN_INLINE static void bindings_set_statfs (struct statvfs *statfs, Local<Object> obj) { // from http://linux.die.net/man/2/stat
@ -768,7 +769,7 @@ NAN_METHOD(OpCallback) {
case OP_READLINK: {
if (args.Length() > 2 && args[2]->IsString()) {
NanUtf8String path(args[2]);
stpcpy((char *) b->data, *path);
strcpy((char *) b->data, *path);
}
}
break;
@ -1130,8 +1131,8 @@ NAN_METHOD(Mount) {
Local<Value> tmp[] = {NanNew<Number>(index), NanNew<FunctionTemplate>(OpCallback)->GetFunction()};
b->callback = new NanCallback(callback_constructor->Call(2, tmp).As<Function>());
stpcpy(b->mnt, *path);
stpcpy(b->mntopts, "-o");
strcpy(b->mnt, *path);
strcpy(b->mntopts, "-o");
Local<Array> options = ops->Get(NanNew<String>("options")).As<Array>();
if (options->IsArray()) {
@ -1203,7 +1204,7 @@ NAN_METHOD(Unmount) {
Local<Function> callback = args[1].As<Function>();
char *path_alloc = (char *) malloc(1024);
stpcpy(path_alloc, *path);
strcpy(path_alloc, *path);
NanAsyncQueueWorker(new UnmountWorker(new NanCallback(callback), path_alloc));
NanReturnUndefined();

@ -68,6 +68,8 @@ exports.mount = function (mnt, ops, cb) {
}
var mount = function () {
// TODO: I got a feeling this can be done better
if(os.platform() !== 'win32') {
fs.stat(mnt, function (err, stat) {
if (err) return cb(new Error('Mountpoint does not exist'))
if (!stat.isDirectory()) return cb(new Error('Mountpoint is not a directory'))
@ -77,6 +79,8 @@ exports.mount = function (mnt, ops, cb) {
})
})
}
else fuse.mount(mnt, ops)
}
if (!ops.force) return mount()
exports.unmount(mnt, mount)

Loading…
Cancel
Save