Skip to content

Commit 93636bf

Browse files
Varada Moffamitkumar
Varada M
authored andcommitted
8353053: (fs) Add support for UserDefinedFileAttributeView on AIX
Backport-of: 1161b566ca06786996cf47a4475bcdabaa24cde8
1 parent c15293d commit 93636bf

File tree

6 files changed

+108
-11
lines changed

6 files changed

+108
-11
lines changed

src/java.base/aix/classes/sun/nio/fs/AixFileStore.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2013 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -88,18 +88,32 @@ UnixMountEntry findMountEntry() throws IOException {
8888
throw new IOException("Mount point not found");
8989
}
9090

91-
@Override
92-
protected boolean isExtendedAttributesEnabled(UnixPath path) {
93-
return false;
94-
}
95-
9691
@Override
9792
public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
93+
// support UserDefinedAttributeView if extended attributes enabled
94+
if (type == UserDefinedFileAttributeView.class) {
95+
// lookup fstypes.properties
96+
FeatureStatus status = checkIfFeaturePresent("user_xattr");
97+
if (status == FeatureStatus.PRESENT)
98+
return true;
99+
if (status == FeatureStatus.NOT_PRESENT)
100+
return false;
101+
102+
// typical AIX file system types that support xattr (JFS2 with EA enabled)
103+
String fstype = entry().fstype();
104+
if ("jfs2".equals(fstype)) {
105+
UnixPath dir = new UnixPath(file().getFileSystem(), entry().dir());
106+
return isExtendedAttributesEnabled(dir);
107+
}
108+
}
98109
return super.supportsFileAttributeView(type);
99110
}
100111

101112
@Override
102113
public boolean supportsFileAttributeView(String name) {
114+
if (name.equals("user"))
115+
return supportsFileAttributeView(UserDefinedFileAttributeView.class);
103116
return super.supportsFileAttributeView(name);
104117
}
118+
105119
}

src/java.base/aix/classes/sun/nio/fs/AixFileSystem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2013 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -56,6 +56,7 @@ private static class SupportedFileFileAttributeViewsHolder {
5656
private static Set<String> supportedFileAttributeViews() {
5757
Set<String> result = new HashSet<String>();
5858
result.addAll(UnixFileSystem.standardFileAttributeViews());
59+
result.add("user");
5960
return Collections.unmodifiableSet(result);
6061
}
6162
}

src/java.base/aix/classes/sun/nio/fs/AixFileSystemProvider.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
33
* Copyright (c) 2013 SAP SE. All rights reserved.
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -26,6 +26,8 @@
2626

2727
package sun.nio.fs;
2828

29+
import java.nio.file.*;
30+
import java.nio.file.attribute.*;
2931
import java.io.IOException;
3032

3133
/**
@@ -49,4 +51,29 @@ AixFileSystem newFileSystem(String dir) {
4951
AixFileStore getFileStore(UnixPath path) throws IOException {
5052
return new AixFileStore(path);
5153
}
54+
55+
@Override
56+
@SuppressWarnings("unchecked")
57+
public <V extends FileAttributeView> V getFileAttributeView(Path obj,
58+
Class<V> type,
59+
LinkOption... options)
60+
{
61+
if (type == UserDefinedFileAttributeView.class) {
62+
return (V) new AixUserDefinedFileAttributeView(UnixPath.toUnixPath(obj),
63+
Util.followLinks(options));
64+
}
65+
return super.getFileAttributeView(obj, type, options);
66+
}
67+
68+
@Override
69+
public DynamicFileAttributeView getFileAttributeView(Path obj,
70+
String name,
71+
LinkOption... options)
72+
{
73+
if (name.equals("user")) {
74+
return new AixUserDefinedFileAttributeView(UnixPath.toUnixPath(obj),
75+
Util.followLinks(options));
76+
}
77+
return super.getFileAttributeView(obj, name, options);
78+
}
5279
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
26+
package sun.nio.fs;
27+
28+
class AixUserDefinedFileAttributeView
29+
extends UnixUserDefinedFileAttributeView
30+
{
31+
32+
AixUserDefinedFileAttributeView(UnixPath file, boolean followLinks) {
33+
super(file, followLinks);
34+
}
35+
36+
@Override
37+
protected int maxNameLength() {
38+
return 255;
39+
}
40+
41+
}

src/java.base/unix/classes/sun/nio/fs/UnixConstants.java.template

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -124,6 +124,8 @@ class UnixConstants {
124124
// fgetxattr error codes for absent attributes depend on the OS:
125125
#ifdef _ALLBSD_SOURCE
126126
static final int PREFIX_XATTR_NOT_FOUND = ENOATTR;
127+
#elif defined(_AIX)
128+
static final int PREFIX_XATTR_NOT_FOUND = ENOATTR;
127129
#elif defined(__linux__)
128130
static final int PREFIX_XATTR_NOT_FOUND = ENODATA;
129131
#else

src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -46,6 +46,10 @@
4646
#include <sys/xattr.h>
4747
#endif
4848

49+
#if defined(_AIX)
50+
#include <sys/ea.h>
51+
#endif
52+
4953
/* For POSIX-compliant getpwuid_r */
5054
#include <pwd.h>
5155
#include <grp.h>
@@ -387,7 +391,7 @@ Java_sun_nio_fs_UnixNativeDispatcher_init(JNIEnv* env, jclass this)
387391

388392
/* supports extended attributes */
389393

390-
#if defined(_SYS_XATTR_H) || defined(_SYS_XATTR_H_)
394+
#if defined(_SYS_XATTR_H) || defined(_SYS_XATTR_H_) || defined(_AIX)
391395
capabilities |= sun_nio_fs_UnixNativeDispatcher_SUPPORTS_XATTR;
392396
#endif
393397

@@ -1381,6 +1385,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_fgetxattr0(JNIEnv* env, jclass clazz,
13811385
res = fgetxattr(fd, name, value, valueLen);
13821386
#elif defined(_ALLBSD_SOURCE)
13831387
res = fgetxattr(fd, name, value, valueLen, 0, 0);
1388+
#elif defined(_AIX)
1389+
res = fgetea(fd, name, value, valueLen);
13841390
#else
13851391
throwUnixException(env, ENOTSUP);
13861392
#endif
@@ -1402,6 +1408,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_fsetxattr0(JNIEnv* env, jclass clazz,
14021408
res = fsetxattr(fd, name, value, valueLen, 0);
14031409
#elif defined(_ALLBSD_SOURCE)
14041410
res = fsetxattr(fd, name, value, valueLen, 0, 0);
1411+
#elif defined(_AIX)
1412+
res = fsetea(fd, name, value, valueLen, 0);
14051413
#else
14061414
throwUnixException(env, ENOTSUP);
14071415
#endif
@@ -1421,6 +1429,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_fremovexattr0(JNIEnv* env, jclass clazz,
14211429
res = fremovexattr(fd, name);
14221430
#elif defined(_ALLBSD_SOURCE)
14231431
res = fremovexattr(fd, name, 0);
1432+
#elif defined(_AIX)
1433+
res = fremoveea(fd, name);
14241434
#else
14251435
throwUnixException(env, ENOTSUP);
14261436
#endif
@@ -1440,6 +1450,8 @@ Java_sun_nio_fs_UnixNativeDispatcher_flistxattr(JNIEnv* env, jclass clazz,
14401450
res = flistxattr(fd, list, (size_t)size);
14411451
#elif defined(_ALLBSD_SOURCE)
14421452
res = flistxattr(fd, list, (size_t)size, 0);
1453+
#elif defined(_AIX)
1454+
res = flistea(fd, list, (size_t)size);
14431455
#else
14441456
throwUnixException(env, ENOTSUP);
14451457
#endif

0 commit comments

Comments
 (0)