Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.base/macosx/classes/sun/nio/fs/BsdFileStore.java
41137 views
1
/*
2
* Copyright (c) 2008, 2019, 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.FileAttributeView;
29
import java.nio.file.attribute.UserDefinedFileAttributeView;
30
import java.io.IOException;
31
import java.util.Arrays;
32
import sun.security.action.GetPropertyAction;
33
34
/**
35
* Bsd implementation of FileStore
36
*/
37
38
class BsdFileStore
39
extends UnixFileStore
40
{
41
BsdFileStore(UnixPath file) throws IOException {
42
super(file);
43
}
44
45
BsdFileStore(UnixFileSystem fs, UnixMountEntry entry) throws IOException {
46
super(fs, entry);
47
}
48
49
/**
50
* Finds, and returns, the mount entry for the file system where the file
51
* resides.
52
*/
53
@Override
54
UnixMountEntry findMountEntry() throws IOException {
55
UnixFileSystem fs = file().getFileSystem();
56
57
// step 1: get realpath
58
UnixPath path = null;
59
try {
60
byte[] rp = UnixNativeDispatcher.realpath(file());
61
path = new UnixPath(fs, rp);
62
} catch (UnixException x) {
63
x.rethrowAsIOException(file());
64
}
65
66
// step 2: find mount point
67
byte[] dir = null;
68
try {
69
dir = BsdNativeDispatcher.getmntonname(path);
70
} catch (UnixException x) {
71
x.rethrowAsIOException(path);
72
}
73
74
// step 3: lookup mounted file systems
75
for (UnixMountEntry entry: fs.getMountEntries()) {
76
if (Arrays.equals(dir, entry.dir()))
77
return entry;
78
}
79
80
throw new IOException("Mount point not found in fstab");
81
}
82
83
@Override
84
public boolean supportsFileAttributeView(Class<? extends FileAttributeView> type) {
85
// support UserDefinedAttributeView if extended attributes enabled
86
if (type == UserDefinedFileAttributeView.class) {
87
// lookup fstypes.properties
88
FeatureStatus status = checkIfFeaturePresent("user_xattr");
89
if (status == FeatureStatus.PRESENT)
90
return true;
91
if (status == FeatureStatus.NOT_PRESENT)
92
return false;
93
94
// typical macOS file system types that are known to support xattr
95
String fstype = entry().fstype();
96
if ("hfs".equals(fstype))
97
return true;
98
if ("apfs".equals(fstype)) {
99
// fgetxattr broken on APFS prior to 10.14
100
return isOsVersionGte(10, 14);
101
}
102
103
// probe file system capabilities
104
UnixPath dir = new UnixPath(file().getFileSystem(), entry().dir());
105
return isExtendedAttributesEnabled(dir);
106
}
107
return super.supportsFileAttributeView(type);
108
}
109
110
@Override
111
public boolean supportsFileAttributeView(String name) {
112
if (name.equals("user"))
113
return supportsFileAttributeView(UserDefinedFileAttributeView.class);
114
return super.supportsFileAttributeView(name);
115
}
116
117
/**
118
* Returns true if the OS major/minor version is greater than, or equal, to the
119
* given major/minor version.
120
*/
121
private static boolean isOsVersionGte(int requiredMajor, int requiredMinor) {
122
String osVersion = GetPropertyAction.privilegedGetProperty("os.version");
123
String[] vers = Util.split(osVersion, '.');
124
int majorVersion = Integer.parseInt(vers[0]);
125
int minorVersion = Integer.parseInt(vers[1]);
126
return (majorVersion > requiredMajor)
127
|| (majorVersion == requiredMajor && minorVersion >= requiredMinor);
128
}
129
}
130
131