Skip to content

Commit

Permalink
Merge branch 'release/0.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed Feb 16, 2023
2 parents a6b6e19 + c768ce6 commit 7844848
Show file tree
Hide file tree
Showing 32 changed files with 786 additions and 43 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ Not all [`fuse_operations`](https://libfuse.github.io/doxygen/structfuse__operat
| flush | :white_check_mark: |
| release | :white_check_mark: |
| fsync | :white_check_mark: |
| setxattr | :x: |
| getxattr | :x: |
| listxattr | :x: |
| removexattr | :x: |
| setxattr | :white_check_mark: |
| getxattr | :white_check_mark: |
| listxattr | :white_check_mark: |
| removexattr | :white_check_mark: |
| opendir | :white_check_mark: |
| readdir | :white_check_mark: |
| releasedir | :white_check_mark: |
Expand Down
2 changes: 1 addition & 1 deletion jfuse-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.cryptomator</groupId>
<artifactId>jfuse-parent</artifactId>
<version>0.3.3</version>
<version>0.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jfuse-api</artifactId>
Expand Down
29 changes: 29 additions & 0 deletions jfuse-api/src/main/java/org/cryptomator/jfuse/api/Errno.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,40 @@ public interface Errno {
*/
int enotempty();

/**
* Operation not supported
*
* @return error constant {@code ENOTSUP}
*/
int enotsup();

/**
* Invalid argument
*
* @return error constant {@code EINVAL}
*/
int einval();

/**
* Result too large
*
* @return error constant {@code ERANGE}
*/
int erange();


/**
* No locks available
*
* @return error constant {@code ENOLCK}
*/
int enolck();

/**
* Filename too long
*
* @return error constant {@code ENAMETOOLONG}
*/
int enametoolong();

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ enum Operation {
FSYNC,
FSYNCDIR,
GET_ATTR,
GET_XATTR,
INIT,
LIST_XATTR,
MKDIR,
OPEN,
OPEN_DIR,
Expand All @@ -32,8 +34,10 @@ enum Operation {
READ_DIR,
RELEASE,
RELEASE_DIR,
REMOVE_XATTR,
RENAME,
RMDIR,
SET_XATTR,
STATFS,
SYMLINK,
TRUNCATE,
Expand Down Expand Up @@ -404,12 +408,11 @@ default int fsync(String path, int datasync, FileInfo fi) {
* @param path file path
* @param name attribute name
* @param value attribute value
* @param size number of bytes of the value TODO: can this be combined with the value buffer?
* @param flags defaults to zero, which creates <em>or</em> replaces the attribute. For fine-grained atomic control,
* <code>XATTR_CREATE</code> or <code>XATTR_REPLACE</code> may be used.
* @return 0 on success or negated error code (-errno)
*/
default int setxattr(String path, String name, ByteBuffer value, long size, int flags) {
default int setxattr(String path, String name, ByteBuffer value, int flags) {
return -errno().enosys();
}

Expand All @@ -418,23 +421,21 @@ default int setxattr(String path, String name, ByteBuffer value, long size, int
*
* @param path file path
* @param name attribute name
* @param value attribute value
* @param size size of the value buffer TODO: can this be combined with the value buffer?
* @param value attribute value. If buffer capacity is zero, return the size of the value
* @return the non-negative value size or negated error code (-errno)
*/
default int getxattr(String path, String name, ByteBuffer value, long size) {
default int getxattr(String path, String name, ByteBuffer value) {
return -errno().enosys();
}

/**
* List extended attributes
*
* @param path file path
* @param list consecutive list of null-terminated attribute names (as many as fit into the buffer)
* @param size size of the list buffer TODO: can this be combined with the value buffer?
* @return the non-negative list size or negated error code (-errno)
* @param list consecutive list of null-terminated attribute names (as many as fit into the buffer). If buffer capacity is zero, return the size of the list
* @return the non-negative number of bytes written to the list buffer or negated error code (-errno)
*/
default int listxattr(String path, ByteBuffer list, long size) {
default int listxattr(String path, ByteBuffer list) {
return -errno().enosys();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ default int getattr(String path, Stat stat, @Nullable FileInfo fi) {
return delegate().getattr(path, stat, fi);
}

@Override
default int getxattr(String path, String name, ByteBuffer value) {
return delegate().getxattr(path, name, value);
}

@Override
default int setxattr(String path, String name, ByteBuffer value, int flags) {
return delegate().setxattr(path, name, value, flags);
}

@Override
default int listxattr(String path, ByteBuffer list) {
return delegate().listxattr(path, list);
}

@Override
default int removexattr(String path, String name) {
return delegate().removexattr(path, name);
}

@Override
default int readlink(String path, ByteBuffer buf, long len) {
return delegate().readlink(path, buf, len);
Expand Down
2 changes: 1 addition & 1 deletion jfuse-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.cryptomator</groupId>
<artifactId>jfuse-parent</artifactId>
<version>0.3.3</version>
<version>0.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jfuse-examples</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.nio.file.attribute.PosixFileAttributes;
import java.nio.file.attribute.PosixFilePermission;
import java.nio.file.attribute.PosixFilePermissions;
import java.nio.file.attribute.UserDefinedFileAttributeView;
import java.util.EnumSet;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -79,7 +80,9 @@ public Set<FuseOperations.Operation> supportedOperations() {
FuseOperations.Operation.FSYNC,
FuseOperations.Operation.FSYNCDIR,
FuseOperations.Operation.GET_ATTR,
FuseOperations.Operation.GET_XATTR,
FuseOperations.Operation.INIT,
FuseOperations.Operation.LIST_XATTR,
FuseOperations.Operation.MKDIR,
FuseOperations.Operation.OPEN_DIR,
FuseOperations.Operation.READ_DIR,
Expand All @@ -90,6 +93,8 @@ public Set<FuseOperations.Operation> supportedOperations() {
FuseOperations.Operation.READ,
FuseOperations.Operation.READLINK,
FuseOperations.Operation.RELEASE,
FuseOperations.Operation.REMOVE_XATTR,
FuseOperations.Operation.SET_XATTR,
FuseOperations.Operation.STATFS,
FuseOperations.Operation.SYMLINK,
FuseOperations.Operation.TRUNCATE,
Expand Down Expand Up @@ -194,6 +199,96 @@ public int getattr(String path, Stat stat, FileInfo fi) {
}
}

@Override
public int getxattr(String path, String name, ByteBuffer value) {
LOG.trace("getxattr {} {}", path, name);
Path node = resolvePath(path);
try {
var xattr = Files.getFileAttributeView(node, UserDefinedFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
if (xattr == null) {
return -errno.enotsup();
}
int size = xattr.size(name);
if (value.capacity() == 0) {
return size;
} else if (value.remaining() < size) {
return -errno.erange();
} else {
return xattr.read(name, value);
}
} catch (NoSuchFileException e) {
return -errno.enoent();
} catch (IOException e) {
return -errno.eio();
}
}

@Override
public int setxattr(String path, String name, ByteBuffer value, int flags) {
LOG.trace("setxattr {} {}", path, name);
Path node = resolvePath(path);
try {
var xattr = Files.getFileAttributeView(node, UserDefinedFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
if (xattr == null) {
return -errno.enotsup();
}
xattr.write(name, value);
return 0;
} catch (NoSuchFileException e) {
return -errno.enoent();
} catch (IOException e) {
return -errno.eio();
}
}

@Override
public int listxattr(String path, ByteBuffer list) {
LOG.trace("listxattr {}", path);
Path node = resolvePath(path);
try {
var xattr = Files.getFileAttributeView(node, UserDefinedFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
if (xattr == null) {
return -errno.enotsup();
}
var names = xattr.list();
if (list.capacity() == 0) {
var contentBytes = xattr.list().stream().map(StandardCharsets.UTF_8::encode).mapToInt(ByteBuffer::remaining).sum();
var nulBytes = names.size();
return contentBytes + nulBytes; // attr1\0aattr2\0attr3\0
} else {
int startpos = list.position();
for (var name : names) {
list.put(StandardCharsets.UTF_8.encode(name)).put((byte) 0x00);
}
return list.position() - startpos;
}
} catch (BufferOverflowException e) {
return -errno.erange();
} catch (NoSuchFileException e) {
return -errno.enoent();
} catch (IOException e) {
return -errno.eio();
}
}

@Override
public int removexattr(String path, String name) {
LOG.trace("removexattr {} {}", path, name);
Path node = resolvePath(path);
try {
var xattr = Files.getFileAttributeView(node, UserDefinedFileAttributeView.class, LinkOption.NOFOLLOW_LINKS);
if (xattr == null) {
return -errno.enotsup();
}
xattr.delete(name);
return 0;
} catch (NoSuchFileException e) {
return -errno.enoent();
} catch (IOException e) {
return -errno.eio();
}
}

@SuppressWarnings("OctalInteger")
protected void copyAttrsToStat(BasicFileAttributes attrs, Stat stat) {
if (attrs instanceof PosixFileAttributes posixAttrs) {
Expand Down
6 changes: 5 additions & 1 deletion jfuse-linux-aarch64/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jfuse-parent</artifactId>
<groupId>org.cryptomator</groupId>
<version>0.3.3</version>
<version>0.4.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>jfuse-linux-aarch64</artifactId>
Expand Down Expand Up @@ -159,7 +159,11 @@
<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>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ protected void bind(FuseOperations.Operation operation) {
case FSYNC -> fuse_operations.fsync$set(fuseOperationsStruct, fuse_operations.fsync.allocate(this::fsync, fuseScope).address());
case FSYNCDIR -> fuse_operations.fsyncdir$set(fuseOperationsStruct, fuse_operations.fsyncdir.allocate(this::fsyncdir, fuseScope).address());
case GET_ATTR -> fuse_operations.getattr$set(fuseOperationsStruct, fuse_operations.getattr.allocate(this::getattr, fuseScope).address());
case GET_XATTR -> fuse_operations.getxattr$set(fuseOperationsStruct, fuse_operations.getxattr.allocate(this::getxattr, fuseScope).address());
case LIST_XATTR -> fuse_operations.listxattr$set(fuseOperationsStruct, fuse_operations.listxattr.allocate(this::listxattr, fuseScope).address());
case MKDIR -> fuse_operations.mkdir$set(fuseOperationsStruct, fuse_operations.mkdir.allocate(this::mkdir, fuseScope).address());
case OPEN -> fuse_operations.open$set(fuseOperationsStruct, fuse_operations.open.allocate(this::open, fuseScope).address());
case OPEN_DIR -> fuse_operations.opendir$set(fuseOperationsStruct, fuse_operations.opendir.allocate(this::opendir, fuseScope).address());
Expand All @@ -87,8 +89,10 @@ protected void bind(FuseOperations.Operation operation) {
case READLINK -> fuse_operations.readlink$set(fuseOperationsStruct, fuse_operations.readlink.allocate(this::readlink, fuseScope).address());
case RELEASE -> fuse_operations.release$set(fuseOperationsStruct, fuse_operations.release.allocate(this::release, fuseScope).address());
case RELEASE_DIR -> fuse_operations.releasedir$set(fuseOperationsStruct, fuse_operations.releasedir.allocate(this::releasedir, fuseScope).address());
case REMOVE_XATTR -> fuse_operations.removexattr$set(fuseOperationsStruct, fuse_operations.removexattr.allocate(this::removexattr, fuseScope).address());
case RENAME -> fuse_operations.rename$set(fuseOperationsStruct, fuse_operations.rename.allocate(this::rename, fuseScope).address());
case RMDIR -> fuse_operations.rmdir$set(fuseOperationsStruct, fuse_operations.rmdir.allocate(this::rmdir, fuseScope).address());
case SET_XATTR -> fuse_operations.setxattr$set(fuseOperationsStruct, fuse_operations.setxattr.allocate(this::setxattr, fuseScope).address());
case STATFS -> fuse_operations.statfs$set(fuseOperationsStruct, fuse_operations.statfs.allocate(this::statfs, fuseScope).address());
case SYMLINK -> fuse_operations.symlink$set(fuseOperationsStruct, fuse_operations.symlink.allocate(this::symlink, fuseScope).address());
case TRUNCATE -> fuse_operations.truncate$set(fuseOperationsStruct, fuse_operations.truncate.allocate(this::truncate, fuseScope).address());
Expand Down Expand Up @@ -163,6 +167,32 @@ private int getattr(MemoryAddress path, MemoryAddress stat, MemoryAddress fi) {
}
}

@VisibleForTesting
int getxattr(MemoryAddress path, MemoryAddress name, MemoryAddress value, long size) {
try (var scope = MemorySession.openConfined()) {
return fuseOperations.getxattr(path.getUtf8String(0), name.getUtf8String(0), MemorySegment.ofAddress(value.address(), size, scope).asByteBuffer());
}
}

@VisibleForTesting
int setxattr(MemoryAddress path, MemoryAddress name, MemoryAddress value, long size, int flags) {
try (var scope = MemorySession.openConfined()) {
return fuseOperations.setxattr(path.getUtf8String(0), name.getUtf8String(0), MemorySegment.ofAddress(value.address(), size, scope).asByteBuffer(), flags);
}
}

@VisibleForTesting
int listxattr(MemoryAddress path, MemoryAddress value, long size) {
try (var scope = MemorySession.openConfined()) {
return fuseOperations.listxattr(path.getUtf8String(0), MemorySegment.ofAddress(value.address(), size, scope).asByteBuffer());
}
}

@VisibleForTesting
int removexattr(MemoryAddress path, MemoryAddress name) {
return fuseOperations.removexattr(path.getUtf8String(0), name.getUtf8String(0));
}

private int mkdir(MemoryAddress path, int mode) {
return fuseOperations.mkdir(path.getUtf8String(0), mode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,28 @@ public int enotempty() {
return errno_h.ENOTEMPTY();
}

@Override
public int enotsup() {
return errno_h.ENOTSUP();
}

@Override
public int einval() {
return errno_h.EINVAL();
}

@Override
public int erange() {
return errno_h.ERANGE();
}

@Override
public int enolck() {
return errno_h.ENOLCK();
}

@Override
public int enametoolong() {
return errno_h.ENAMETOOLONG();
}
}
Loading

0 comments on commit 7844848

Please sign in to comment.