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

migrated to new JEP 434 API (JDK20) #29

Merged
merged 11 commits into from
Apr 4, 2023
Merged
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
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: 19
java-version: 20
distribution: 'zulu'
cache: 'maven'
- name: Setup fuse
Expand All @@ -35,7 +35,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: 19
java-version: 20
distribution: 'zulu'
cache: 'maven'
- name: Setup fuse
Expand All @@ -59,11 +59,11 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: 19
java-version: 20
distribution: 'zulu'
cache: 'maven'
- name: Setup fuse
run: choco install winfsp --version 1.11.22176 -y
run: choco install winfsp --version 1.12.22339 -y
- name: Maven build
shell: bash # surprise, running maven in pwsh is crappy, see https://stackoverflow.com/q/6347985/4014509
run: mvn -B verify -Dfuse.lib.path="C:\Program Files (x86)\WinFsp\bin\winfsp-x64.dll"
Expand All @@ -83,7 +83,7 @@ jobs:
fetch-depth: 0
- uses: actions/setup-java@v3
with:
java-version: 19
java-version: 20
distribution: 'zulu'
cache: 'maven'
- name: Cache SonarCloud packages
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-central.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
ref: "refs/tags/${{ github.event.inputs.tag }}"
- uses: actions/setup-java@v3
with:
java-version: 19
java-version: 20
distribution: 'zulu'
cache: 'maven'
server-id: ossrh # Value of the distributionManagement/repository/id field of the pom.xml
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: 19
java-version: 20
distribution: 'zulu'
cache: 'maven'
gpg-private-key: ${{ secrets.RELEASES_GPG_PRIVATE_KEY }} # Value of the GPG private key to import
Expand Down
2 changes: 1 addition & 1 deletion .idea/misc.xml

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

3 changes: 1 addition & 2 deletions .idea/runConfigurations/HelloWorldFileSystem.xml

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

3 changes: 1 addition & 2 deletions .idea/runConfigurations/HelloWorldFileSystem__Windows_.xml

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

5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@

# jFUSE

Zero-Dependency Java bindings for FUSE using [JEP 424](https://openjdk.org/jeps/424).
Zero-Dependency Java bindings for FUSE using [JEP 434](https://openjdk.org/jeps/434).

## Status

This is currently an experimental library requiring JDK 19. As long as the [Foreign Function & Memory API](https://openjdk.org/jeps/424) is incubating, the required JDK will increase.
This is currently an experimental library requiring JDK 20. As long as the [Foreign Function & Memory API](https://openjdk.org/jeps/434) is incubating, the required JDK will increase.
Older JDK versions are *not supported*. Please refer to an older version of this lib, if you are interested in using it with an older JDK. Older versions will not receive patches or any kind of support, though!

We attempt to support libfuse 3.x on Linux and Windows while also remaining compatible with libfuse 2.x on macOS, leading to some compromises in the API.

Expand Down
19 changes: 10 additions & 9 deletions jfuse-api/src/main/java/org/cryptomator/jfuse/api/Fuse.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import org.jetbrains.annotations.VisibleForTesting;

import java.io.IOException;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemorySession;
import java.lang.foreign.SegmentAllocator;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -43,7 +43,7 @@ public abstract class Fuse implements AutoCloseable {
/**
* The memory session associated with the lifecycle of this Fuse instance.
*/
protected final MemorySession fuseScope = MemorySession.openShared();
protected final Arena fuseArena = Arena.openShared();

/**
* The file system operations invoked by this FUSE file system.
Expand All @@ -66,7 +66,7 @@ public abstract class Fuse implements AutoCloseable {
*/
protected Fuse(FuseOperations fuseOperations, Function<SegmentAllocator, MemorySegment> structAllocator) {
this.fuseOperations = new MountProbeObserver(fuseOperations, mountProbeSucceeded::countDown);
this.fuseOperationsStruct = structAllocator.apply(fuseScope);
this.fuseOperationsStruct = structAllocator.apply(fuseArena);
fuseOperations.supportedOperations().forEach(this::bind);
}

Expand Down Expand Up @@ -108,7 +108,7 @@ public static FuseBuilder builder() {
@Blocking
@MustBeInvokedByOverriders
public synchronized void mount(String progName, Path mountPoint, String... flags) throws FuseMountFailedException, IllegalArgumentException {
if (!fuseScope.isAlive()) {
if (!fuseArena.scope().isAlive()) {
throw new IllegalStateException("Already closed"); //TODO: throw specialized exception
}

Expand Down Expand Up @@ -156,8 +156,9 @@ void waitForMountingToComplete(Path mountPoint, Future<Integer> fuseLoop) throws
@Blocking
private int fuseLoop(FuseMount mount) {
AtomicInteger result = new AtomicInteger();
fuseScope.whileAlive(() -> {
result.set(mount.loop());
fuseArena.scope().whileAlive(() -> {
int r = mount.loop();
result.set(r);
});
return result.get();
}
Expand All @@ -184,7 +185,7 @@ private int fuseLoop(FuseMount mount) {
@Blocking
@MustBeInvokedByOverriders
public synchronized void close() throws TimeoutException {
if (!fuseScope.isAlive()) {
if (!fuseArena.scope().isAlive()) {
return; // already closed
}
try {
Expand All @@ -199,13 +200,13 @@ public synchronized void close() throws TimeoutException {
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
fuseScope.close();
fuseArena.close();
}
}

/**
* Decorates the {@link FuseOperations#getattr(String, Stat, FileInfo) getattr} call of a FuseOperations object
* in order to detect accesses to {@value MOUNT_PROBE} system during {@link #waitForMountingToComplete(Path)}.
* in order to detect accesses to {@value MOUNT_PROBE} system during {@link #waitForMountingToComplete(Path, Future)}}.
*
* @param delegate The original FuseOperations object
* @param onObserve Handler to invoke as soon as the desired call is detected
Expand Down
80 changes: 40 additions & 40 deletions jfuse-linux-aarch64/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@
<plugin>
<groupId>io.github.coffeelibs</groupId>
<artifactId>jextract-maven-plugin</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
<configuration>
<executable>${user.home}/.sdkman/candidates/java/19.ea.jextract/bin/jextract</executable>
<executable>/Users/sebastian/Documents/Cryptomator/jextract/build/jextract/bin/jextract</executable>
<headerSearchPaths>${linux.headerSearchPath}</headerSearchPaths>
<outputDirectory>${project.build.sourceDirectory}</outputDirectory>
<targetPackage>org.cryptomator.jfuse.linux.aarch64.extr</targetPackage>
Expand Down Expand Up @@ -147,24 +147,24 @@
<configuration>
<headerFile>${linux.headerSearchPath}/errno.h</headerFile>
<headerClassName>errno_h</headerClassName>
<includeMacros>
<includeMacro>ENOENT</includeMacro>
<includeMacro>ENOSYS</includeMacro>
<includeMacro>ENOMEM</includeMacro>
<includeMacro>EACCES</includeMacro>
<includeMacro>EIO</includeMacro>
<includeMacro>EROFS</includeMacro>
<includeMacro>EBADF</includeMacro>
<includeMacro>EEXIST</includeMacro>
<includeMacro>ENOTDIR</includeMacro>
<includeMacro>EISDIR</includeMacro>
<includeMacro>ENOTEMPTY</includeMacro>
<includeMacro>ENOTSUP</includeMacro>
<includeMacro>EINVAL</includeMacro>
<includeMacro>ERANGE</includeMacro>
<includeMacro>ENOLCK</includeMacro>
<includeMacro>ENAMETOOLONG</includeMacro>
</includeMacros>
<includeConstants>
<includeConstant>ENOENT</includeConstant>
<includeConstant>ENOSYS</includeConstant>
<includeConstant>ENOMEM</includeConstant>
<includeConstant>EACCES</includeConstant>
<includeConstant>EIO</includeConstant>
<includeConstant>EROFS</includeConstant>
<includeConstant>EBADF</includeConstant>
<includeConstant>EEXIST</includeConstant>
<includeConstant>ENOTDIR</includeConstant>
<includeConstant>EISDIR</includeConstant>
<includeConstant>ENOTEMPTY</includeConstant>
<includeConstant>ENOTSUP</includeConstant>
<includeConstant>EINVAL</includeConstant>
<includeConstant>ERANGE</includeConstant>
<includeConstant>ENOLCK</includeConstant>
<includeConstant>ENAMETOOLONG</includeConstant>
</includeConstants>
</configuration>
</execution>
<execution>
Expand All @@ -175,10 +175,10 @@
<configuration>
<headerFile>${linux.headerSearchPath}/sys/stat.h</headerFile>
<headerClassName>stat_h</headerClassName>
<includeMacros>
<includeMacro>UTIME_NOW</includeMacro>
<includeMacro>UTIME_OMIT</includeMacro>
</includeMacros>
<includeConstants>
<includeConstant>UTIME_NOW</includeConstant>
<includeConstant>UTIME_OMIT</includeConstant>
</includeConstants>
</configuration>
</execution>
<execution>
Expand All @@ -189,17 +189,17 @@
<configuration>
<headerFile>${linux.headerSearchPath}/fcntl.h</headerFile>
<headerClassName>fcntl_h</headerClassName>
<includeMacros>
<includeMacro>O_RDONLY</includeMacro>
<includeMacro>O_WRONLY</includeMacro>
<includeMacro>O_RDWR</includeMacro>
<includeMacro>O_APPEND</includeMacro>
<includeMacro>O_CREAT</includeMacro>
<includeMacro>O_TRUNC</includeMacro>
<includeMacro>O_EXCL</includeMacro>
<includeMacro>O_DSYNC</includeMacro>
<includeMacro>O_SYNC</includeMacro>
</includeMacros>
<includeConstants>
<includeConstant>O_RDONLY</includeConstant>
<includeConstant>O_WRONLY</includeConstant>
<includeConstant>O_RDWR</includeConstant>
<includeConstant>O_APPEND</includeConstant>
<includeConstant>O_CREAT</includeConstant>
<includeConstant>O_TRUNC</includeConstant>
<includeConstant>O_EXCL</includeConstant>
<includeConstant>O_DSYNC</includeConstant>
<includeConstant>O_SYNC</includeConstant>
</includeConstants>
</configuration>
</execution>
<execution>
Expand All @@ -213,12 +213,12 @@
<cPreprocessorMacros>
<cPreprocessorMacro>_GNU_SOURCE=1</cPreprocessorMacro>
</cPreprocessorMacros>
<includeMacros>
<includeConstants>
<!-- GNU-specific flags for rename: -->
<includeMacro>RENAME_NOREPLACE</includeMacro>
<includeMacro>RENAME_EXCHANGE</includeMacro>
<includeMacro>RENAME_WHITEOUT</includeMacro>
</includeMacros>
<includeConstant>RENAME_NOREPLACE</includeConstant>
<includeConstant>RENAME_EXCHANGE</includeConstant>
<includeConstant>RENAME_WHITEOUT</includeConstant>
</includeConstants>
</configuration>
</execution>
</executions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
import org.cryptomator.jfuse.linux.aarch64.extr.fuse_fill_dir_t;
import org.cryptomator.jfuse.linux.aarch64.extr.stat;

import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemorySession;
import java.lang.foreign.Arena;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.SegmentScope;
import java.util.function.Consumer;

record DirFillerImpl(MemoryAddress buf, fuse_fill_dir_t callback, MemorySession scope) implements DirFiller {
record DirFillerImpl(MemorySegment buf, fuse_fill_dir_t callback, Arena arena) implements DirFiller {

DirFillerImpl(MemoryAddress buf, MemoryAddress callback, MemorySession scope) {
this(buf, fuse_fill_dir_t.ofAddress(callback, scope), scope);
DirFillerImpl(MemorySegment buf, MemorySegment callback, Arena arena) {
this(buf, fuse_fill_dir_t.ofAddress(callback, arena.scope()), arena);
}

@Override
public int fill(String name, Consumer<Stat> statFiller, long offset, int flags) {
var statSegment = stat.allocate(scope);
var statSegment = stat.allocate(arena);
statFiller.accept(new StatImpl(statSegment));
return callback.apply(buf, scope.allocateUtf8String(name).address(), statSegment.address(), offset, flags);
return callback.apply(buf, arena.allocateUtf8String(name), statSegment, offset, flags);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
import org.cryptomator.jfuse.linux.aarch64.extr.fcntl_h;
import org.cryptomator.jfuse.linux.aarch64.extr.fuse_file_info;

import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemorySession;
import java.lang.foreign.SegmentScope;
import java.nio.file.StandardOpenOption;
import java.util.EnumSet;
import java.util.Set;
Expand All @@ -23,7 +22,7 @@ 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();

public FileInfoImpl(MemoryAddress address, MemorySession scope) {
public FileInfoImpl(MemorySegment address, SegmentScope scope) {
this(fuse_file_info.ofAddress(address, scope));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.cryptomator.jfuse.linux.aarch64.extr.fuse_args;
import org.cryptomator.jfuse.linux.aarch64.extr.fuse_cmdline_opts;

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

Expand All @@ -15,7 +14,7 @@ public String toString() {
var argc = fuse_args.argc$get(args);
var argv = fuse_args.argv$get(args);
for (int i = 0; i < argc; i++) {
var cString = argv.getAtIndex(ValueLayout.ADDRESS, i);
var cString = argv.getAtIndex(ValueLayout.ADDRESS.asUnbounded(), i);
sb.append("arg[").append(i).append("] = ").append(cString.getUtf8String(0)).append(", ");
}
sb.append("mountPoint = ").append(mountPoint().getUtf8String(0));
Expand All @@ -24,7 +23,7 @@ public String toString() {
return sb.toString();
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import org.cryptomator.jfuse.api.FuseConfig;
import org.cryptomator.jfuse.linux.aarch64.extr.fuse_config;

import java.lang.foreign.MemoryAddress;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.MemorySession;
import java.lang.foreign.SegmentScope;

record FuseConfigImpl(MemorySegment segment) implements FuseConfig {

public FuseConfigImpl(MemoryAddress address, MemorySession scope) {
public FuseConfigImpl(MemorySegment address, SegmentScope scope) {
this(fuse_config.ofAddress(address, scope));
}

Expand Down
Loading