forked from facebookarchive/dfuse
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
dfuse is a simple D language wrapper around libfuse. It works both on MacOS and Linux.
- Loading branch information
David Soria Parra
committed
Jul 29, 2014
0 parents
commit 40447bb
Showing
10 changed files
with
934 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
*.o | ||
*.so | ||
*.dylib | ||
simplefs | ||
*.swp | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
Boost Software License - Version 1.0 - August 17th, 2003 | ||
|
||
For dfuse software | ||
|
||
Copyright (c) 2014, Facebook, Inc. | ||
All rights reserved. | ||
|
||
Permission is hereby granted, free of charge, to any person or organization | ||
obtaining a copy of the software and accompanying documentation covered by | ||
this license (the "Software") to use, reproduce, display, distribute, | ||
execute, and transmit the Software, and to prepare derivative works of the | ||
Software, and to permit third-parties to whom the Software is furnished to | ||
do so, all subject to the following: | ||
|
||
The copyright notices in the Software and this entire statement, including | ||
the above license grant, this restriction and the following disclaimer, | ||
must be included in all copies of the Software, in whole or in part, and | ||
all derivative works of the Software, unless such copies or derivative | ||
works are solely in the form of machine-executable object code generated by | ||
a source language processor. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT | ||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE | ||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, | ||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# | ||
# Copyright (c) 2014, Facebook, Inc. | ||
# All rights reserved. | ||
# | ||
# This source code is licensed under the Boost-style license found in the | ||
# LICENSE file in the root directory of this source tree. An additional grant | ||
# of patent rights can be found in the PATENTS file in the same directory. | ||
# | ||
VERSION=0.3.0 | ||
INTERNAL_VERSION=0003 | ||
|
||
product=libdfuse-$(VERSION) | ||
|
||
PREFIX=/usr/local | ||
DMD=dmd | ||
DMDFLAGS= | ||
|
||
sources = source/c/fuse/fuse.d source/c/fuse/common.d source/dfuse/fuse.d | ||
uname := $(shell uname -s) | ||
|
||
# Define variables and buildmodes depending on ENABLE_DEBUG, ENABLE_64BIT and | ||
# operating system. | ||
buildmode=release | ||
ifeq ($(ENABLE_DEBUG),1) | ||
MODE=-debug -g | ||
buildmode=debug | ||
else | ||
MODE=-release -O -inline | ||
buildmode=release | ||
endif | ||
|
||
bitmode=64 | ||
ifeq ($(uname),Darwin) | ||
ifeq ($(ENABLE_64BIT),1) | ||
MODE+=-version=DARWIN_USE_64_BIT_INODE | ||
LIBS=-L-losxfuse | ||
bitmde=64 | ||
else | ||
LIBS=-L-losxfuse_i32 | ||
bitmode=32 | ||
endif | ||
endif | ||
|
||
ifeq ($(uname),Linux) | ||
LIBS=-L-lfuse | ||
bitmode=64 | ||
endif | ||
|
||
# Define build directories and main target for libs | ||
builddir=build/$(buildmode)/$(bitmode) | ||
|
||
ifeq ($(uname),Linux) | ||
artifact=$(builddir)/$(product).so | ||
endif | ||
ifeq ($(uname),Darwin) | ||
artifact=$(builddir)/$(product).dylib | ||
endif | ||
|
||
all:: dfuse | ||
|
||
$(builddir): | ||
mkdir -p $(builddir) | ||
|
||
$(builddir)/$(product).so: $(sources) | ||
$(DMD) -w $(MODE) -shared $(LIBS) -version=$(INTERNAL_VERSION) -of$@ $(sources) | ||
|
||
$(builddir)/$(product).dylib: $(sources) | ||
$(DMD) -w $(MODE) -shared $(LIBS) -version=$(INTERNAL_VERSION) -of$@ $(sources) | ||
|
||
simplefs: example/simplefs.d $(sources) | ||
$(DMD) -w -debug -g $(LIBS) -of$@ example/simplefs.d $(sources) | ||
|
||
examples: simplefs | ||
|
||
dfuse: $(artifact) | ||
|
||
clean: | ||
@(rm simplefs 2>/dev/null || exit 0) | ||
@(rm -r $(artifact) || exit 0) | ||
@(rmdir -p build/ || exit 0) | ||
|
||
.PHONY: dfuse all clean examples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Additional Grant of Patent Rights | ||
|
||
"Software" means the dfuse software distributed by Facebook, Inc. | ||
|
||
Facebook hereby grants you a perpetual, worldwide, royalty-free, | ||
non-exclusive, irrevocable (subject to the termination provision below) | ||
license under any rights in any patent claims owned by Facebook, to make, | ||
have made, use, sell, offer to sell, import, and otherwise transfer the | ||
Software. For avoidance of doubt, no license is granted under Facebook’s | ||
rights in any patent claims that are infringed by (i) modifications to the | ||
Software made by you or a third party, or (ii) the Software in combination | ||
with any software or other technology provided by you or a third party. | ||
|
||
The license granted hereunder will terminate, automatically and without | ||
notice, for anyone that makes any claim (including by filing any lawsuit, | ||
assertion or other action) alleging (a) direct, indirect, or contributory | ||
infringement or inducement to infringe any patent: (i) by Facebook or any | ||
of its subsidiaries or affiliates, whether or not such claim is related | ||
to the Software, (ii) by any party if such claim arises in whole or in | ||
part from any software, product or service of Facebook or any of its | ||
subsidiaries or affiliates, whether or not such claim is related to the | ||
Software, or (iii) by any party relating to the Software; or (b) that | ||
any right in any patent claim of Facebook is invalid or unenforceable. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# dfuse version 0.3.0 | ||
*dfuse* is a [D language binding](http://dlang.org) for the high level | ||
[fuse](http://fuse.sourceforge.net) library. It allows to write a fuse | ||
filesystem for Linux or Mac OS (using [osxfuse](http://osxfuse.github.io)) in D. | ||
|
||
Fuse is a library and kernel extension to write filesystems in userspace. These | ||
filesystems are easy to implement and have access to userland components like | ||
HTTP libraries, etc. For more information about fuse see: http://fuse.sourceforge.net. | ||
|
||
## Examples | ||
A simple filesystems implementing a directory listing can be found in the [examples/](https://github.com/facebook/dfuse/tree/master/example) directory. | ||
You can build the examples using: | ||
```Shell | ||
$ make examples | ||
$ mkdir /mnt/simplefs | ||
$ ./simplefs /mnt/simplefs | ||
``` | ||
|
||
## Implementing a filesystems | ||
dfuse provides a high level interface for libfuse. To implement a filesystem, extend the *Operations* class in the *dfuse.fuse* module: | ||
```D | ||
import dfuse.fuse; | ||
class MyFS : Operations | ||
{ | ||
override void getattr(const(char)[] path, ref stat_t s) | ||
{ | ||
/* implementation */ | ||
throw new FuseException(EOPNOTSUPP); | ||
} | ||
override string[] readdir(const(char)[] path) | ||
{ | ||
return [/*...list of files...*/]; | ||
} | ||
override ulong read(const(char)[] path, ubyte[] buf, ulong offset) | ||
{ | ||
/* implementation */ | ||
throw new FuseException(EOPNOTSUPP); | ||
} | ||
} | ||
``` | ||
|
||
A minimal filesystem implements *Operations.getattr*, *Operations.readdir*, *Operations.read*. See [dfuse/fuse.d](https://github.com/facebook/dfuse/blob/master/dfuse/fuse.d) for implementation specific details. | ||
|
||
To mount a filesystem use a Fuse object and call mount: | ||
```D | ||
import dfuse.fuse; | ||
int main(string[] args) | ||
{ | ||
/* foreground=true, threading=false */ | ||
auto fs = new Fuse("MyFS", true, false); | ||
fs.mount(new MyFS(), "/mnt", ["allow_other"]); | ||
} | ||
``` | ||
|
||
## Requirements | ||
dfuse requires: | ||
* Mac OS X or Linux | ||
* fuse >= 2.8.0 or [osxfuse](http://osxfuse.github.io/) >= 2.6.0 | ||
* DMD/Druntime/Phobos >= 2.065 | ||
|
||
## Building dfuse | ||
dfuse comes with a standard makefile that assumes that DMD (the D-compiler) is | ||
in your $PATH. | ||
|
||
### Linux | ||
In order to compile dfuse on Linux: | ||
```Shell | ||
$ make dfuse | ||
or | ||
$ make dfuse ENABLE_DEBUG=1 | ||
to build a debug version | ||
``` | ||
|
||
### MacOS | ||
MacOS supports two inode sizes which are both supported by OSXfuse, however when | ||
compiling dfuse you have to be aware which OSXfuse should be linked. | ||
|
||
By default dfuse is trying to build with a 32bit inode size and link against | ||
osxfuse_i32 which is part of OSXfuse for compatibility. Please note that your | ||
library itself will still be 64bit on a 64bit system. The setting only affects | ||
the size of the inode. | ||
|
||
To build just run | ||
```Shell | ||
$ make dfuse | ||
``` | ||
|
||
If you want to compile with 64bit inodes you need a at least DMD, Druntime, | ||
Phobos in version 2.066: | ||
```Shell | ||
$ make dfuse ENABLE_64BIT=1 | ||
``` | ||
|
||
## Installing dfuse | ||
At the moment the dfuse makefile doesn't support an install target. It is | ||
recommended to just include the library in a project at this point. | ||
|
||
## How dfuse works | ||
dfuse is a simple D wrapper. It exposes a lowelevel interface to the libfuse C | ||
functions in c/fuse/fuse.d. The lowlevel interface preserves C types. | ||
|
||
A highlevel interface is provided by fs/fuse.d. The D interface initializes fuse filsystems operations structure and installs it's own handlers. Every dfuse handler converts C | ||
types to D types and is trapping FuseExceptions used for error handling. The | ||
handlers keep track of the initialized Operations object and call the | ||
appropriate method once types are converted and pass the result into the D | ||
layer. | ||
|
||
The user facing interface is the *Operations* class in fs/fuse.d. It provides | ||
default implementations for all handlers and every method can be invidually | ||
overwritten to provide an interface. | ||
|
||
## Join the dfuse community | ||
* Website: https://github.com/facebook/dfuse/wiki | ||
* Mailing list: [The D Mailinglist](http://lists.puremagic.com/cgi-bin/mailman/listinfo/digitalmars-d) | ||
* irc: irc.freenode.net #d | ||
|
||
## License | ||
dfuse is Boost-licensed. We also provide an additional patent grant. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
d_library( | ||
name = 'dfuse', | ||
srcs = [ | ||
"fs/fuse.d", | ||
"c/fuse/fuse.d", | ||
"c/fuse/common.d", | ||
], | ||
external_deps = [ | ||
('fuse', '>=2.8.6'), | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (c) 2014, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the Boost-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
* | ||
*/ | ||
import dfuse.fuse; | ||
|
||
import std.algorithm, std.conv, std.stdio; | ||
|
||
/** | ||
* A simple directory listing using dfuse | ||
*/ | ||
class SimpleFS : Operations | ||
{ | ||
override void getattr(const(char)[] path, ref stat_t s) | ||
{ | ||
if (path == "/") | ||
{ | ||
s.st_mode = S_IFDIR | octal!755; | ||
s.st_size = 0; | ||
return; | ||
} | ||
|
||
if (path.among("/a", "/b")) | ||
{ | ||
s.st_mode = S_IFREG | octal!644; | ||
s.st_size = 42; | ||
return; | ||
} | ||
|
||
throw new FuseException(errno.ENOENT); | ||
} | ||
|
||
override string[] readdir(const(char)[] path) | ||
{ | ||
if (path == "/") | ||
{ | ||
return ["a", "b"]; | ||
} | ||
|
||
throw new FuseException(errno.ENOENT); | ||
} | ||
} | ||
|
||
int main(string[] args) | ||
{ | ||
if (args.length != 2) | ||
{ | ||
stderr.writeln("simplefs <MOUNTPOINT>"); | ||
return -1; | ||
} | ||
|
||
stdout.writeln("mounting simplefs"); | ||
|
||
auto fs = new Fuse("SimpleFS", true, false); | ||
fs.mount(new SimpleFS(), args[1], []); | ||
|
||
return 0; | ||
} |
Oops, something went wrong.