Skip to content

Commit

Permalink
keep original scope when reinterpreting char* as ByteBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Aug 22, 2023
1 parent 4a9c6a7 commit f37635d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,20 @@ private int getattr(MemorySegment path, MemorySegment stat, MemorySegment fi) {

@VisibleForTesting
int getxattr(MemorySegment path, MemorySegment name, MemorySegment value, long size) {
try (var arena = Arena.ofConfined()) {
var val = value.reinterpret(size, arena, null).asByteBuffer();
return fuseOperations.getxattr(path.getUtf8String(0), name.getUtf8String(0), val);
}
var val = value.reinterpret(size).asByteBuffer();
return fuseOperations.getxattr(path.getUtf8String(0), name.getUtf8String(0), val);
}

@VisibleForTesting
int setxattr(MemorySegment path, MemorySegment name, MemorySegment value, long size, int flags) {
try (var arena = Arena.ofConfined()) {
var val = value.reinterpret(size, arena, null).asByteBuffer();
return fuseOperations.setxattr(path.getUtf8String(0), name.getUtf8String(0), val, flags);
}
var val = value.reinterpret(size).asByteBuffer();
return fuseOperations.setxattr(path.getUtf8String(0), name.getUtf8String(0), val, flags);
}

@VisibleForTesting
int listxattr(MemorySegment path, MemorySegment value, long size) {
try (var arena = Arena.ofConfined()) {
var val = value.reinterpret(size, arena, null).asByteBuffer();
return fuseOperations.listxattr(path.getUtf8String(0), val);
}
var val = value.reinterpret(size).asByteBuffer();
return fuseOperations.listxattr(path.getUtf8String(0), val);
}

@VisibleForTesting
Expand All @@ -211,7 +205,7 @@ private int opendir(MemorySegment path, MemorySegment fi) {

private int read(MemorySegment path, MemorySegment buf, long size, long offset, MemorySegment fi) {
try (var arena = Arena.ofConfined()) {
var buffer = buf.reinterpret(size, arena, null).asByteBuffer();
var buffer = buf.reinterpret(size).asByteBuffer();
return fuseOperations.read(path.getUtf8String(0), buffer, size, offset, new FileInfoImpl(fi, arena));
}
}
Expand All @@ -223,10 +217,8 @@ private int readdir(MemorySegment path, MemorySegment buf, MemorySegment filler,
}

private int readlink(MemorySegment path, MemorySegment buf, long len) {
try (var arena = Arena.ofConfined()) {
var buffer = buf.reinterpret(len, arena, null).asByteBuffer();
return fuseOperations.readlink(path.getUtf8String(0), buffer, len);
}
var buffer = buf.reinterpret(len).asByteBuffer();
return fuseOperations.readlink(path.getUtf8String(0), buffer, len);
}

private int release(MemorySegment path, MemorySegment fi) {
Expand Down Expand Up @@ -290,7 +282,7 @@ int utimens(MemorySegment path, MemorySegment times, MemorySegment fi) {

private int write(MemorySegment path, MemorySegment buf, long size, long offset, MemorySegment fi) {
try (var arena = Arena.ofConfined()) {
var buffer = buf.reinterpret(size, arena, null).asByteBuffer();
var buffer = buf.reinterpret(size).asByteBuffer();
return fuseOperations.write(path.getUtf8String(0), buffer, size, offset, new FileInfoImpl(fi, arena));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,26 +166,20 @@ private int getattr(MemorySegment path, MemorySegment stat, MemorySegment fi) {

@VisibleForTesting
int getxattr(MemorySegment path, MemorySegment name, MemorySegment value, long size) {
try (var arena = Arena.ofConfined()) {
var val = value.reinterpret(size, arena, null).asByteBuffer();
return fuseOperations.getxattr(path.getUtf8String(0), name.getUtf8String(0), val);
}
var val = value.reinterpret(size).asByteBuffer();
return fuseOperations.getxattr(path.getUtf8String(0), name.getUtf8String(0), val);
}

@VisibleForTesting
int setxattr(MemorySegment path, MemorySegment name, MemorySegment value, long size, int flags) {
try (var arena = Arena.ofConfined()) {
var val = value.reinterpret(size, arena, null).asByteBuffer();
return fuseOperations.setxattr(path.getUtf8String(0), name.getUtf8String(0), val, flags);
}
var val = value.reinterpret(size).asByteBuffer();
return fuseOperations.setxattr(path.getUtf8String(0), name.getUtf8String(0), val, flags);
}

@VisibleForTesting
int listxattr(MemorySegment path, MemorySegment value, long size) {
try (var arena = Arena.ofConfined()) {
var val = value.reinterpret(size, arena, null).asByteBuffer();
return fuseOperations.listxattr(path.getUtf8String(0), val);
}
var val = value.reinterpret(size).asByteBuffer();
return fuseOperations.listxattr(path.getUtf8String(0), val);
}

@VisibleForTesting
Expand All @@ -211,7 +205,7 @@ private int opendir(MemorySegment path, MemorySegment fi) {

private int read(MemorySegment path, MemorySegment buf, long size, long offset, MemorySegment fi) {
try (var arena = Arena.ofConfined()) {
var buffer = buf.reinterpret(size, arena, null).asByteBuffer();
var buffer = buf.reinterpret(size).asByteBuffer();
return fuseOperations.read(path.getUtf8String(0), buffer, size, offset, new FileInfoImpl(fi, arena));
}
}
Expand All @@ -223,10 +217,8 @@ private int readdir(MemorySegment path, MemorySegment buf, MemorySegment filler,
}

private int readlink(MemorySegment path, MemorySegment buf, long len) {
try (var arena = Arena.ofConfined()) {
var buffer = buf.reinterpret(len, arena, null).asByteBuffer();
return fuseOperations.readlink(path.getUtf8String(0), buffer, len);
}
var buffer = buf.reinterpret(len).asByteBuffer();
return fuseOperations.readlink(path.getUtf8String(0), buffer, len);
}

private int release(MemorySegment path, MemorySegment fi) {
Expand Down Expand Up @@ -289,7 +281,7 @@ int utimens(MemorySegment path, MemorySegment times, MemorySegment fi) {

private int write(MemorySegment path, MemorySegment buf, long size, long offset, MemorySegment fi) {
try (var arena = Arena.ofConfined()) {
var buffer = buf.reinterpret(size, arena, null).asByteBuffer();
var buffer = buf.reinterpret(size).asByteBuffer();
return fuseOperations.write(path.getUtf8String(0), buffer, size, offset, new FileInfoImpl(fi, arena));
}
}
Expand Down
28 changes: 10 additions & 18 deletions jfuse-win/src/main/java/org/cryptomator/jfuse/win/FuseImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,26 +176,20 @@ int getattr(MemorySegment path, MemorySegment stat, MemorySegment fi) {

@VisibleForTesting
int getxattr(MemorySegment path, MemorySegment name, MemorySegment value, long size) {
try (var arena = Arena.ofConfined()) {
var val = value.reinterpret(size, arena, null).asByteBuffer();
return fuseOperations.getxattr(path.getUtf8String(0), name.getUtf8String(0), val);
}
var val = value.reinterpret(size).asByteBuffer();
return fuseOperations.getxattr(path.getUtf8String(0), name.getUtf8String(0), val);
}

@VisibleForTesting
int setxattr(MemorySegment path, MemorySegment name, MemorySegment value, long size, int flags) {
try (var arena = Arena.ofConfined()) {
var val = value.reinterpret(size, arena, null).asByteBuffer();
return fuseOperations.setxattr(path.getUtf8String(0), name.getUtf8String(0), val, flags);
}
var val = value.reinterpret(size).asByteBuffer();
return fuseOperations.setxattr(path.getUtf8String(0), name.getUtf8String(0), val, flags);
}

@VisibleForTesting
int listxattr(MemorySegment path, MemorySegment value, long size) {
try (var arena = Arena.ofConfined()) {
var val = value.reinterpret(size, arena, null).asByteBuffer();
return fuseOperations.listxattr(path.getUtf8String(0), val);
}
var val = value.reinterpret(size).asByteBuffer();
return fuseOperations.listxattr(path.getUtf8String(0), val);
}

@VisibleForTesting
Expand All @@ -221,7 +215,7 @@ private int opendir(MemorySegment path, MemorySegment fi) {

private int read(MemorySegment path, MemorySegment buf, long size, long offset, MemorySegment fi) {
try (var arena = Arena.ofConfined()) {
var buffer = buf.reinterpret(size, arena, null).asByteBuffer();
var buffer = buf.reinterpret(size).asByteBuffer();
return fuseOperations.read(path.getUtf8String(0), buffer, size, offset, new FileInfoImpl(fi, arena));
}
}
Expand All @@ -233,10 +227,8 @@ private int readdir(MemorySegment path, MemorySegment buf, MemorySegment filler,
}

private int readlink(MemorySegment path, MemorySegment buf, long len) {
try (var arena = Arena.ofConfined()) {
var buffer = buf.reinterpret(len, arena, null).asByteBuffer();
return fuseOperations.readlink(path.getUtf8String(0), buffer, len);
}
var buffer = buf.reinterpret(len).asByteBuffer();
return fuseOperations.readlink(path.getUtf8String(0), buffer, len);
}

private int release(MemorySegment path, MemorySegment fi) {
Expand Down Expand Up @@ -295,7 +287,7 @@ int utimens(MemorySegment path, MemorySegment times, MemorySegment fi) {

private int write(MemorySegment path, MemorySegment buf, long size, long offset, MemorySegment fi) {
try (var arena = Arena.ofConfined()) {
var buffer = buf.reinterpret(size, arena, null).asByteBuffer();
var buffer = buf.reinterpret(size).asByteBuffer();
return fuseOperations.write(path.getUtf8String(0), buffer, size, offset, new FileInfoImpl(fi, arena));
}
}
Expand Down

0 comments on commit f37635d

Please sign in to comment.