Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Msys2 pkg-config #350

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions dokan_fuse/pkg/.PKGINFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by hand
# Tue Sep 13 21:11:06 UTC 2016
pkgname = fuse
pkgbase = dokan_fuse
pkgver = 1.0.0-4
pkgdesc = A wrapper library that makes Dokan compatible with FUSE API
url = https://github.com/dokan-dev/dokany/wiki/FUSE
builddate = 1323390194
packager = http://mgalgs.github.io/2011/12/08/creating-arch-linux-packages-by-hand.html
size = 8192
arch = x86_64
license = GPL
license = LGPL
group = libraries
287 changes: 287 additions & 0 deletions dokan_fuse/pkg/opt/include/dokan_fuse/ScopeGuard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
#ifndef SCOPEGUARD_H_
#define SCOPEGUARD_H_

#include <assert.h>

template <class T>
class RefHolder
{
T& ref_;
public:
RefHolder(T& ref) : ref_(ref) {}
operator T& () const
{
return ref_;
}
private:
// Disable assignment - not implemented
RefHolder& operator=(const RefHolder&);
};

template <class T>
inline RefHolder<T> ByRef(T& t)
{
return RefHolder<T>(t);
}

class ScopeGuardImplBase
{
ScopeGuardImplBase& operator =(const ScopeGuardImplBase&);
protected:
~ScopeGuardImplBase()
{
}
ScopeGuardImplBase(const ScopeGuardImplBase& other) throw()
: dismissed_(other.dismissed_)
{
other.Dismiss();
}
template <typename J>
static void SafeExecute(J& j) throw()
{
if (!j.dismissed_)
try
{
j.Execute();
}
catch(...)
{
assert(!"Exception while performing cleanup!");
}
}

mutable bool dismissed_;
public:
ScopeGuardImplBase() throw() : dismissed_(false)
{
}
void Dismiss() const throw()
{
dismissed_ = true;
}
};

typedef const ScopeGuardImplBase& ScopeGuard;

template <typename F>
class ScopeGuardImpl0 : public ScopeGuardImplBase
{
public:
static ScopeGuardImpl0<F> MakeGuard(F fun)
{
return ScopeGuardImpl0<F>(fun);
}
~ScopeGuardImpl0() throw()
{
SafeExecute(*this);
}
void Execute()
{
fun_();
}
protected:
ScopeGuardImpl0(F fun) : fun_(fun)
{
}
F fun_;
};

template <typename F>
inline ScopeGuardImpl0<F> MakeGuard(F fun)
{
return ScopeGuardImpl0<F>::MakeGuard(fun);
}

template <typename F, typename P1>
class ScopeGuardImpl1 : public ScopeGuardImplBase
{
public:
static ScopeGuardImpl1<F, P1> MakeGuard(F fun, P1 p1)
{
return ScopeGuardImpl1<F, P1>(fun, p1);
}
~ScopeGuardImpl1() throw()
{
SafeExecute(*this);
}
void Execute()
{
fun_(p1_);
}
protected:
ScopeGuardImpl1(F fun, P1 p1) : fun_(fun), p1_(p1)
{
}
F fun_;
const P1 p1_;
};

template <typename F, typename P1>
inline ScopeGuardImpl1<F, P1> MakeGuard(F fun, P1 p1)
{
return ScopeGuardImpl1<F, P1>::MakeGuard(fun, p1);
}

template <typename F, typename P1, typename P2>
class ScopeGuardImpl2: public ScopeGuardImplBase
{
public:
static ScopeGuardImpl2<F, P1, P2> MakeGuard(F fun, P1 p1, P2 p2)
{
return ScopeGuardImpl2<F, P1, P2>(fun, p1, p2);
}
~ScopeGuardImpl2() throw()
{
SafeExecute(*this);
}
void Execute()
{
fun_(p1_, p2_);
}
protected:
ScopeGuardImpl2(F fun, P1 p1, P2 p2) : fun_(fun), p1_(p1), p2_(p2)
{
}
F fun_;
const P1 p1_;
const P2 p2_;
};

template <typename F, typename P1, typename P2>
inline ScopeGuardImpl2<F, P1, P2> MakeGuard(F fun, P1 p1, P2 p2)
{
return ScopeGuardImpl2<F, P1, P2>::MakeGuard(fun, p1, p2);
}

template <typename F, typename P1, typename P2, typename P3>
class ScopeGuardImpl3 : public ScopeGuardImplBase
{
public:
static ScopeGuardImpl3<F, P1, P2, P3> MakeGuard(F fun, P1 p1, P2 p2, P3 p3)
{
return ScopeGuardImpl3<F, P1, P2, P3>(fun, p1, p2, p3);
}
~ScopeGuardImpl3() throw()
{
SafeExecute(*this);
}
void Execute()
{
fun_(p1_, p2_, p3_);
}
protected:
ScopeGuardImpl3(F fun, P1 p1, P2 p2, P3 p3) : fun_(fun), p1_(p1), p2_(p2), p3_(p3)
{
}
F fun_;
const P1 p1_;
const P2 p2_;
const P3 p3_;
};

template <typename F, typename P1, typename P2, typename P3>
inline ScopeGuardImpl3<F, P1, P2, P3> MakeGuard(F fun, P1 p1, P2 p2, P3 p3)
{
return ScopeGuardImpl3<F, P1, P2, P3>::MakeGuard(fun, p1, p2, p3);
}

//************************************************************

template <class Obj, typename MemFun>
class ObjScopeGuardImpl0 : public ScopeGuardImplBase
{
public:
static ObjScopeGuardImpl0<Obj, MemFun> MakeObjGuard(Obj& obj, MemFun memFun)
{
return ObjScopeGuardImpl0<Obj, MemFun>(obj, memFun);
}
~ObjScopeGuardImpl0() throw()
{
SafeExecute(*this);
}
void Execute()
{
(obj_.*memFun_)();
}
protected:
ObjScopeGuardImpl0(Obj& obj, MemFun memFun)
: obj_(obj), memFun_(memFun) {}
Obj& obj_;
MemFun memFun_;
};

template <class Obj, typename MemFun>
inline ObjScopeGuardImpl0<Obj, MemFun> MakeObjGuard(Obj& obj, MemFun memFun)
{
return ObjScopeGuardImpl0<Obj, MemFun>::MakeObjGuard(obj, memFun);
}

template <class Obj, typename MemFun, typename P1>
class ObjScopeGuardImpl1 : public ScopeGuardImplBase
{
public:
static ObjScopeGuardImpl1<Obj, MemFun, P1> MakeObjGuard(Obj& obj, MemFun memFun, P1 p1)
{
return ObjScopeGuardImpl1<Obj, MemFun, P1>(obj, memFun, p1);
}
~ObjScopeGuardImpl1() throw()
{
SafeExecute(*this);
}
void Execute()
{
(obj_.*memFun_)(p1_);
}
protected:
ObjScopeGuardImpl1(Obj& obj, MemFun memFun, P1 p1)
: obj_(obj), memFun_(memFun), p1_(p1) {}
Obj& obj_;
MemFun memFun_;
const P1 p1_;
};

template <class Obj, typename MemFun, typename P1>
inline ObjScopeGuardImpl1<Obj, MemFun, P1> MakeObjGuard(Obj& obj, MemFun memFun, P1 p1)
{
return ObjScopeGuardImpl1<Obj, MemFun, P1>::MakeObjGuard(obj, memFun, p1);
}

template <class Obj, typename MemFun, typename P1, typename P2>
class ObjScopeGuardImpl2 : public ScopeGuardImplBase
{
public:
static ObjScopeGuardImpl2<Obj, MemFun, P1, P2> MakeObjGuard(Obj& obj, MemFun memFun, P1 p1, P2 p2)
{
return ObjScopeGuardImpl2<Obj, MemFun, P1, P2>(obj, memFun, p1, p2);
}
~ObjScopeGuardImpl2() throw()
{
SafeExecute(*this);
}
void Execute()
{
(obj_.*memFun_)(p1_, p2_);
}
protected:
ObjScopeGuardImpl2(Obj& obj, MemFun memFun, P1 p1, P2 p2)
: obj_(obj), memFun_(memFun), p1_(p1), p2_(p2) {}
Obj& obj_;
MemFun memFun_;
const P1 p1_;
const P2 p2_;
};

template <class Obj, typename MemFun, typename P1, typename P2>
inline ObjScopeGuardImpl2<Obj, MemFun, P1, P2> MakeObjGuard(Obj& obj, MemFun memFun, P1 p1, P2 p2)
{
return ObjScopeGuardImpl2<Obj, MemFun, P1, P2>::MakeObjGuard(obj, memFun, p1, p2);
}

#define CONCATENATE_DIRECT(s1, s2) s1##s2
#define CONCATENATE(s1, s2) CONCATENATE_DIRECT(s1, s2)
#define ANONYMOUS_VARIABLE(str) CONCATENATE(str, __COUNTER__)

#define ON_BLOCK_EXIT ScopeGuard ANONYMOUS_VARIABLE(scopeGuard) = MakeGuard
#define ON_BLOCK_EXIT_OBJ ScopeGuard ANONYMOUS_VARIABLE(scopeGuard) = MakeObjGuard

#endif //SCOPEGUARD_H_
64 changes: 64 additions & 0 deletions dokan_fuse/pkg/opt/include/dokan_fuse/dokanfuse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#ifndef DOKANFUSE_H_
#define DOKANFUSE_H_

#include <string>

#define FUSE_THREAD_COUNT 10
#define DOKAN_DLL L"dokan" DOKAN_MAJOR_API_VERSION L".dll"

struct fuse_config
{
unsigned int umask;
unsigned int fileumask, dirumask;
const char *fsname, *volname;
int help;
int debug;
int setsignals;
unsigned int timeoutInSec;
int networkDrive;
};

struct fuse_session
{
fuse_chan *ch;
};

struct fuse_chan
{
fuse_chan():ResolvedDokanMain(NULL), ResolvedDokanUnmount(NULL), ResolvedDokanRemoveMountPoint(NULL), dokanDll(NULL) {}
~fuse_chan();

//This method dynamically loads DOKAN functions
bool init();

typedef int (__stdcall *DokanMainType)(PDOKAN_OPTIONS,PDOKAN_OPERATIONS);
typedef BOOL (__stdcall *DokanUnmountType)(WCHAR DriveLetter);
typedef BOOL (__stdcall *DokanRemoveMountPointType)(LPCWSTR MountPoint);
DokanMainType ResolvedDokanMain;
DokanUnmountType ResolvedDokanUnmount;
DokanRemoveMountPointType ResolvedDokanRemoveMountPoint;

std::string mountpoint;
private:
HMODULE dokanDll;
};

struct fuse
{
bool within_loop;
std::unique_ptr<fuse_chan> ch;
fuse_session sess;
fuse_config conf;

struct fuse_operations ops;
void *user_data;

fuse() : within_loop(), user_data()
{
memset(&conf,0,sizeof(fuse_config));
memset(&sess, 0, sizeof(fuse_session));
memset(&ops, 0, sizeof(fuse_operations));
}
};

#endif //DOKANFUSE_H_
854 changes: 854 additions & 0 deletions dokan_fuse/pkg/opt/include/dokan_fuse/fuse.h

Large diffs are not rendered by default.

249 changes: 249 additions & 0 deletions dokan_fuse/pkg/opt/include/dokan_fuse/fuse_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
/*
FUSE: Filesystem in Userspace
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
This program can be distributed under the terms of the GNU LGPLv2.
See the file COPYING.LIB.
*/

/** @file */

#if !defined(FUSE_H_) && !defined(FUSE_LOWLEVEL_H_)
#error "Never include <fuse_common.h> directly; use <fuse.h> or <fuse_lowlevel.h> instead."
#endif

#ifndef FUSE_COMMON_H_
#define FUSE_COMMON_H_

#include "fuse_opt.h"
#ifndef _MSC_VER
#include <stdint.h>
#endif

/** Major version of FUSE library interface */
#define FUSE_MAJOR_VERSION 2

/** Minor version of FUSE library interface */
#define FUSE_MINOR_VERSION 7

#define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min))
#define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)

/* This interface uses 64 bit off_t, except on Windows where it's
possible to use 32-bit filelengths for compatibility with MSVC CRT */
#ifndef _MSC_VER
/* This interface uses 64 bit off_t */
#if _FILE_OFFSET_BITS != 64
#error Please add -D_FILE_OFFSET_BITS=64 to your compile flags!
#endif
#endif

#ifdef __cplusplus
extern "C" {
#endif

/**
* Information about open files
*
* Changed in version 2.5
*/
struct fuse_file_info {
/** Open flags. Available in open() and release() */
int flags;

/** Old file handle, don't use */
unsigned long fh_old;

/** In case of a write operation indicates if this was caused by a
writepage */
int writepage;

/** Can be filled in by open, to use direct I/O on this file.
Introduced in version 2.4 */
unsigned int direct_io : 1;

/** Can be filled in by open, to indicate, that cached file data
need not be invalidated. Introduced in version 2.4 */
unsigned int keep_cache : 1;

/** Indicates a flush operation. Set in flush operation, also
maybe set in highlevel lock operation and lowlevel release
operation. Introduced in version 2.6 */
unsigned int flush : 1;

/** Padding. Do not use*/
unsigned int padding : 29;

/** File handle. May be filled in by filesystem in open().
Available in all other file operations */
uint64_t fh;

/** Lock owner id. Available in locking operations and flush */
uint64_t lock_owner;
};

/**
* Connection information, passed to the ->init() method
*
* Some of the elements are read-write, these can be changed to
* indicate the value requested by the filesystem. The requested
* value must usually be smaller than the indicated value.
*/
struct fuse_conn_info {
/**
* Major version of the protocol (read-only)
*/
unsigned proto_major;

/**
* Minor version of the protocol (read-only)
*/
unsigned proto_minor;

/**
* Is asynchronous read supported (read-write)
*/
unsigned async_read;

/**
* Maximum size of the write buffer
*/
unsigned max_write;

/**
* Maximum readahead
*/
unsigned max_readahead;

/**
* For future use.
*/
unsigned reserved[27];
};

struct fuse_session;
struct fuse_chan;

/**
* Create a FUSE mountpoint
*
* Returns a control file descriptor suitable for passing to
* fuse_new()
*
* @param mountpoint the mount point path
* @param args argument vector
* @return the communication channel on success, NULL on failure
*/
struct fuse_chan *fuse_mount(const char *mountpoint, struct fuse_args *args);

/**
* Umount a FUSE mountpoint
*
* @param mountpoint the mount point path
* @param ch the communication channel
*/
void fuse_unmount(const char *mountpoint, struct fuse_chan *ch);

/**
* Parse common options
*
* The following options are parsed:
*
* '-f' foreground
* '-d' '-odebug' foreground, but keep the debug option
* '-s' single threaded
* '-h' '--help' help
* '-ho' help without header
* '-ofsname=..' file system name, if not present, then set to the program
* name
*
* All parameters may be NULL
*
* @param args argument vector
* @param mountpoint the returned mountpoint, should be freed after use
* @param multithreaded set to 1 unless the '-s' option is present
* @param foreground set to 1 if one of the relevant options is present
* @return 0 on success, -1 on failure
*/
int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint,
int *multithreaded, int *foreground);

/**
* Go into the background
*
* @param foreground if true, stay in the foreground
* @return 0 on success, -1 on failure
*/
int fuse_daemonize(int foreground);

/**
* Get the version of the library
*
* @return the version
*/
int fuse_version(void);

/* ----------------------------------------------------------- *
* Signal handling *
* ----------------------------------------------------------- */

/**
* Exit session on HUP, TERM and INT signals and ignore PIPE signal
*
* Stores session in a global variable. May only be called once per
* process until fuse_remove_signal_handlers() is called.
*
* @param se the session to exit
* @return 0 on success, -1 on failure
*/
int fuse_set_signal_handlers(struct fuse_session *se);

/**
* Restore default signal handlers
*
* Resets global session. After this fuse_set_signal_handlers() may
* be called again.
*
* @param se the same session as given in fuse_set_signal_handlers()
*/
void fuse_remove_signal_handlers(struct fuse_session *se);

/* ----------------------------------------------------------- *
* Compatibility stuff *
* ----------------------------------------------------------- */

#if FUSE_USE_VERSION < 26
# ifdef __FreeBSD__
# if FUSE_USE_VERSION < 25
# error On FreeBSD API version 25 or greater must be used
# endif
# endif
# include "fuse_common_compat.h"
# undef FUSE_MINOR_VERSION
# undef fuse_main
# define fuse_unmount fuse_unmount_compat22
# if FUSE_USE_VERSION == 25
# define FUSE_MINOR_VERSION 5
# define fuse_mount fuse_mount_compat25
# elif FUSE_USE_VERSION == 24 || FUSE_USE_VERSION == 22
# define FUSE_MINOR_VERSION 4
# define fuse_mount fuse_mount_compat22
# elif FUSE_USE_VERSION == 21
# define FUSE_MINOR_VERSION 1
# define fuse_mount fuse_mount_compat22
# elif FUSE_USE_VERSION == 11
# warning Compatibility with API version 11 is deprecated
# undef FUSE_MAJOR_VERSION
# define FUSE_MAJOR_VERSION 1
# define FUSE_MINOR_VERSION 1
# define fuse_mount fuse_mount_compat1
# else
# error Compatibility with API version other than 21, 22, 24, 25 and 11 not supported
# endif
#endif

#ifdef __cplusplus
}
#endif

#endif /* FUSE_COMMON_H_ */
267 changes: 267 additions & 0 deletions dokan_fuse/pkg/opt/include/dokan_fuse/fuse_opt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,267 @@
/*
FUSE: Filesystem in Userspace
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
This program can be distributed under the terms of the GNU LGPLv2.
See the file COPYING.LIB.
*/

#ifndef FUSE_OPT_H_
#define FUSE_OPT_H_

/** @file
*
* This file defines the option parsing interface of FUSE
*/

#ifdef _MSC_VER
#define STRDUP _strdup
#else
#define STRDUP strdup
#endif

#ifdef __cplusplus
extern "C" {
#endif

/**
* Option description
*
* This structure describes a single option, and and action associated
* with it, in case it matches.
*
* More than one such match may occur, in which case the action for
* each match is executed.
*
* There are three possible actions in case of a match:
*
* i) An integer (int or unsigned) variable determined by 'offset' is
* set to 'value'
*
* ii) The processing function is called, with 'value' as the key
*
* iii) An integer (any) or string (char *) variable determined by
* 'offset' is set to the value of an option parameter
*
* 'offset' should normally be either set to
*
* - 'offsetof(struct foo, member)' actions i) and iii)
*
* - -1 action ii)
*
* The 'offsetof()' macro is defined in the <stddef.h> header.
*
* The template determines which options match, and also have an
* effect on the action. Normally the action is either i) or ii), but
* if a format is present in the template, then action iii) is
* performed.
*
* The types of templates are:
*
* 1) "-x", "-foo", "--foo", "--foo-bar", etc. These match only
* themselves. Invalid values are "--" and anything beginning
* with "-o"
*
* 2) "foo", "foo-bar", etc. These match "-ofoo", "-ofoo-bar" or
* the relevant option in a comma separated option list
*
* 3) "bar=", "--foo=", etc. These are variations of 1) and 2)
* which have a parameter
*
* 4) "bar=%s", "--foo=%lu", etc. Same matching as above but perform
* action iii).
*
* 5) "-x ", etc. Matches either "-xparam" or "-x param" as
* two separate arguments
*
* 6) "-x %s", etc. Combination of 4) and 5)
*
* If the format is "%s", memory is allocated for the string unlike
* with scanf().
*/
struct fuse_opt {
/** Matching template and optional parameter formatting */
const char *templ;

/**
* Offset of variable within 'data' parameter of fuse_opt_parse()
* or -1
*/
unsigned long offset;

/**
* Value to set the variable to, or to be passed as 'key' to the
* processing function. Ignored if template has a format
*/
int value;
};

/**
* Key option. In case of a match, the processing function will be
* called with the specified key.
*/
#define FUSE_OPT_KEY(templ, key) { templ, (unsigned long)(-1), key }

/**
* Last option. An array of 'struct fuse_opt' must end with a NULL
* template value
*/
#define FUSE_OPT_END { NULL }

/**
* Argument list
*/
struct fuse_args {
/** Argument count */
int argc;

/** Argument vector. NULL terminated */
char **argv;

/** Is 'argv' allocated? */
int allocated;
};

/**
* Initializer for 'struct fuse_args'
*/
#define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }

/**
* Key value passed to the processing function if an option did not
* match any template
*/
#define FUSE_OPT_KEY_OPT -1

/**
* Key value passed to the processing function for all non-options
*
* Non-options are the arguments beginning with a charater other than
* '-' or all arguments after the special '--' option
*/
#define FUSE_OPT_KEY_NONOPT -2

/**
* Special key value for options to keep
*
* Argument is not passed to processing function, but behave as if the
* processing function returned 1
*/
#define FUSE_OPT_KEY_KEEP -3

/**
* Special key value for options to discard
*
* Argument is not passed to processing function, but behave as if the
* processing function returned zero
*/
#define FUSE_OPT_KEY_DISCARD -4

/**
* Processing function
*
* This function is called if
* - option did not match any 'struct fuse_opt'
* - argument is a non-option
* - option did match and offset was set to -1
*
* The 'arg' parameter will always contain the whole argument or
* option including the parameter if exists. A two-argument option
* ("-x foo") is always converted to single arguemnt option of the
* form "-xfoo" before this function is called.
*
* Options of the form '-ofoo' are passed to this function without the
* '-o' prefix.
*
* The return value of this function determines whether this argument
* is to be inserted into the output argument vector, or discarded.
*
* @param data is the user data passed to the fuse_opt_parse() function
* @param arg is the whole argument or option
* @param key determines why the processing function was called
* @param outargs the current output argument list
* @return -1 on error, 0 if arg is to be discarded, 1 if arg should be kept
*/
typedef int (*fuse_opt_proc_t)(void *data, const char *arg, int key,
struct fuse_args *outargs);

/**
* Option parsing function
*
* If 'args' was returned from a previous call to fuse_opt_parse() or
* it was constructed from
*
* A NULL 'args' is equivalent to an empty argument vector
*
* A NULL 'opts' is equivalent to an 'opts' array containing a single
* end marker
*
* A NULL 'proc' is equivalent to a processing function always
* returning '1'
*
* @param args is the input and output argument list
* @param data is the user data
* @param opts is the option description array
* @param proc is the processing function
* @return -1 on error, 0 on success
*/
int fuse_opt_parse(struct fuse_args *args, void *data,
const struct fuse_opt opts[], fuse_opt_proc_t proc);

/**
* Add an option to a comma separated option list
*
* @param opts is a pointer to an option list, may point to a NULL value
* @param opt is the option to add
* @return -1 on allocation error, 0 on success
*/
int fuse_opt_add_opt(char **opts, const char *opt);

/**
* Add an argument to a NULL terminated argument vector
*
* @param args is the structure containing the current argument list
* @param arg is the new argument to add
* @return -1 on allocation error, 0 on success
*/
int fuse_opt_add_arg(struct fuse_args *args, const char *arg);

/**
* Add an argument at the specified position in a NULL terminated
* argument vector
*
* Adds the argument to the N-th position. This is useful for adding
* options at the beggining of the array which must not come after the
* special '--' option.
*
* @param args is the structure containing the current argument list
* @param pos is the position at which to add the argument
* @param arg is the new argument to add
* @return -1 on allocation error, 0 on success
*/
int fuse_opt_insert_arg(struct fuse_args *args, int pos, const char *arg);

/**
* Free the contents of argument list
*
* The structure itself is not freed
*
* @param args is the structure containing the argument list
*/
void fuse_opt_free_args(struct fuse_args *args);


/**
* Check if an option matches
*
* @param opts is the option description array
* @param opt is the option to match
* @return 1 if a match is found, 0 if not
*/
int fuse_opt_match(const struct fuse_opt opts[], const char *opt);

#ifdef __cplusplus
}
#endif

#endif /* FUSE_OPT_H_ */
27 changes: 27 additions & 0 deletions dokan_fuse/pkg/opt/include/dokan_fuse/fuse_sem_fix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef FUSE_SEM_FIX_H_
#define FUSE_SEM_FIX_H_

#ifdef __CYGWIN__
#include <semaphore.h>

#ifdef __cplusplus
extern "C" {
#endif

int my_sem_init(sem_t *sem, int pshared, int initial);
int my_sem_destroy(sem_t *sem);
int my_sem_post (sem_t * sem);
int my_sem_wait (sem_t * sem);
#define sem_init my_sem_init
#define sem_destroy my_sem_destroy
#define sem_wait my_sem_wait
#define sem_post my_sem_post

#ifdef __cplusplus
};
#endif


#endif

#endif //FUSE_SEM_FIX_H_
221 changes: 221 additions & 0 deletions dokan_fuse/pkg/opt/include/dokan_fuse/fuse_win.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
/* ----------------------------------------------------------- *
* Win32 helper functions *
* Compilation on MSVC requires /Zc:wchar_t compiler option *
* ----------------------------------------------------------- */
#ifndef FUSE_WIN_H_
#define FUSE_WIN_H_

#include <time.h>
#include <sys/types.h>

#ifdef _MSC_VER
#define WIN32_NO_STATUS
#include <windows.h>
#undef WIN32_NO_STATUS
#endif

/** Only use the latest version on Windows */
#ifndef FUSE_USE_VERSION
#define FUSE_USE_VERSION 27
#endif

#ifndef DEFAULT_FUSE_VOLUME_NAME
#define DEFAULT_FUSE_VOLUME_NAME "DOKAN"
#endif

#ifndef DEFAULT_FUSE_FILESYSTEM_NAME
#define DEFAULT_FUSE_FILESYSTEM_NAME "Dokan user-level file system"
#endif

#ifdef __cplusplus
extern "C" {
#endif
int ntstatus_error_to_errno(int win_res);
int errno_to_ntstatus_error(int err);

//This stuff is useful only on Windows in MSVC
#ifdef _MSC_VER
char** convert_args(int argc, wchar_t* argv[]);
void free_converted_args(int argc, char **argv);
#endif

#ifdef __cplusplus
};
#endif

extern wchar_t* Dokan_filesystem_name;
extern wchar_t* Dokan_volume_name;

/////////////////////////////////////////////////////////////////////
////// Type definitions for MINGW32
/////////////////////////////////////////////////////////////////////
#if defined(__MINGW32__) && !defined(UID_GID_DEF)
typedef unsigned int gid_t;
typedef unsigned int uid_t;
#endif

#if !defined(HAVE_STRUCT_TIMESPEC) && !defined(__CYGWIN__) && !defined(_TIMESPEC_DEFINED) && defined(_CRT_NO_TIME_T) /* win32 pthread.h time.h defines it */
/* POSIX.1b structure for a time value. This is like a `struct timeval' but
has nanoseconds instead of microseconds. */
#define HAVE_STRUCT_TIMESPEC 1
#define _TIMESPEC_DEFINED
struct timespec
{
time_t tv_sec; /* Seconds. */
long int tv_nsec; /* Nanoseconds. */
};
#endif

#if defined(__MINGW32__)
/** Use 64 bit offsets */
#define __USE_FILE_OFFSET64
//Block sizes
typedef unsigned __int64 fsfilcnt64_t;
typedef unsigned __int64 fsblkcnt64_t;
typedef struct timespec timestruc_t;
typedef unsigned short nlink_t;
typedef unsigned __int64 uint64_t;
typedef unsigned int blksize_t;
typedef unsigned __int64 blkcnt_t;

/** Transplanted from <sys/statvfs.h>*/
struct statvfs
{
unsigned long int f_bsize;
unsigned long int f_frsize;
fsblkcnt64_t f_blocks;
fsblkcnt64_t f_bfree;
fsblkcnt64_t f_bavail;
fsfilcnt64_t f_files;
fsfilcnt64_t f_ffree;
fsfilcnt64_t f_favail;
unsigned long int f_fsid;
unsigned long int f_flag;
unsigned long int f_namemax;
};
struct flock {
short l_type;
short l_whence;
off_t l_start;
off_t l_len;
pid_t l_pid;
};

#endif

/////////////////////////////////////////////////////////////////////
////// Type definitions for MSVC
/////////////////////////////////////////////////////////////////////
#if defined(_MSC_VER)
//UNIX compatibility
typedef struct timespec timestruc_t;
typedef unsigned int mode_t;
typedef unsigned short nlink_t;
typedef unsigned int pid_t;
typedef unsigned int gid_t;
typedef unsigned int uid_t;
typedef unsigned int blksize_t;
typedef unsigned __int64 blkcnt_t;
typedef unsigned int uint32_t;
typedef unsigned __int64 uint64_t;
typedef __int64 int64_t;


//OCTAL constants!
#define S_IFLNK 0120000
#define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK)

/** Use 64 bit offsets */
#define __USE_FILE_OFFSET64
//Block sizes
typedef unsigned __int64 fsfilcnt64_t;
typedef unsigned __int64 fsblkcnt64_t;

/** Transplanted from <sys/statvfs.h>*/
struct statvfs
{
unsigned long int f_bsize;
unsigned long int f_frsize;
fsblkcnt64_t f_blocks;
fsblkcnt64_t f_bfree;
fsblkcnt64_t f_bavail;
fsfilcnt64_t f_files;
fsfilcnt64_t f_ffree;
fsfilcnt64_t f_favail;
unsigned long int f_fsid;
unsigned long int f_flag;
unsigned long int f_namemax;
};

struct flock {
short l_type;
short l_whence;
__int64 l_start;
__int64 l_len;
pid_t l_pid;
};

#endif

//We have a choice between CRT-compatible 32-bit off_t definition
//and a custom 64-bit definition
#define WIDE_OFF_T 1
#ifndef WIDE_OFF_T
#define FUSE_OFF_T off_t
#define FUSE_STAT stat

#else
#define FUSE_OFF_T __int64
// #define FUSE_STAT _stati64
// use stat from cygwin instead for having more members and
// being more compatible
// stat ported from cygwin sys/stat.h
struct stat64_cygwin
{
dev_t st_dev;
uint64_t st_ino;
mode_t st_mode;
nlink_t st_nlink;
uid_t st_uid;
gid_t st_gid;
dev_t st_rdev;
FUSE_OFF_T st_size;
timestruc_t st_atim;
timestruc_t st_mtim;
timestruc_t st_ctim;
blksize_t st_blksize;
blkcnt_t st_blocks;
timestruc_t st_birthtim;
};
/* The following breaks struct stat definiton in native Windows stats.h
* So whenever referencing st_atime|st_ctime|st_mtime, replacing is needed.
*/
/*
#define st_atime st_atim.tv_sec
#define st_ctime st_ctim.tv_sec
#define st_mtime st_mtim.tv_sec
*/
#define FUSE_STAT stat64_cygwin
#if 0
struct stat64 {
dev_t st_dev;
ino_t st_ino;
unsigned short st_mode;
short st_nlink;
short st_uid;
short st_gid;
dev_t st_rdev;
FUSE_OFF_T st_size;
time_t st_atime;
time_t st_mtime;
time_t st_ctime;
};
#endif
#endif


#define F_WRLCK 1
#define F_UNLCK 2
#define F_SETLK 6

#endif // FUSE_WIN_H_
234 changes: 234 additions & 0 deletions dokan_fuse/pkg/opt/include/dokan_fuse/fusemain.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
#ifndef FUSEMAIN_H_
#define FUSEMAIN_H_

#include "../../dokan/dokan.h"
#include "fuse.h"
#include "utils.h"
#include <string>
#include <vector>
#include <memory>
#include <map>

#define CHECKED(arg) if (0);else {int __res=arg; if (__res<0) return __res;}
#define MAX_READ_SIZE (65536)

class impl_fuse_context;
struct impl_chain_link;

class impl_file_handle;
class impl_file_lock;

class impl_file_locks
{
private:
typedef std::map<std::string, impl_file_lock *> file_locks_t;
file_locks_t file_locks;
CRITICAL_SECTION lock;
public:
impl_file_locks() { InitializeCriticalSection(&lock); }
~impl_file_locks() { DeleteCriticalSection(&lock); };
int get_file(const std::string &name, bool is_dir, DWORD access_mode, DWORD shared_mode, std::unique_ptr<impl_file_handle>& out);
void renamed_file(const std::string &name,const std::string &new_name);
void remove_file(const std::string& name);
};

struct impl_chain_link
{
impl_chain_link *prev_link_;
fuse_context call_ctx_;
impl_chain_link() : prev_link_(nullptr) { memset(&call_ctx_, 0, sizeof(call_ctx_)); }
};

/*
This class pushes the impl_fuse_context frame on a thread-local stack,
this allows to have reentrant FUSE filesystem (if anyone really wants
it one day...)
*/
class impl_chain_guard
{
impl_chain_link link;
public:
impl_chain_guard(impl_fuse_context* ctx, int caller_pid);
~impl_chain_guard();
};

class win_error
{
public:
win_error(int _err): err(errno_to_ntstatus_error(_err)) {}
win_error(int _err, bool): err(_err) {}
operator int() { return err; }
private:
int err;
};
/*
FUSE filesystem context
*/
class impl_fuse_context
{
friend class impl_chain_guard;

struct fuse_operations ops_;
fuse_conn_info conn_info_;
void *user_data_;
bool debug_;

unsigned int filemask_;
unsigned int dirmask_;
const char *fsname_, *volname_;

impl_file_locks file_locks;
public:
impl_fuse_context(const struct fuse_operations *ops, void *user_data,
bool debug, unsigned int filemask, unsigned int dirmask,
const char *fsname, const char *volname);

bool debug() const {return debug_;}

////////////////////////////////////Methods///////////////////////////////
static int cast_from_longlong(LONGLONG src, FUSE_OFF_T *res);

int do_open_dir(LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo);

int do_open_file(LPCWSTR FileName, DWORD share_mode, DWORD Flags, PDOKAN_FILE_INFO DokanFileInfo);

int do_create_file(LPCWSTR FileName, DWORD Disposition, DWORD share_mode, DWORD Flags,
PDOKAN_FILE_INFO DokanFileInfo);

int do_delete_directory(LPCWSTR file_name, PDOKAN_FILE_INFO dokan_file_info);

int do_delete_file(LPCWSTR file_name, PDOKAN_FILE_INFO dokan_file_info);

int convert_flags(DWORD Flags);

int resolve_symlink(const std::string &name, std::string *res);
int check_and_resolve(std::string *name);

struct walk_data
{
impl_fuse_context *ctx;
std::string dirname;
PDOKAN_FILE_INFO DokanFileInfo;
PFillFindData delegate;
std::vector<std::string> getdir_data; //Used only in walk_directory_getdir()
};
static int walk_directory(void *buf, const char *name,
const struct FUSE_STAT *stbuf, FUSE_OFF_T off);
static int walk_directory_getdir(fuse_dirh_t hndl, const char *name, int type,ino_t ino);

///////////////////////////////////Delegates//////////////////////////////
int find_files(LPCWSTR file_name, PFillFindData fill_find_data,
PDOKAN_FILE_INFO dokan_file_info);

int open_directory(LPCWSTR file_name, PDOKAN_FILE_INFO dokan_file_info);

int cleanup(LPCWSTR file_name, PDOKAN_FILE_INFO dokan_file_info);

int create_directory(LPCWSTR file_name, PDOKAN_FILE_INFO dokan_file_info);

int delete_directory(LPCWSTR file_name, PDOKAN_FILE_INFO dokan_file_info);

win_error create_file(LPCWSTR file_name, DWORD access_mode, DWORD share_mode,
DWORD creation_disposition, DWORD flags_and_attributes,
PDOKAN_FILE_INFO dokan_file_info);

int close_file(LPCWSTR file_name, PDOKAN_FILE_INFO dokan_file_info);

int read_file(LPCWSTR file_name, LPVOID buffer, DWORD num_bytes_to_read,
LPDWORD read_bytes, LONGLONG offset, PDOKAN_FILE_INFO dokan_file_info);

int write_file(LPCWSTR file_name, LPCVOID buffer,
DWORD num_bytes_to_write,LPDWORD num_bytes_written,
LONGLONG offset, PDOKAN_FILE_INFO dokan_file_info);

int flush_file_buffers(LPCWSTR file_name,
PDOKAN_FILE_INFO dokan_file_info);

int get_file_information(LPCWSTR file_name,
LPBY_HANDLE_FILE_INFORMATION handle_file_information,
PDOKAN_FILE_INFO dokan_file_info);

int delete_file(LPCWSTR file_name, PDOKAN_FILE_INFO dokan_file_info);

int move_file(LPCWSTR file_name, LPCWSTR new_file_name,
BOOL replace_existing, PDOKAN_FILE_INFO dokan_file_info);

int lock_file(LPCWSTR file_name, LONGLONG byte_offset, LONGLONG length,
PDOKAN_FILE_INFO dokan_file_info);

int unlock_file(LPCWSTR file_name, LONGLONG byte_offset, LONGLONG length,
PDOKAN_FILE_INFO dokan_file_info);

int set_end_of_file(LPCWSTR file_name, LONGLONG byte_offset,
PDOKAN_FILE_INFO dokan_file_info);

int set_file_attributes(LPCWSTR file_name, DWORD file_attributes,
PDOKAN_FILE_INFO dokan_file_info);

int helper_set_time_struct(const FILETIME* filetime, const time_t backup,
time_t *dest);

int set_file_time(PCWSTR file_name, const FILETIME* creation_time,
const FILETIME* last_access_time, const FILETIME* last_write_time,
PDOKAN_FILE_INFO dokan_file_info);

int get_disk_free_space(PULONGLONG free_bytes_available,
PULONGLONG number_of_bytes, PULONGLONG number_of_free_bytes,
PDOKAN_FILE_INFO dokan_file_info);

int get_volume_information(LPWSTR volume_name_buffer,DWORD volume_name_size,
LPWSTR file_system_name_buffer, DWORD file_system_name_size,
PDOKAN_FILE_INFO dokan_file_info, LPDWORD volume_flags);

int mounted(PDOKAN_FILE_INFO DokanFileInfo);

int unmounted(PDOKAN_FILE_INFO DokanFileInfo);
};


class impl_file_lock
{
friend class impl_file_handle;
friend class impl_file_locks;
std::string name_;
impl_file_locks* locks;
impl_file_handle *first;
CRITICAL_SECTION lock;

void add_file_unlocked(impl_file_handle *file);
int lock_file(impl_file_handle *file, long long start, long long len, bool mark=true);
int unlock_file(impl_file_handle *file, long long start, long long len);
public:
impl_file_lock(impl_file_locks* _locks, const std::string& name): locks(_locks), name_(name), first(NULL) { InitializeCriticalSection(&lock); }
~impl_file_lock() { DeleteCriticalSection(&lock); };
void remove_file(impl_file_handle *file);
const std::string& get_name() const {return name_;}
};


class impl_file_handle
{
friend class impl_file_lock;
friend class impl_file_locks;
bool is_dir_;
uint64_t fh_;
impl_file_handle *next_file;
impl_file_lock *file_lock;
DWORD shared_mode_;
typedef std::map<long long, long long> locks_t;
locks_t locks;
impl_file_handle(bool is_dir, DWORD shared_mode);
public:
~impl_file_handle();

bool is_dir() const {return is_dir_;}
int close(const struct fuse_operations *ops);
fuse_file_info make_finfo();
const std::string& get_name() const {return file_lock->get_name();}
void set_finfo(const fuse_file_info& finfo) { fh_ = finfo.fh; };
int check_lock(long long start, long long len) { return file_lock->lock_file(this, start, len, false); }
int lock(long long start, long long len) { return file_lock->lock_file(this, start, len); }
int unlock(long long start, long long len) { return file_lock->unlock_file(this, start, len); }
};

#endif // FUSEMAIN_H_
59 changes: 59 additions & 0 deletions dokan_fuse/pkg/opt/include/dokan_fuse/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#ifndef UTILS_H_
#define UTILS_H_

#include <string>
#include <sys/stat.h>
#include "fuse.h"

/*#ifdef _MSC_VER
#define DLLLOCAL
#else
#define DLLLOCAL __attribute__ ((visibility("hidden")))
#endif*/

void utf8_to_wchar_buf_old(const char *src, wchar_t *res, int maxlen);
void utf8_to_wchar_buf(const char *src, wchar_t *res, int maxlen);
std::string wchar_to_utf8_cstr(const wchar_t *str);

std::string unixify(const std::string &str);
std::string extract_file_name(const std::string &str);
std::string extract_dir_name(const std::string &str);

FILETIME unixTimeToFiletime(time_t t);
time_t filetimeToUnixTime(const FILETIME *ft);
bool is_filetime_set(const FILETIME *ft);

template<class T> void convertStatlikeBuf(const struct FUSE_STAT *stbuf, const std::string &name,
T * find_data)
{
if (stbuf==NULL) return;

if ((stbuf->st_mode&S_IFDIR)==S_IFDIR)
find_data->dwFileAttributes=FILE_ATTRIBUTE_DIRECTORY;
else
find_data->dwFileAttributes=FILE_ATTRIBUTE_NORMAL;

#ifndef WIDE_OFF_T
find_data->nFileSizeLow=stbuf->st_size;
#else
//Support 64 sizes
find_data->nFileSizeLow=(DWORD) stbuf->st_size;
find_data->nFileSizeHigh=stbuf->st_size>>32;
#endif
if (stbuf->st_ctim.tv_sec!=0)
find_data->ftCreationTime=unixTimeToFiletime(stbuf->st_ctim.tv_sec);
if (stbuf->st_atim.tv_sec!=0)
find_data->ftLastAccessTime=unixTimeToFiletime(stbuf->st_atim.tv_sec);
if (stbuf->st_mtim.tv_sec!=0)
find_data->ftLastWriteTime=unixTimeToFiletime(stbuf->st_mtim.tv_sec);

//Partial support for read-only files - currently done for a files without write permission only
if (!(stbuf->st_mode&0222))
find_data->dwFileAttributes|=FILE_ATTRIBUTE_READONLY;
//TODO: add full support for read-only files - try to derive it from file's owner?
std::string fname=extract_file_name(name);
if (!fname.empty() && fname.at(0)=='.') //UNIX hidden files
find_data->dwFileAttributes|=FILE_ATTRIBUTE_HIDDEN;
}

#endif // UTILS_H_
10 changes: 10 additions & 0 deletions dokan_fuse/pkg/usr/lib/pkgconfig/fuse.pc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
prefix=/opt
exec_prefix=${prefix}
libdir=${exec_prefix}/bin
includedir=${prefix}/include

Name: fuse
Description: A wrapper library that makes Dokan compatible with FUSE API
Version: 2.7
Libs: -L${libdir} -ldokanfuse1
Cflags: -I${includedir}/dokan_fuse