diff --git a/.idea/runConfigurations/_template__of_JUnit.xml b/.idea/runConfigurations/_template__of_JUnit.xml new file mode 100644 index 00000000..cde359ec --- /dev/null +++ b/.idea/runConfigurations/_template__of_JUnit.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7f..63c9ab20 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -2,5 +2,9 @@ + + + + \ No newline at end of file diff --git a/jfuse-api/pom.xml b/jfuse-api/pom.xml index 53e571d9..3dc7fbc0 100644 --- a/jfuse-api/pom.xml +++ b/jfuse-api/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.4.0 + 0.4.1 4.0.0 jfuse-api diff --git a/jfuse-examples/pom.xml b/jfuse-examples/pom.xml index 63c1d88b..be015173 100644 --- a/jfuse-examples/pom.xml +++ b/jfuse-examples/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.4.0 + 0.4.1 4.0.0 jfuse-examples diff --git a/jfuse-linux-aarch64/pom.xml b/jfuse-linux-aarch64/pom.xml index 72abb49b..0aa75f6e 100644 --- a/jfuse-linux-aarch64/pom.xml +++ b/jfuse-linux-aarch64/pom.xml @@ -5,7 +5,7 @@ jfuse-parent org.cryptomator - 0.4.0 + 0.4.1 4.0.0 jfuse-linux-aarch64 diff --git a/jfuse-linux-amd64/pom.xml b/jfuse-linux-amd64/pom.xml index 4a010077..b124c530 100644 --- a/jfuse-linux-amd64/pom.xml +++ b/jfuse-linux-amd64/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.4.0 + 0.4.1 4.0.0 jfuse-linux-amd64 diff --git a/jfuse-mac/pom.xml b/jfuse-mac/pom.xml index df6ac927..77453e67 100644 --- a/jfuse-mac/pom.xml +++ b/jfuse-mac/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.4.0 + 0.4.1 4.0.0 jfuse-mac diff --git a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java index c1a047f7..243041cb 100644 --- a/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java +++ b/jfuse-mac/src/main/java/org/cryptomator/jfuse/mac/StatvfsImpl.java @@ -9,6 +9,8 @@ record StatvfsImpl(MemorySegment segment) implements Statvfs { + private static final long MAX_UINT = 0xFFFFFFFFL; + public StatvfsImpl(MemoryAddress address, MemorySession scope) { this(statvfs.ofAddress(address, scope)); } @@ -35,44 +37,32 @@ public void setFrsize(long frsize) { @Override public long getBlocks() { - return statvfs.f_blocks$get(segment); + return Integer.toUnsignedLong(statvfs.f_blocks$get(segment)); } @Override public void setBlocks(long blocks) { - if (blocks > Integer.MAX_VALUE) { - throw new IllegalArgumentException("Max supported number of blocks: " + Integer.MAX_VALUE); - } else { - statvfs.f_blocks$set(segment, (int) blocks); - } + statvfs.f_blocks$set(segment,(int) Math.min(MAX_UINT, blocks)); } @Override public long getBfree() { - return statvfs.f_bfree$get(segment); + return Integer.toUnsignedLong(statvfs.f_bfree$get(segment)); } @Override public void setBfree(long bfree) { - if (bfree > Integer.MAX_VALUE) { - throw new IllegalArgumentException("Max supported number of blocks: " + Integer.MAX_VALUE); - } else { - statvfs.f_bfree$set(segment, (int) bfree); - } + statvfs.f_bfree$set(segment,(int) Math.min(MAX_UINT, bfree)); } @Override public long getBavail() { - return statvfs.f_bavail$get(segment); + return Integer.toUnsignedLong(statvfs.f_bavail$get(segment)); } @Override public void setBavail(long bavail) { - if (bavail > Integer.MAX_VALUE) { - throw new IllegalArgumentException("Max supported number of blocks: " + Integer.MAX_VALUE); - } else { - statvfs.f_bavail$set(segment, (int) bavail); - } + statvfs.f_bavail$set(segment,(int) Math.min(MAX_UINT, bavail)); } @Override diff --git a/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java new file mode 100644 index 00000000..909f2930 --- /dev/null +++ b/jfuse-mac/src/test/java/org/cryptomator/jfuse/mac/StatvfsImplTest.java @@ -0,0 +1,96 @@ +package org.cryptomator.jfuse.mac; + +import org.cryptomator.jfuse.api.Statvfs; +import org.cryptomator.jfuse.mac.extr.statvfs; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Named; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +import java.lang.foreign.MemorySegment; +import java.lang.foreign.MemorySession; +import java.util.function.BiConsumer; +import java.util.function.Function; +import java.util.stream.Stream; + +public class StatvfsImplTest { + + @DisplayName("test getters") + @ParameterizedTest(name = "{1}") + @MethodSource + public void testGetters(SetInMemorySegment setter, GetInStatvfs getter, Number value, long expected) { + try (var scope = MemorySession.openConfined()) { + var segment = statvfs.allocate(scope); + var statvfs = new StatvfsImpl(segment.address(), scope); + + setter.accept(segment, value); + + Assertions.assertEquals(expected, getter.apply(statvfs).longValue()); + } + } + + public static Stream testGetters() { + return Stream.of( + Arguments.arguments((SetInMemorySegment) statvfs::f_bsize$set, Named.of("getBsize()", (GetInStatvfs) Statvfs::getBsize), 42L, 42L), + Arguments.arguments((SetInMemorySegment) statvfs::f_frsize$set, Named.of("getFrsize()", (GetInStatvfs) Statvfs::getFrsize), 42L, 42L), + Arguments.arguments((SetInMemorySegment) statvfs::f_namemax$set, Named.of("getNameMax()", (GetInStatvfs) Statvfs::getNameMax), 42L, 42L), + + Arguments.arguments((SetInMemorySegment) statvfs::f_blocks$set, Named.of("getBlocks() with memory containing value < INT32", (GetInStatvfs) Statvfs::getBlocks), 42, 42L), + Arguments.arguments((SetInMemorySegment) statvfs::f_bfree$set, Named.of("getBfree() with memory containing value < INT32", (GetInStatvfs) Statvfs::getBfree), 42, 42L), + Arguments.arguments((SetInMemorySegment) statvfs::f_bavail$set, Named.of("getBavail() with memory containing value < INT32", (GetInStatvfs) Statvfs::getBavail), 42, 42L), + + Arguments.arguments((SetInMemorySegment) statvfs::f_blocks$set, Named.of("getBlocks() with memory containing value < UINT32", (GetInStatvfs) Statvfs::getBlocks), 0xFFFFFFD6, 0x00000000_FFFFFFD6L), + Arguments.arguments((SetInMemorySegment) statvfs::f_bfree$set, Named.of("getBfree() with memory containing value < UINT32", (GetInStatvfs) Statvfs::getBfree), 0xFFFFFFD6, 0x00000000_FFFFFFD6L), + Arguments.arguments((SetInMemorySegment) statvfs::f_bavail$set, Named.of("getBavail() with memory containing value < UINT32", (GetInStatvfs) Statvfs::getBavail), 0xFFFFFFD6, 0x00000000_FFFFFFD6L) + ); + } + + private interface SetInMemorySegment extends BiConsumer { + } + + private interface GetInStatvfs extends Function { + } + + @DisplayName("test setters") + @ParameterizedTest(name = "{0}") + @MethodSource + public void testSetters(SetInStatvfs setter, GetInMemorySegment getter, Number value, long expected) { + try (var scope = MemorySession.openConfined()) { + var segment = statvfs.allocate(scope); + var statvfs = new StatvfsImpl(segment.address(), scope); + + setter.accept(statvfs, value.longValue()); + + Assertions.assertEquals(expected, getter.apply(segment).longValue()); + } + } + + public static Stream testSetters() { + return Stream.of( + Arguments.arguments(Named.of("setBsize()", (SetInStatvfs) Statvfs::setBsize), (GetInMemorySegment) statvfs::f_bsize$get, 42L, 42L), + Arguments.arguments(Named.of("setFrsize()", (SetInStatvfs) Statvfs::setFrsize), (GetInMemorySegment) statvfs::f_frsize$get, 42L, 42L), + Arguments.arguments(Named.of("setNameMax()", (SetInStatvfs) Statvfs::setNameMax), (GetInMemorySegment) statvfs::f_namemax$get, 42L, 42L), + + Arguments.arguments(Named.of("setBlocks(i) with i < INT32", (SetInStatvfs) Statvfs::setBlocks), (GetInMemorySegment) statvfs::f_blocks$get, 42, 42), + Arguments.arguments(Named.of("setBfree(i) with i < INT32", (SetInStatvfs) Statvfs::setBfree), (GetInMemorySegment) statvfs::f_bfree$get, 42, 42), + Arguments.arguments(Named.of("setBavail(i) with i < INT32", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, 42, 42), + + Arguments.arguments(Named.of("setBlocks(i) with i > INT32", (SetInStatvfs) Statvfs::setBlocks), (GetInMemorySegment) statvfs::f_blocks$get, 0xFFFFFFD6, 0xFFFFFFD6), + Arguments.arguments(Named.of("setBfree(i) with i > INT32", (SetInStatvfs) Statvfs::setBfree), (GetInMemorySegment) statvfs::f_bfree$get, 0xFFFFFFD6, 0xFFFFFFD6), + Arguments.arguments(Named.of("setBavail(i) with i > INT32", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, 0xFFFFFFD6, 0xFFFFFFD6), + + Arguments.arguments(Named.of("setBlocks(i) with i > UINT32", (SetInStatvfs) Statvfs::setBlocks), (GetInMemorySegment) statvfs::f_blocks$get, 0x01234567_89ABCDEFL, 0xFFFFFFFF), + Arguments.arguments(Named.of("setBfree(i) with i > UINT32", (SetInStatvfs) Statvfs::setBfree), (GetInMemorySegment) statvfs::f_bfree$get, 0x01234567_89ABCDEFL, 0xFFFFFFFF), + Arguments.arguments(Named.of("setBavail(i) with i > UINT32", (SetInStatvfs) Statvfs::setBavail), (GetInMemorySegment) statvfs::f_bavail$get, 0x01234567_89ABCDEFL, 0xFFFFFFFF) + ); + } + + + private interface SetInStatvfs extends BiConsumer { + } + + private interface GetInMemorySegment extends Function { + } +} diff --git a/jfuse-tests/pom.xml b/jfuse-tests/pom.xml index 5acb0b07..683a628a 100644 --- a/jfuse-tests/pom.xml +++ b/jfuse-tests/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.4.0 + 0.4.1 4.0.0 jfuse-tests diff --git a/jfuse-win/pom.xml b/jfuse-win/pom.xml index 9ba8e5b3..d8707f30 100644 --- a/jfuse-win/pom.xml +++ b/jfuse-win/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.4.0 + 0.4.1 4.0.0 jfuse-win diff --git a/jfuse/pom.xml b/jfuse/pom.xml index 3f8f49f2..f72c304a 100644 --- a/jfuse/pom.xml +++ b/jfuse/pom.xml @@ -5,7 +5,7 @@ org.cryptomator jfuse-parent - 0.4.0 + 0.4.1 4.0.0 jfuse diff --git a/pom.xml b/pom.xml index 06cbdf49..3e8a0160 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.cryptomator jfuse-parent pom - 0.4.0 + 0.4.1 jFUSE Java bindings for FUSE using foreign functions & memory API https://github.com/cryptomator/jfuse