Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/nio/fs/LinuxFileStore.java
32288 views
1
/*
2
* Copyright (c) 2008, 2018, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
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
59
// step 1: get realpath
60
UnixPath path = null;
61
try {
62
byte[] rp = UnixNativeDispatcher.realpath(file());
63
path = new UnixPath(fs, rp);
64
} catch (UnixException x) {
65
x.rethrowAsIOException(file());
66
}
67
68
// step 2: find mount point
69
List<UnixMountEntry> procMountsEntries =
70
fs.getMountEntries("/proc/mounts");
71
UnixPath parent = path.getParent();
72
while (parent != null) {
73
UnixFileAttributes attrs = null;
74
try {
75
attrs = UnixFileAttributes.get(parent, true);
76
} catch (UnixException x) {
77
x.rethrowAsIOException(parent);
78
}
79
if (attrs.dev() != dev()) {
80
// step 3: lookup mounted file systems (use /proc/mounts to
81
// ensure we find the file system even when not in /etc/mtab)
82
byte[] dir = path.asByteArray();
83
for (UnixMountEntry entry : procMountsEntries) {
84
if (Arrays.equals(dir, entry.dir()))
85
return entry;
86
}
87
}
88
path = parent;
89
parent = parent.getParent();
90
}
91
92
// step 3: lookup mounted file systems (use /proc/mounts to
93
// ensure we find the file system even when not in /etc/mtab)
94
byte[] dir = path.asByteArray();
95
for (UnixMountEntry entry : procMountsEntries) {
96
if (Arrays.equals(dir, entry.dir()))
97
return entry;
98
}
99
100
throw new IOException("Mount point not found");
101
}
102
103
// returns true if extended attributes enabled on file system where given
104
// file resides, returns false if disabled or unable to determine.
105
private boolean isExtendedAttributesEnabled(UnixPath path) {
106
try {
107
int fd = path.openForAttributeAccess(false);
108
try {
109
// fgetxattr returns size if called with size==0
110
byte[] name = Util.toBytes("user.java");
111
LinuxNativeDispatcher.fgetxattr(fd, name, 0L, 0);
112
return true;
113
} catch (UnixException e) {
114
// attribute does not exist
115
if (e.errno() == UnixConstants.ENODATA)
116
return true;
117
} finally {
118
UnixNativeDispatcher.close(fd);
119
}
120
} catch (IOException ignore) {
121
// nothing we can do
122
}
123
return false;
124
}
125
126
@Override
127
public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
128
// support DosFileAttributeView and UserDefinedAttributeView if extended
129
// attributes enabled
130
if (type == DosFileAttributeView.class ||
131
type == UserDefinedFileAttributeView.class)
132
{
133
// lookup fstypes.properties
134
FeatureStatus status = checkIfFeaturePresent("user_xattr");
135
if (status == FeatureStatus.PRESENT)
136
return true;
137
if (status == FeatureStatus.NOT_PRESENT)
138
return false;
139
140
// if file system is mounted with user_xattr option then assume
141
// extended attributes are enabled
142
if ((entry().hasOption("user_xattr")))
143
return true;
144
145
// user_xattr option not present but we special-case ext3/4 as we
146
// know that extended attributes are not enabled by default.
147
if (entry().fstype().equals("ext3") || entry().fstype().equals("ext4"))
148
return false;
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);
168
if (name.equals("user"))
169
return supportsFileAttributeView(UserDefinedFileAttributeView.class);
170
return super.supportsFileAttributeView(name);
171
}
172
}
173
174