Skip to content

Commit

Permalink
Merge branch 'feature/xattr' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
overheadhunter committed Jan 9, 2023
2 parents 6ad9851 + 84f2a22 commit c71982b
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 6 deletions.
7 changes: 7 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,6 +88,13 @@ public interface Errno {
*/
int enotempty();

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

/**
* Invalid argument
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ public int getxattr(String path, String name, ByteBuffer value) {
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;
Expand All @@ -226,6 +229,9 @@ public int setxattr(String path, String name, ByteBuffer value, int flags) {
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) {
Expand All @@ -241,15 +247,21 @@ public int listxattr(String path, ByteBuffer list) {
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) {
return names.size();
}
int startpos = list.position();
for (var name : names) {
list.put(StandardCharsets.UTF_8.encode(name)).put((byte) 0x00);
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;
}
return list.position() - startpos;
} catch (BufferOverflowException e) {
return -errno.erange();
} catch (NoSuchFileException e) {
Expand All @@ -265,6 +277,9 @@ public int removexattr(String path, String 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) {
Expand Down
1 change: 1 addition & 0 deletions jfuse-linux-aarch64/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<includeMacro>ENOTDIR</includeMacro>
<includeMacro>EISDIR</includeMacro>
<includeMacro>ENOTEMPTY</includeMacro>
<includeMacro>ENOTSUP</includeMacro>
<includeMacro>EINVAL</includeMacro>
<includeMacro>ERANGE</includeMacro>
</includeMacros>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public int enotempty() {
return errno_h.ENOTEMPTY();
}

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

@Override
public int einval() {
return errno_h.EINVAL();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public static int ENOSYS() {
public static int ENOTEMPTY() {
return (int)39L;
}
public static int ENOTSUP() {
return (int)95L;
}
}


1 change: 1 addition & 0 deletions jfuse-linux-amd64/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@
<includeMacro>ENOTDIR</includeMacro>
<includeMacro>EISDIR</includeMacro>
<includeMacro>ENOTEMPTY</includeMacro>
<includeMacro>ENOTSUP</includeMacro>
<includeMacro>EINVAL</includeMacro>
<includeMacro>ERANGE</includeMacro>
</includeMacros>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public int enotempty() {
return errno_h.ENOTEMPTY();
}

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

@Override
public int einval() {
return errno_h.EINVAL();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public static int ENOSYS() {
public static int ENOTEMPTY() {
return (int)39L;
}
public static int ENOTSUP() {
return (int)95L;
}
}


1 change: 1 addition & 0 deletions jfuse-mac/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<includeMacro>ENOTDIR</includeMacro>
<includeMacro>EISDIR</includeMacro>
<includeMacro>ENOTEMPTY</includeMacro>
<includeMacro>ENOTSUP</includeMacro>
<includeMacro>EINVAL</includeMacro>
<includeMacro>ERANGE</includeMacro>
</includeMacros>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public int enotempty() {
return errno_h.ENOTEMPTY();
}

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

@Override
public int einval() {
return errno_h.EINVAL();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public static int EROFS() {
public static int ERANGE() {
return (int)34L;
}
public static int ENOTSUP() {
return (int)45L;
}
public static int ENOTEMPTY() {
return (int)66L;
}
Expand Down
1 change: 1 addition & 0 deletions jfuse-win/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@
<includeMacro>ENOTDIR</includeMacro>
<includeMacro>EISDIR</includeMacro>
<includeMacro>ENOTEMPTY</includeMacro>
<includeMacro>ENOTSUP</includeMacro>
<includeMacro>EINVAL</includeMacro>
<includeMacro>ERANGE</includeMacro>
</includeMacros>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public int enotempty() {
return errno_h.ENOTEMPTY();
}

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

@Override
public int einval() {
return errno_h.EINVAL();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public static int ENOSYS() {
public static int ENOTEMPTY() {
return (int)41L;
}
public static int ENOTSUP() {
return (int)129L;
}
public static int EINVAL() {
return (int)22L;
}
Expand Down

0 comments on commit c71982b

Please sign in to comment.