23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package sun.nio.fs; |
26 package sun.nio.fs; |
27 |
27 |
28 import java.nio.file.attribute.*; |
|
29 import java.util.*; |
|
30 import java.io.IOException; |
28 import java.io.IOException; |
|
29 import java.nio.file.attribute.DosFileAttributeView; |
|
30 import java.nio.file.attribute.FileAttributeView; |
|
31 import java.nio.file.attribute.PosixFileAttributeView; |
|
32 import java.nio.file.attribute.UserDefinedFileAttributeView; |
|
33 import java.util.Arrays; |
|
34 import java.util.List; |
|
35 import java.util.regex.Pattern; |
31 |
36 |
32 /** |
37 /** |
33 * Linux implementation of FileStore |
38 * Linux implementation of FileStore |
34 */ |
39 */ |
35 |
40 |
117 return true; |
122 return true; |
118 } finally { |
123 } finally { |
119 UnixNativeDispatcher.close(fd); |
124 UnixNativeDispatcher.close(fd); |
120 } |
125 } |
121 return false; |
126 return false; |
|
127 } |
|
128 |
|
129 // get kernel version as a three element array {major, minor, micro} |
|
130 private static int[] getKernelVersion() { |
|
131 Pattern pattern = Pattern.compile("\\D+"); |
|
132 String[] matches = pattern.split(System.getProperty("os.version")); |
|
133 int[] majorMinorMicro = new int[3]; |
|
134 int length = Math.min(matches.length, majorMinorMicro.length); |
|
135 for (int i = 0; i < length; i++) { |
|
136 majorMinorMicro[i] = Integer.valueOf(matches[i]); |
|
137 } |
|
138 return majorMinorMicro; |
122 } |
139 } |
123 |
140 |
124 @Override |
141 @Override |
125 public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) { |
142 public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) { |
126 // support DosFileAttributeView and UserDefinedAttributeView if extended |
143 // support DosFileAttributeView and UserDefinedAttributeView if extended |
138 // if file system is mounted with user_xattr option then assume |
155 // if file system is mounted with user_xattr option then assume |
139 // extended attributes are enabled |
156 // extended attributes are enabled |
140 if ((entry().hasOption("user_xattr"))) |
157 if ((entry().hasOption("user_xattr"))) |
141 return true; |
158 return true; |
142 |
159 |
143 // for ext3 and ext4 user_xattr option is enabled by default so |
160 // check for explicit disabling of extended attributes |
144 // check for explicit disabling of this option |
161 if (entry().hasOption("nouser_xattr")) { |
145 if (entry().fstype().equals("ext3") || |
162 return false; |
146 entry().fstype().equals("ext4")) { |
163 } |
147 return !entry().hasOption("nouser_xattr"); |
164 |
|
165 // user_{no}xattr options not present but we special-case ext3 as |
|
166 // we know that extended attributes are not enabled by default. |
|
167 if (entry().fstype().equals("ext3")) { |
|
168 return false; |
|
169 } |
|
170 |
|
171 // user_xattr option not present but we special-case ext4 as we |
|
172 // know that extended attributes are enabled by default for |
|
173 // kernel version >= 2.6.39 |
|
174 if (entry().fstype().equals("ext4")) { |
|
175 if (!xattrChecked) { |
|
176 // check kernel version |
|
177 int[] kernelVersion = getKernelVersion(); |
|
178 xattrEnabled = kernelVersion[0] > 2 || |
|
179 (kernelVersion[0] == 2 && kernelVersion[1] > 6) || |
|
180 (kernelVersion[0] == 2 && kernelVersion[1] == 6 && |
|
181 kernelVersion[2] >= 39); |
|
182 xattrChecked = true; |
|
183 } |
|
184 return xattrEnabled; |
148 } |
185 } |
149 |
186 |
150 // not ext3/4 so probe mount point |
187 // not ext3/4 so probe mount point |
151 if (!xattrChecked) { |
188 if (!xattrChecked) { |
152 UnixPath dir = new UnixPath(file().getFileSystem(), entry().dir()); |
189 UnixPath dir = new UnixPath(file().getFileSystem(), entry().dir()); |