Skip to content

Commit 1c9a8be

Browse files
Initial Commit
0 parents  commit 1c9a8be

File tree

18 files changed

+1345
-0
lines changed

18 files changed

+1345
-0
lines changed

.gitignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
*.class
2+
3+
# Package Files #
4+
*.jar
5+
*.war
6+
*.ear
7+
8+
# Eclipse Settings Files #
9+
.settings
10+
.project
11+
.classpath
12+
13+
# Maven #
14+
target/
15+
pom.xml.versionsBackup
16+
17+
# IntelliJ Settings Files (https://intellij-support.jetbrains.com/hc/en-us/articles/206544839-How-to-manage-projects-under-Version-Control-Systems) #
18+
.idea/**/workspace.xml
19+
.idea/**/tasks.xml
20+
.idea/dictionaries
21+
.idea/**/libraries/
22+
*.iml

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[submodule "libfuse"]
2+
path = libfuse
3+
url = https://github.com/libfuse/libfuse.git
4+
branch = fuse-2_9_bugfix

.idea/.gitignore

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations/HelloFileSystem.xml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/pom.xml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>fuse-panama</artifactId>
7+
<groupId>de.skymatic</groupId>
8+
<version>0.1.0-SNAPSHOT</version>
9+
</parent>
10+
<modelVersion>4.0.0</modelVersion>
11+
12+
<artifactId>fuse-panama-bindings</artifactId>
13+
14+
<dependencies>
15+
<dependency>
16+
<groupId>de.skymatic</groupId>
17+
<artifactId>fuse</artifactId>
18+
<version>1.0</version>
19+
<scope>system</scope>
20+
<systemPath>${basedir}/../ffi/fuse.jar</systemPath>
21+
</dependency>
22+
23+
<dependency>
24+
<groupId>org.slf4j</groupId>
25+
<artifactId>slf4j-api</artifactId>
26+
<version>1.7.29</version>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.slf4j</groupId>
30+
<artifactId>slf4j-simple</artifactId>
31+
<version>1.7.29</version>
32+
</dependency>
33+
</dependencies>
34+
35+
</project>
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
package de.skymatic.fusepanama;
2+
3+
import java.foreign.Scope;
4+
import java.foreign.memory.Callback;
5+
import java.foreign.memory.Pointer;
6+
import java.lang.reflect.Method;
7+
import java.util.Arrays;
8+
import java.util.Set;
9+
import java.util.stream.Collectors;
10+
11+
import com.github.libfuse.fuse_common_h;
12+
import com.github.libfuse.fuse_h;
13+
import com.github.libfuse.fuse_lib;
14+
import org.slf4j.Logger;
15+
import org.slf4j.LoggerFactory;
16+
17+
public abstract class AbstractFuseFileSystem implements AutoCloseable, FuseOperations {
18+
19+
private static final Logger LOG = LoggerFactory.getLogger(AbstractFuseFileSystem.class);
20+
21+
protected final Scope scope;
22+
protected final fuse_h.fuse_operations fuseOperations;
23+
private final Set<String> notImplementedMethods;
24+
private Pointer<fuse_h.fuse> fuseHandle;
25+
26+
public AbstractFuseFileSystem() {
27+
this.scope = Scope.globalScope().fork();
28+
this.fuseOperations = scope.allocateStruct(fuse_h.fuse_operations.class);
29+
this.notImplementedMethods = Arrays.stream(getClass().getMethods())
30+
.filter(method -> method.getAnnotation(NotImplemented.class) != null)
31+
.map(Method::getName)
32+
.collect(Collectors.toSet());
33+
fuseOperations.getattr$set(allocateIfImplemented("getattr", this::getattr));
34+
fuseOperations.readlink$set(allocateIfImplemented("readlink", this::readlink));
35+
fuseOperations.getdir$set(allocateIfImplemented("getdir", this::getdir));
36+
fuseOperations.mknod$set(allocateIfImplemented("mknod", this::mknod));
37+
fuseOperations.mkdir$set(allocateIfImplemented("mkdir", this::mkdir));
38+
fuseOperations.unlink$set(allocateIfImplemented("unlink", this::unlink));
39+
fuseOperations.rmdir$set(allocateIfImplemented("rmdir", this::rmdir));
40+
fuseOperations.symlink$set(allocateIfImplemented("symlink", this::symlink));
41+
fuseOperations.rename$set(allocateIfImplemented("rename", this::rename));
42+
fuseOperations.link$set(allocateIfImplemented("link", this::link));
43+
fuseOperations.chmod$set(allocateIfImplemented("chmod", this::chmod));
44+
fuseOperations.chown$set(allocateIfImplemented("chown", this::chown));
45+
fuseOperations.truncate$set(allocateIfImplemented("truncate", this::truncate));
46+
fuseOperations.utime$set(allocateIfImplemented("utime", this::utime));
47+
fuseOperations.open$set(allocateIfImplemented("open", this::open));
48+
fuseOperations.read$set(allocateIfImplemented("read", this::read));
49+
fuseOperations.write$set(allocateIfImplemented("write", this::write));
50+
fuseOperations.statfs$set(allocateIfImplemented("statfs", this::statfs));
51+
fuseOperations.flush$set(allocateIfImplemented("flush", this::flush));
52+
fuseOperations.release$set(allocateIfImplemented("release", this::release));
53+
fuseOperations.fsync$set(allocateIfImplemented("fsync", this::fsync));
54+
fuseOperations.setxattr$set(allocateIfImplemented("setxattr", this::setxattr));
55+
fuseOperations.getxattr$set(allocateIfImplemented("getxattr", this::getxattr));
56+
fuseOperations.listxattr$set(allocateIfImplemented("listxattr", this::listxattr));
57+
fuseOperations.removexattr$set(allocateIfImplemented("removexattr", this::removexattr));
58+
fuseOperations.opendir$set(allocateIfImplemented("opendir", this::opendir));
59+
fuseOperations.readdir$set(allocateIfImplemented("readdir", this::readdir));
60+
fuseOperations.releasedir$set(allocateIfImplemented("releasedir", this::releasedir));
61+
fuseOperations.fsyncdir$set(allocateIfImplemented("fsyncdir", this::fsyncdir));
62+
fuseOperations.init$set(allocateIfImplemented("init", this::init));
63+
fuseOperations.destroy$set(allocateIfImplemented("destroy", this::destroy));
64+
fuseOperations.access$set(allocateIfImplemented("access", this::access));
65+
fuseOperations.create$set(allocateIfImplemented("create", this::create));
66+
fuseOperations.ftruncate$set(allocateIfImplemented("ftruncate", this::ftruncate));
67+
fuseOperations.fgetattr$set(allocateIfImplemented("fgetattr", this::fgetattr));
68+
fuseOperations.lock$set(allocateIfImplemented("lock", this::lock));
69+
fuseOperations.utimens$set(allocateIfImplemented("utimens", this::utimens));
70+
fuseOperations.bmap$set(allocateIfImplemented("bmap", this::bmap));
71+
fuseOperations.ioctl$set(allocateIfImplemented("ioctl", this::ioctl));
72+
fuseOperations.poll$set(allocateIfImplemented("poll", this::poll));
73+
fuseOperations.write_buf$set(allocateIfImplemented("writeBuf", this::writeBuf));
74+
fuseOperations.read_buf$set(allocateIfImplemented("readBuf", this::readBuf));
75+
fuseOperations.flock$set(allocateIfImplemented("flock", this::flock));
76+
fuseOperations.fallocate$set(allocateIfImplemented("fallocate", this::fallocate));
77+
}
78+
79+
private <T> Callback<T> allocateIfImplemented(String methodName, T callback) {
80+
if (notImplementedMethods.contains(methodName)) {
81+
return Callback.ofNull();
82+
} else {
83+
return scope.allocateCallback(callback);
84+
}
85+
}
86+
87+
@Override
88+
public Pointer<Void> init(Pointer<fuse_common_h.fuse_conn_info> conn) {
89+
this.fuseHandle = fuse_lib.fuse_get_context().get().fuse$get();
90+
LOG.debug("init()");
91+
return Pointer.ofNull();
92+
}
93+
94+
protected Pointer<fuse_h.fuse> getFuseHandle() {
95+
return fuseHandle;
96+
}
97+
98+
public fuse_h.fuse_operations getFuseOperations() {
99+
return fuseOperations;
100+
}
101+
102+
@Override
103+
public void destroy(Pointer<?> pointer) {
104+
this.fuseHandle = Pointer.ofNull();
105+
LOG.debug("destroy()");
106+
}
107+
108+
@Override
109+
public void close() {
110+
scope.close();
111+
}
112+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package de.skymatic.fusepanama;
2+
3+
/**
4+
* Error codes extracted from
5+
* <a href="https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/asm-generic/errno.h">errno.h (linux)</a>
6+
* and <a href="https://github.com/apple/darwin-xnu/blob/master/bsd/sys/errno.h">errno.h (darwin)</a>
7+
*/
8+
public interface Errno {
9+
10+
boolean IS_MAC = System.getProperty("os.name").toLowerCase().contains("mac");
11+
12+
/**
13+
* No such file or directory
14+
*/
15+
int ENOENT = 2;
16+
17+
/**
18+
* Invalid system call number
19+
*/
20+
int ENOSYS = IS_MAC ? 78 : 38;
21+
}

0 commit comments

Comments
 (0)