8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.nio.fs;
27
28 import java.nio.file.attribute.*;
29 import java.util.*;
30 import java.io.IOException;
31
32 /**
33 * Linux implementation of FileStore
34 */
35
36 class LinuxFileStore
37 extends UnixFileStore
38 {
39 // used when checking if extended attributes are enabled or not
40 private volatile boolean xattrChecked;
41 private volatile boolean xattrEnabled;
42
43 LinuxFileStore(UnixPath file) throws IOException {
44 super(file);
45 }
46
47 LinuxFileStore(UnixFileSystem fs, UnixMountEntry entry) throws IOException {
48 super(fs, entry);
49 }
50
51 /**
52 * Finds, and returns, the mount entry for the file system where the file
53 * resides.
54 */
55 @Override
56 UnixMountEntry findMountEntry() throws IOException {
57 LinuxFileSystem fs = (LinuxFileSystem)file().getFileSystem();
58
123
124 @Override
125 public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
126 // support DosFileAttributeView and UserDefinedAttributeView if extended
127 // attributes enabled
128 if (type == DosFileAttributeView.class ||
129 type == UserDefinedFileAttributeView.class)
130 {
131 // lookup fstypes.properties
132 FeatureStatus status = checkIfFeaturePresent("user_xattr");
133 if (status == FeatureStatus.PRESENT)
134 return true;
135 if (status == FeatureStatus.NOT_PRESENT)
136 return false;
137
138 // if file system is mounted with user_xattr option then assume
139 // extended attributes are enabled
140 if ((entry().hasOption("user_xattr")))
141 return true;
142
143 // for ext3 and ext4 user_xattr option is enabled by default so
144 // check for explicit disabling of this option
145 if (entry().fstype().equals("ext3") ||
146 entry().fstype().equals("ext4")) {
147 return !entry().hasOption("nouser_xattr");
148 }
149
150 // not ext3/4 so probe mount point
151 if (!xattrChecked) {
152 UnixPath dir = new UnixPath(file().getFileSystem(), entry().dir());
153 xattrEnabled = isExtendedAttributesEnabled(dir);
154 xattrChecked = true;
155 }
156 return xattrEnabled;
157 }
158 // POSIX attributes not supported on FAT
159 if (type == PosixFileAttributeView.class && entry().fstype().equals("vfat"))
160 return false;
161 return super.supportsFileAttributeView(type);
162 }
163
164 @Override
165 public boolean supportsFileAttributeView(String name) {
166 if (name.equals("dos"))
167 return supportsFileAttributeView(DosFileAttributeView.class);
|
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.nio.fs;
27
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;
36
37 /**
38 * Linux implementation of FileStore
39 */
40
41 class LinuxFileStore
42 extends UnixFileStore
43 {
44 // get kernel version as a three element array {major, minor, micro}
45 private static int[] getKernelVersion() {
46 Pattern pattern = Pattern.compile("\\D+");
47 String[] matches = pattern.split(System.getProperty("os.version"));
48 int[] majorMinorMicro = new int[3];
49 int length = Math.min(matches.length, majorMinorMicro.length);
50 for (int i = 0; i < length; i++) {
51 majorMinorMicro[i] = Integer.valueOf(matches[i]);
52 }
53 return majorMinorMicro;
54 }
55
56 // used when checking if extended attributes are enabled or not
57 private volatile boolean xattrChecked;
58 private volatile boolean xattrEnabled;
59
60 LinuxFileStore(UnixPath file) throws IOException {
61 super(file);
62 }
63
64 LinuxFileStore(UnixFileSystem fs, UnixMountEntry entry) throws IOException {
65 super(fs, entry);
66 }
67
68 /**
69 * Finds, and returns, the mount entry for the file system where the file
70 * resides.
71 */
72 @Override
73 UnixMountEntry findMountEntry() throws IOException {
74 LinuxFileSystem fs = (LinuxFileSystem)file().getFileSystem();
75
140
141 @Override
142 public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
143 // support DosFileAttributeView and UserDefinedAttributeView if extended
144 // attributes enabled
145 if (type == DosFileAttributeView.class ||
146 type == UserDefinedFileAttributeView.class)
147 {
148 // lookup fstypes.properties
149 FeatureStatus status = checkIfFeaturePresent("user_xattr");
150 if (status == FeatureStatus.PRESENT)
151 return true;
152 if (status == FeatureStatus.NOT_PRESENT)
153 return false;
154
155 // if file system is mounted with user_xattr option then assume
156 // extended attributes are enabled
157 if ((entry().hasOption("user_xattr")))
158 return true;
159
160 // check for explicit disabling of extended attributes
161 if (entry().hasOption("nouser_xattr")) {
162 return false;
163 }
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;
185 }
186
187 // not ext3/4 so probe mount point
188 if (!xattrChecked) {
189 UnixPath dir = new UnixPath(file().getFileSystem(), entry().dir());
190 xattrEnabled = isExtendedAttributesEnabled(dir);
191 xattrChecked = true;
192 }
193 return xattrEnabled;
194 }
195 // POSIX attributes not supported on FAT
196 if (type == PosixFileAttributeView.class && entry().fstype().equals("vfat"))
197 return false;
198 return super.supportsFileAttributeView(type);
199 }
200
201 @Override
202 public boolean supportsFileAttributeView(String name) {
203 if (name.equals("dos"))
204 return supportsFileAttributeView(DosFileAttributeView.class);
|