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

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2014, Oracle and/or its affiliates. All rights reserved.
  * Copyright 2013 SAP AG. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as

@@ -22,10 +22,14 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
+/*
+ * Portions Copyright (c) 2014 IBM Corporation
+ */
+
 package sun.nio.fs;
 
 import java.nio.file.attribute.*;
 import java.util.*;
 import java.io.IOException;

@@ -35,10 +39,13 @@
  */
 
 class AixFileStore
     extends UnixFileStore
 {
+    // used when checking if extended attributes are enabled or not
+    private volatile boolean xattrChecked;
+    private volatile boolean xattrEnabled;
 
     AixFileStore(UnixPath file) throws IOException {
         super(file);
     }
 

@@ -89,18 +96,68 @@
     }
 
     // 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) {
+        try {
+            int fd = path.openForAttributeAccess(false);
+            try {
+                // fgetxattr returns size if called with size==0
+                AixNativeDispatcher.fgetxattr(fd, "user.java".getBytes(), 0L, 0);
+                return true;
+            } catch (UnixException e) {
+                // attribute does not exist
+                if (e.errno() == UnixConstants.ENODATA)
+                    return true;
+            } finally {
+                UnixNativeDispatcher.close(fd);
+            }
+        } catch (IOException ignore) {
+            // nothing we can do
+        }
         return false;
     }
 
     @Override
     public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
+        // support DosFileAttributeView and UserDefinedAttributeView if extended
+        // attributes enabled
+        if (type == DosFileAttributeView.class ||
+            type == UserDefinedFileAttributeView.class)
+        {
+            // lookup fstypes.properties
+            FeatureStatus status = checkIfFeaturePresent("user_xattr");
+            if (status == FeatureStatus.PRESENT)
+                return true;
+            if (status == FeatureStatus.NOT_PRESENT)
+                return false;
+
+            // if file system is mounted with user_xattr option then assume
+            // extended attributes are enabled
+            if ((entry().hasOption("user_xattr")))
+                return true;
+
+            // user_xattr option not present but we special-case ext3/4 as we
+            // know that extended attributes are not enabled by default.
+            if (entry().fstype().equals("ext3") || entry().fstype().equals("ext4"))
+                return false;
+
+            // not ext3/4 so probe mount point
+            if (!xattrChecked) {
+                UnixPath dir = new UnixPath(file().getFileSystem(), entry().dir());
+                xattrEnabled = isExtendedAttributesEnabled(dir);
+                xattrChecked = true;
+            }
+            return xattrEnabled;
+        }
         return super.supportsFileAttributeView(type);
     }
 
     @Override
     public boolean supportsFileAttributeView(String name) {
+        if (name.equals("dos"))
+            return supportsFileAttributeView(DosFileAttributeView.class);
+        if (name.equals("user"))
+            return supportsFileAttributeView(UserDefinedFileAttributeView.class);
         return super.supportsFileAttributeView(name);
     }
 }