< prev index next >
src/java.base/linux/classes/sun/nio/fs/LinuxFileStore.java
Print this page
rev 51048 : 8206448: (fs) Extended attributes assumed to be enabled on ext3 (lnx)
Summary: Assume extended attributes are only explicitly enable on ext3
Reviewed-by: mbaesken, alanb
rev 51049 : imported patch xattr-ext3-8206448.01
@@ -23,21 +23,38 @@
* questions.
*/
package sun.nio.fs;
-import java.nio.file.attribute.*;
-import java.util.*;
import java.io.IOException;
+import java.nio.file.attribute.DosFileAttributeView;
+import java.nio.file.attribute.FileAttributeView;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.UserDefinedFileAttributeView;
+import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Pattern;
/**
* Linux implementation of FileStore
*/
class LinuxFileStore
extends UnixFileStore
{
+ // get kernel version as a three element array {major, minor, micro}
+ private static int[] getKernelVersion() {
+ Pattern pattern = Pattern.compile("\\D+");
+ String[] matches = pattern.split(System.getProperty("os.version"));
+ int[] majorMinorMicro = new int[3];
+ int length = Math.min(matches.length, majorMinorMicro.length);
+ for (int i = 0; i < length; i++) {
+ majorMinorMicro[i] = Integer.valueOf(matches[i]);
+ }
+ return majorMinorMicro;
+ }
+
// used when checking if extended attributes are enabled or not
private volatile boolean xattrChecked;
private volatile boolean xattrEnabled;
LinuxFileStore(UnixPath file) throws IOException {
@@ -138,15 +155,35 @@
// if file system is mounted with user_xattr option then assume
// extended attributes are enabled
if ((entry().hasOption("user_xattr")))
return true;
- // for ext3 and ext4 user_xattr option is enabled by default so
- // check for explicit disabling of this option
- if (entry().fstype().equals("ext3") ||
- entry().fstype().equals("ext4")) {
- return !entry().hasOption("nouser_xattr");
+ // check for explicit disabling of extended attributes
+ if (entry().hasOption("nouser_xattr")) {
+ return false;
+ }
+
+ // user_{no}xattr options not present but we special-case ext3 as
+ // we know that extended attributes are not enabled by default.
+ if (entry().fstype().equals("ext3")) {
+ return false;
+ }
+
+ // user_xattr option not present but we special-case ext4 as we
+ // know that extended attributes are enabled by default for
+ // kernel version >= 2.6.39
+ if (entry().fstype().equals("ext4")) {
+ if (!xattrChecked) {
+ // check kernel version
+ int[] kernelVersion = getKernelVersion();
+ xattrEnabled = kernelVersion[0] > 2 ||
+ (kernelVersion[0] == 2 && kernelVersion[1] > 6) ||
+ (kernelVersion[0] == 2 && kernelVersion[1] == 6 &&
+ kernelVersion[2] >= 39);
+ xattrChecked = true;
+ }
+ return xattrEnabled;
}
// not ext3/4 so probe mount point
if (!xattrChecked) {
UnixPath dir = new UnixPath(file().getFileSystem(), entry().dir());
< prev index next >