Skip to content
Permalink
Browse files
8260966: (fs) Consolidate Linux and macOS implementations of UserDefi…
…nedFileAttributeView

8260691: (fs) LinuxNativeDispatcher should link to xattr functions

Reviewed-by: alanb
  • Loading branch information
overheadhunter authored and Alan Bateman committed Mar 2, 2021
1 parent 5f4bc0a commit 0de6abd4b49e7111effbaef99a93317bcd7246f0
Show file tree
Hide file tree
Showing 16 changed files with 555 additions and 977 deletions.
@@ -105,27 +105,6 @@ UnixMountEntry findMountEntry() throws IOException {
throw new IOException("Mount point not found");
}

// returns true if extended attributes enabled on file system where given
// file resides, returns false if disabled or unable to determine.
private boolean isExtendedAttributesEnabled(UnixPath path) {
int fd = -1;
try {
fd = path.openForAttributeAccess(false);

// fgetxattr returns size if called with size==0
byte[] name = Util.toBytes("user.java");
LinuxNativeDispatcher.fgetxattr(fd, name, 0L, 0);
return true;
} catch (UnixException e) {
// attribute does not exist
if (e.errno() == UnixConstants.ENODATA)
return true;
} finally {
UnixNativeDispatcher.close(fd);
}
return false;
}

// get kernel version as a three element array {major, minor, micro}
private static int[] getKernelVersion() {
Pattern pattern = Pattern.compile("\\D+");
@@ -69,7 +69,7 @@ public Set<String> supportedFileAttributeViews() {

@Override
void copyNonPosixAttributes(int ofd, int nfd) {
LinuxUserDefinedFileAttributeView.copyExtendedAttributes(ofd, nfd);
UnixUserDefinedFileAttributeView.copyExtendedAttributes(ofd, nfd);
}

/**
@@ -69,61 +69,6 @@ static native int getmntent0(long fp, UnixMountEntry entry, long buffer, int buf
*/
static native void endmntent(long stream) throws UnixException;

/**
* ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size);
*/
static int fgetxattr(int filedes, byte[] name, long valueAddress,
int valueLen) throws UnixException
{
NativeBuffer buffer = NativeBuffers.asNativeBuffer(name);
try {
return fgetxattr0(filedes, buffer.address(), valueAddress, valueLen);
} finally {
buffer.release();
}
}

private static native int fgetxattr0(int filedes, long nameAddress,
long valueAddress, int valueLen) throws UnixException;

/**
* fsetxattr(int filedes, const char *name, const void *value, size_t size, int flags);
*/
static void fsetxattr(int filedes, byte[] name, long valueAddress,
int valueLen) throws UnixException
{
NativeBuffer buffer = NativeBuffers.asNativeBuffer(name);
try {
fsetxattr0(filedes, buffer.address(), valueAddress, valueLen);
} finally {
buffer.release();
}
}

private static native void fsetxattr0(int filedes, long nameAddress,
long valueAddress, int valueLen) throws UnixException;

/**
* fremovexattr(int filedes, const char *name);
*/
static void fremovexattr(int filedes, byte[] name) throws UnixException {
NativeBuffer buffer = NativeBuffers.asNativeBuffer(name);
try {
fremovexattr0(filedes, buffer.address());
} finally {
buffer.release();
}
}

private static native void fremovexattr0(int filedes, long nameAddress)
throws UnixException;

/**
* size_t flistxattr(int filedes, const char *list, size_t size)
*/
static native int flistxattr(int filedes, long listAddress, int size)
throws UnixException;

// initialize
private static native void init();

1 comment on commit 0de6abd

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 0de6abd Mar 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.