Skip to content
Draft
Show file tree
Hide file tree
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public synchronized void mount(String progName, Path mountPoint, String... flags
Thread.currentThread().interrupt();
throw new FuseMountFailedException("Interrupted while waiting for mounting to finish");
} catch (ExecutionException e) {
throw new FuseMountFailedException("Exception when starting fuse_loop. Message: " + e.getCause().getMessage());
throw new FuseMountFailedException("Exception when starting fuse_loop.", e);
} finally {
mount.compareAndSet(lock, UNMOUNTED); // if value is still `lock`, mount has failed.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,14 @@ public FuseMountFailedException(String message) {
super(message);
}

/**
* Constructs a new exception with the specified detail message and cause.
*
* @param message the detail message
* @param cause the cause of the failure
*/
public FuseMountFailedException(String message, Throwable cause) {
super(message, cause);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void main(String[] args) {
}
try (var fuse = builder.build(new PosixMirrorFileSystem(mirrored, builder.errno()))) {
LOG.info("Mounting at {}...", mountPoint);
fuse.mount("jfuse", mountPoint, "-s");
fuse.mount("jfuse", mountPoint, "-s", "-obackend=fskit");
LOG.info("Mounted to {}.", mountPoint);
LOG.info("Enter a anything to unmount...");
System.in.read();
Expand Down
41 changes: 34 additions & 7 deletions jfuse-mac/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<fileset>
<directory>${project.build.sourceDirectory}/org/cryptomator/jfuse/mac/extr</directory>
<includes>
<include>*.java</include>
<include>**/*.java</include>
</includes>
<followSymlinks>false</followSymlinks>
</fileset>
Expand All @@ -94,18 +94,24 @@
<goal>sources</goal>
</goals>
<configuration>
<headerFile>${project.parent.basedir}/libfuse2/include/fuse.h</headerFile>
<targetPackage>org.cryptomator.jfuse.mac.extr.fuse</targetPackage>
<headerFile>/usr/local/include/fuse3/fuse.h</headerFile>
<targetPackage>org.cryptomator.jfuse.mac.extr.fuse3</targetPackage>
<headerClassName>fuse_h</headerClassName>
<cPreprocessorMacros>
<cPreprocessorMacro>_FILE_OFFSET_BITS=64</cPreprocessorMacro>
<cPreprocessorMacro>FUSE_USE_VERSION=29</cPreprocessorMacro>
<cPreprocessorMacro>FUSE_USE_VERSION=317</cPreprocessorMacro>
<cPreprocessorMacro>LIBFUSE_BUILT_WITH_VERSIONED_SYMBOLS=1</cPreprocessorMacro>
</cPreprocessorMacros>
<includeFunctions>
<includeFunction>fuse_parse_cmdline</includeFunction>
<includeFunction>fuse_version</includeFunction>
<includeFunction>fuse_lib_help</includeFunction>
<includeFunction>fuse_mount</includeFunction>
<includeFunction>fuse_new</includeFunction>
<includeFunction>fuse_get_session</includeFunction>
<includeFunction>fuse_loop</includeFunction>
<includeFunction>fuse_loop_cfg_create</includeFunction>
<includeFunction>fuse_loop_cfg_set_clone_fd</includeFunction>
<includeFunction>fuse_loop_cfg_set_max_threads</includeFunction>
<includeFunction>fuse_loop_cfg_destroy</includeFunction>
<includeFunction>fuse_loop_mt</includeFunction>
<includeFunction>fuse_exit</includeFunction>
<includeFunction>fuse_unmount</includeFunction>
Expand All @@ -118,10 +124,31 @@
<includeStruct>fuse_operations</includeStruct>
<includeStruct>fuse_file_info</includeStruct>
<includeStruct>stat</includeStruct>
<includeStruct>statvfs</includeStruct>
<includeStruct>fsid</includeStruct>
<includeStruct>statfs</includeStruct>
<includeStruct>timespec</includeStruct>
<includeStruct>fuse_conn_info</includeStruct>
<includeStruct>fuse_config</includeStruct>
<includeStruct>fuse_args</includeStruct>
<includeStruct>fuse_loop_config_v1</includeStruct>
</includeStructs>
</configuration>
</execution>
<execution>
<id>jextract-fuse-lowlevel</id>
<goals>
<goal>sources</goal>
</goals>
<configuration>
<headerFile>/usr/local/include/fuse3/fuse_lowlevel.h</headerFile>
<targetPackage>org.cryptomator.jfuse.mac.extr.fuse3_lowlevel</targetPackage>
<headerClassName>fuse_lowlevel_h</headerClassName>
<cPreprocessorMacros>
<cPreprocessorMacro>_FILE_OFFSET_BITS=64</cPreprocessorMacro>
<cPreprocessorMacro>FUSE_USE_VERSION=317</cPreprocessorMacro>
</cPreprocessorMacros>
<includeStructs>
<includeStruct>fuse_cmdline_opts</includeStruct>
</includeStructs>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.cryptomator.jfuse.api.DirFiller;
import org.cryptomator.jfuse.api.Stat;
import org.cryptomator.jfuse.mac.extr.fuse.fuse_fill_dir_t;
import org.cryptomator.jfuse.mac.extr.fuse.stat;
import org.cryptomator.jfuse.mac.extr.fuse3.fuse_fill_dir_t;
import org.cryptomator.jfuse.mac.extr.fuse3.stat;

import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
Expand All @@ -15,7 +15,7 @@ record DirFillerImpl(MemorySegment buf, MemorySegment callback, Arena arena) imp
public int fill(String name, Consumer<Stat> statFiller, long offset, int flags) {
var statSegment = stat.allocate(arena);
statFiller.accept(new StatImpl(statSegment));
return fuse_fill_dir_t.invoke(callback, buf, arena.allocateFrom(name), statSegment, offset);
return fuse_fill_dir_t.invoke(callback, buf, arena.allocateFrom(name), statSegment, offset, flags);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import org.cryptomator.jfuse.api.FileInfo;
import org.cryptomator.jfuse.mac.extr.fcntl.fcntl_h;
import org.cryptomator.jfuse.mac.extr.fuse.fuse_file_info;
import org.cryptomator.jfuse.mac.extr.fuse3.fuse_file_info;
import org.jetbrains.annotations.Nullable;

import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.nio.file.StandardOpenOption;
import java.util.EnumSet;
Expand All @@ -22,6 +22,17 @@ record FileInfoImpl(MemorySegment segment) implements FileInfo {
private static final int O_SYNC = fcntl_h.O_SYNC();
private static final int O_DSYNC = fcntl_h.O_DSYNC();

/**
* Null-safe factory method to map native memory to an {@link FileInfo} object
*
* @param address the {@link MemorySegment} representing the starting address
* @return an {@link FileInfo} object or {@code null} if {@code address} is a NULL pointer
*/
@Nullable
public static FileInfoImpl ofNullable(MemorySegment address) {
return MemorySegment.NULL.equals(address) ? null : new FileInfoImpl(address);
}

@Override
public long getFh() {
return fuse_file_info.fh(segment);
Expand Down
31 changes: 27 additions & 4 deletions jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/FuseArgs.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.cryptomator.jfuse.mac;

import org.cryptomator.jfuse.mac.extr.fuse.fuse_args;
import org.cryptomator.jfuse.mac.extr.fuse3.fuse_args;
import org.cryptomator.jfuse.mac.extr.fuse3_lowlevel.fuse_cmdline_opts;

import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;

record FuseArgs(MemorySegment args, MemorySegment mountPoint, boolean multiThreaded) {
record FuseArgs(MemorySegment args, MemorySegment cmdLineOpts) {

@Override
public String toString() {
Expand All @@ -16,8 +17,30 @@ public String toString() {
var cString = argv.getAtIndex(ValueLayout.ADDRESS, i).reinterpret(Long.MAX_VALUE);
sb.append("arg[").append(i).append("] = ").append(cString.getString(0)).append(", ");
}
sb.append("mountPoint = ").append(mountPoint.getString(0)).append(", ");
sb.append("multiThreaded = ").append(multiThreaded);
sb.append("mountPoint = ").append(mountPoint().getString(0));
sb.append("debug = ").append(fuse_cmdline_opts.debug(cmdLineOpts));
sb.append("singlethreaded = ").append(!multithreaded());
return sb.toString();
}

public MemorySegment mountPoint() {
return fuse_cmdline_opts.mountpoint(cmdLineOpts);
}

public boolean multithreaded() {
return fuse_cmdline_opts.singlethread(cmdLineOpts) == 0;
}

public int cloneFd() {
return fuse_cmdline_opts.clone_fd(cmdLineOpts);
}

public int maxIdleThreads() {
return fuse_cmdline_opts.max_idle_threads(cmdLineOpts);
}

public int maxThreads() {
return fuse_cmdline_opts.max_threads(cmdLineOpts);
}

}
120 changes: 120 additions & 0 deletions jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/FuseConfigImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package org.cryptomator.jfuse.mac;

import org.cryptomator.jfuse.api.FuseConfig;
import org.cryptomator.jfuse.mac.extr.fuse3.fuse_config;

import java.lang.foreign.MemorySegment;

record FuseConfigImpl(MemorySegment segment) implements FuseConfig {

@Override
public int setGid() {
return fuse_config.set_gid(segment);
}

@Override
public int gid() {
return fuse_config.gid(segment);
}

@Override
public int setUid() {
return fuse_config.set_uid(segment);
}

@Override
public int uid() {
return fuse_config.uid(segment);
}

@Override
public int setMode() {
return fuse_config.set_mode(segment);
}

@Override
public int umask() {
return fuse_config.umask(segment);
}

@Override
public double entryTimeout() {
return fuse_config.entry_timeout(segment);
}

@Override
public double negativeTimeout() {
return fuse_config.negative_timeout(segment);
}

@Override
public double attrTimeout() {
return fuse_config.attr_timeout(segment);
}

@Override
public int intr() {
return fuse_config.intr(segment);
}

@Override
public int intrSignal() {
return fuse_config.intr_signal(segment);
}

@Override
public int remember() {
return fuse_config.remember(segment);
}

@Override
public int hardRemove() {
return fuse_config.hard_remove(segment);
}

@Override
public int useIno() {
return fuse_config.use_ino(segment);
}

@Override
public int readdirIno() {
return fuse_config.readdir_ino(segment);
}

@Override
public int directIo() {
return fuse_config.direct_io(segment);
}

@Override
public int kernelCache() {
return fuse_config.kernel_cache(segment);
}

@Override
public int autoCache() {
return fuse_config.auto_cache(segment);
}

@Override
public int acAttrTimeoutSet() {
return fuse_config.ac_attr_timeout_set(segment);
}

@Override
public double acAttrTimeout() {
return fuse_config.ac_attr_timeout(segment);
}

@Override
public int nullpathOk() {
return fuse_config.nullpath_ok(segment);
}

@Override
public int noRofdFlush() {
return fuse_config.no_rofd_flush(segment);
}

}
Loading
Loading