Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
Automatic merge of jdk:master into master
  • Loading branch information
duke committed Jan 17, 2021
2 parents f38c45e + da4cf05 commit 0ee76de31e70ea7454d92dcfd08d18069826e773
@@ -77,4 +77,56 @@ UnixMountEntry findMountEntry() throws IOException {

throw new IOException("Mount point not found in fstab");
}

// 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");
BsdNativeDispatcher.fgetxattr(fd, name, 0L, 0);
return true;
} catch (UnixException e) {
// attribute does not exist
if (e.errno() == UnixConstants.ENOATTR)
return true;
} finally {
UnixNativeDispatcher.close(fd);
}
return false;
}

@Override
public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
// support UserDefinedAttributeView if extended attributes enabled
if (type == UserDefinedFileAttributeView.class) {
// lookup fstypes.properties
FeatureStatus status = checkIfFeaturePresent("user_xattr");
if (status == FeatureStatus.PRESENT)
return true;
if (status == FeatureStatus.NOT_PRESENT)
return false;

// typical macOS file system types that are known to support xattr
if (entry().fstype().equals("apfs")
|| entry().fstype().equals("hfs")) {
return true;
}

// probe file system capabilities
UnixPath dir = new UnixPath(file().getFileSystem(), entry().dir());
return isExtendedAttributesEnabled(dir);
}
return super.supportsFileAttributeView(type);
}

@Override
public boolean supportsFileAttributeView(String name) {
if (name.equals("user"))
return supportsFileAttributeView(UserDefinedFileAttributeView.class);
return super.supportsFileAttributeView(name);
}
}
@@ -56,6 +56,8 @@ private static class SupportedFileFileAttributeViewsHolder {
private static Set<String> supportedFileAttributeViews() {
Set<String> result = new HashSet<String>();
result.addAll(standardFileAttributeViews());
// additional BSD-specific views
result.add("user");
return Collections.unmodifiableSet(result);
}
}
@@ -25,6 +25,8 @@

package sun.nio.fs;

import java.nio.file.*;
import java.nio.file.attribute.*;
import java.io.IOException;

/**
@@ -45,4 +47,29 @@ BsdFileSystem newFileSystem(String dir) {
BsdFileStore getFileStore(UnixPath path) throws IOException {
return new BsdFileStore(path);
}

@Override
@SuppressWarnings("unchecked")
public <V extends FileAttributeView> V getFileAttributeView(Path obj,
Class<V> type,
LinkOption... options)
{
if (type == UserDefinedFileAttributeView.class) {
return (V) new BsdUserDefinedFileAttributeView(UnixPath.toUnixPath(obj),
Util.followLinks(options));
}
return super.getFileAttributeView(obj, type, options);
}

@Override
public DynamicFileAttributeView getFileAttributeView(Path obj,
String name,
LinkOption... options)
{
if (name.equals("user")) {
return new BsdUserDefinedFileAttributeView(UnixPath.toUnixPath(obj),
Util.followLinks(options));
}
return super.getFileAttributeView(obj, name, options);
}
}
@@ -65,6 +65,67 @@ static byte[] getmntonname(UnixPath path) throws UnixException {
}
static native byte[] getmntonname0(long pathAddress) throws UnixException;

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

private static native int fgetxattr0(int fd, long nameAddress,
long valueAddress, int valueLen, long position, int options) throws UnixException;

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

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

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

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

/**
* ssize_t flistxattr(int fd, char *namebuf, size_t size, int options);
*/
static int flistxattr(int fd, long nameBufAddress, int size) throws UnixException {
return flistxattr0(fd, nameBufAddress, size, 0);
}

private static native int flistxattr0(int fd, long nameBufAddress, int size,
int options) throws UnixException;

// initialize field IDs
private static native void initIDs();

0 comments on commit 0ee76de

Please sign in to comment.