8262957: (fs) Fail fast in UnixFileStore.isExtendedAttributesEnabled

Reviewed-by: alanb
This commit is contained in:
Sebastian Stenzel 2021-04-14 09:55:52 +00:00 committed by Alan Bateman
parent e2106d5af6
commit 27dd88bf9e
3 changed files with 21 additions and 2 deletions

View File

@ -179,6 +179,11 @@ abstract class UnixFileStore
* @return <code>true</code> if enabled, <code>false</code> if disabled or unable to determine
*/
protected boolean isExtendedAttributesEnabled(UnixPath path) {
if (!UnixNativeDispatcher.xattrSupported()) {
// avoid I/O if native code doesn't support xattr
return false;
}
int fd = -1;
try {
fd = path.openForAttributeAccess(false);

View File

@ -614,8 +614,9 @@ class UnixNativeDispatcher {
*/
private static final int SUPPORTS_OPENAT = 1 << 1; // syscalls
private static final int SUPPORTS_FUTIMES = 1 << 2;
private static final int SUPPORTS_FUTIMENS = 1 << 4;
private static final int SUPPORTS_LUTIMES = 1 << 8;
private static final int SUPPORTS_FUTIMENS = 1 << 3;
private static final int SUPPORTS_LUTIMES = 1 << 4;
private static final int SUPPORTS_XATTR = 1 << 5;
private static final int SUPPORTS_BIRTHTIME = 1 << 16; // other features
private static final int capabilities;
@ -654,6 +655,13 @@ class UnixNativeDispatcher {
return (capabilities & SUPPORTS_BIRTHTIME) != 0;
}
/**
* Supports extended attributes
*/
static boolean xattrSupported() {
return (capabilities & SUPPORTS_XATTR) != 0;
}
private static native int init();
static {
jdk.internal.loader.BootLoader.loadLibrary("nio");

View File

@ -315,6 +315,12 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_BIRTHTIME;
#endif
/* supports extended attributes */
#ifdef _SYS_XATTR_H_
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_XATTR;
#endif
return capabilities;
}