forked from openjdk/jdk17u
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d025f52
commit 05dca17
Showing
1 changed file
with
20 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,10 @@ | |
#endif | ||
#include <sys/time.h> | ||
|
||
#if defined(__linux__) || defined(_ALLBSD_SOURCE) | ||
#if defined(__linux__) || defined(MACOSX) | ||
#include <sys/xattr.h> | ||
#elif defined(__FreeBSD__) || defined(__NetBSD__) | ||
#include <sys/extattr.h> | ||
#endif | ||
|
||
/* For POSIX-compliant getpwuid_r */ | ||
|
@@ -1245,19 +1247,21 @@ JNIEXPORT jint JNICALL | |
Java_sun_nio_fs_UnixNativeDispatcher_fgetxattr0(JNIEnv* env, jclass clazz, | ||
jint fd, jlong nameAddress, jlong valueAddress, jint valueLen) | ||
{ | ||
size_t res = -1; | ||
ssize_t res = -1; | ||
const char* name = jlong_to_ptr(nameAddress); | ||
void* value = jlong_to_ptr(valueAddress); | ||
|
||
#ifdef __linux__ | ||
res = fgetxattr(fd, name, value, valueLen); | ||
#elif _ALLBSD_SOURCE | ||
#elif MACOSX | ||
res = fgetxattr(fd, name, value, valueLen, 0, 0); | ||
#elif defined(__FreeBSD__) || defined(__NetBSD__) | ||
res = extattr_get_fd(fd, EXTATTR_NAMESPACE_USER, name, value, (size_t)valueLen); | ||
#else | ||
throwUnixException(env, ENOTSUP); | ||
#endif | ||
|
||
if (res == (size_t)-1) | ||
if (res == (ssize_t)-1) | ||
throwUnixException(env, errno); | ||
return (jint)res; | ||
} | ||
|
@@ -1272,8 +1276,10 @@ Java_sun_nio_fs_UnixNativeDispatcher_fsetxattr0(JNIEnv* env, jclass clazz, | |
|
||
#ifdef __linux__ | ||
res = fsetxattr(fd, name, value, valueLen, 0); | ||
#elif _ALLBSD_SOURCE | ||
#elif MACOSX | ||
res = fsetxattr(fd, name, value, valueLen, 0, 0); | ||
#elif defined(__FreeBSD__) || defined(__NetBSD__) | ||
res = extattr_set_fd(fd, EXTATTR_NAMESPACE_USER, name, value, (size_t)valueLen); | ||
#else | ||
throwUnixException(env, ENOTSUP); | ||
#endif | ||
|
@@ -1291,8 +1297,10 @@ Java_sun_nio_fs_UnixNativeDispatcher_fremovexattr0(JNIEnv* env, jclass clazz, | |
|
||
#ifdef __linux__ | ||
res = fremovexattr(fd, name); | ||
#elif _ALLBSD_SOURCE | ||
#elif MACOSX | ||
res = fremovexattr(fd, name, 0); | ||
#elif defined(__FreeBSD__) || defined(__NetBSD__) | ||
res = extattr_delete_fd(fd, EXTATTR_NAMESPACE_USER, name); | ||
#else | ||
throwUnixException(env, ENOTSUP); | ||
#endif | ||
|
@@ -1305,18 +1313,20 @@ JNIEXPORT jint JNICALL | |
Java_sun_nio_fs_UnixNativeDispatcher_flistxattr(JNIEnv* env, jclass clazz, | ||
jint fd, jlong listAddress, jint size) | ||
{ | ||
size_t res = -1; | ||
ssize_t res = -1; | ||
char* list = jlong_to_ptr(listAddress); | ||
|
||
#ifdef __linux__ | ||
res = flistxattr(fd, list, (size_t)size); | ||
#elif _ALLBSD_SOURCE | ||
#elif MACOSX | ||
res = flistxattr(fd, list, (size_t)size, 0); | ||
#elif defined(__FreeBSD__) || defined(__NetBSD__) | ||
res = extattr_list_fd(fd, EXTATTR_NAMESPACE_USER, list, (size_t)size); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
rednoah
|
||
#else | ||
throwUnixException(env, ENOTSUP); | ||
#endif | ||
|
||
if (res == (size_t)-1) | ||
if (res == (ssize_t)-1) | ||
throwUnixException(env, errno); | ||
return (jint)res; | ||
} | ||
} |
Note that this code does not work. Linux
flistxattr
andextattr_list_fd
don't return the same data structure.flistxattr
will return a list 0-terminated Stringsextattr_list_fd
does not, and since no\0
appears, the code on the Java side (https://github.com/battleblow/jdk17u/blob/bsd-port/src/java.base/unix/classes/sun/nio/fs/UnixUserDefinedFileAttributeView.java#L78) doesn't break but it also never parses any list items, i.e.UnixUserDefinedFileAttributeView::list
is always empty."""
extattr_list_file() returns a list of attributes present in the requested
namespace. Each list entry consists of a single byte containing the
length of the attribute name, followed by the attribute name. The attri-
bute name is not terminated by ASCII 0 (nul).
"""