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 java.io;
27
28 import java.util.Properties;
29 import jdk.internal.misc.Blocker;
30 import jdk.internal.util.StaticProperty;
31 import sun.security.action.GetPropertyAction;
32
33 final class UnixFileSystem extends FileSystem {
34
35 private final char slash;
36 private final char colon;
37 private final String userDir;
38
39 UnixFileSystem() {
40 Properties props = GetPropertyAction.privilegedGetProperties();
41 slash = props.getProperty("file.separator").charAt(0);
42 colon = props.getProperty("path.separator").charAt(0);
43 userDir = StaticProperty.userDir();
44 }
45
46 /* -- Normalization and construction -- */
47
48 @Override
49 public char getSeparator() {
144 }
145
146 @Override
147 public boolean isInvalid(File f) {
148 return f.getPath().indexOf('\u0000') >= 0;
149 }
150
151 @Override
152 public String resolve(File f) {
153 if (isAbsolute(f)) return f.getPath();
154 @SuppressWarnings("removal")
155 SecurityManager sm = System.getSecurityManager();
156 if (sm != null) {
157 sm.checkPropertyAccess("user.dir");
158 }
159 return resolve(userDir, f.getPath());
160 }
161
162 @Override
163 public String canonicalize(String path) throws IOException {
164 long comp = Blocker.begin();
165 try {
166 return canonicalize0(path);
167 } finally {
168 Blocker.end(comp);
169 }
170 }
171 private native String canonicalize0(String path) throws IOException;
172
173 /* -- Attribute accessors -- */
174
175 private native int getBooleanAttributes0(File f);
176
177 @Override
178 public int getBooleanAttributes(File f) {
179 int rv;
180 long comp = Blocker.begin();
181 try {
182 rv = getBooleanAttributes0(f);
183 } finally {
184 Blocker.end(comp);
185 }
186 return rv | isHidden(f);
187 }
188
189 @Override
190 public boolean hasBooleanAttributes(File f, int attributes) {
191 int rv;
192 long comp = Blocker.begin();
193 try {
194 rv = getBooleanAttributes0(f);
195 } finally {
196 Blocker.end(comp);
197 }
198 if ((attributes & BA_HIDDEN) != 0) {
199 rv |= isHidden(f);
200 }
201 return (rv & attributes) == attributes;
202 }
203
204 private static int isHidden(File f) {
205 return f.getName().startsWith(".") ? BA_HIDDEN : 0;
206 }
207
208 @Override
209 public boolean checkAccess(File f, int access) {
210 long comp = Blocker.begin();
211 try {
212 return checkAccess0(f, access);
213 } finally {
214 Blocker.end(comp);
215 }
216 }
217 private native boolean checkAccess0(File f, int access);
218
219 @Override
220 public long getLastModifiedTime(File f) {
221 long comp = Blocker.begin();
222 try {
223 return getLastModifiedTime0(f);
224 } finally {
225 Blocker.end(comp);
226 }
227 }
228 private native long getLastModifiedTime0(File f);
229
230 @Override
231 public long getLength(File f) {
232 long comp = Blocker.begin();
233 try {
234 return getLength0(f);
235 } finally {
236 Blocker.end(comp);
237 }
238 }
239 private native long getLength0(File f);
240
241 @Override
242 public boolean setPermission(File f, int access, boolean enable, boolean owneronly) {
243 long comp = Blocker.begin();
244 try {
245 return setPermission0(f, access, enable, owneronly);
246 } finally {
247 Blocker.end(comp);
248 }
249 }
250 private native boolean setPermission0(File f, int access, boolean enable, boolean owneronly);
251
252 /* -- File operations -- */
253
254 @Override
255 public boolean createFileExclusively(String path) throws IOException {
256 long comp = Blocker.begin();
257 try {
258 return createFileExclusively0(path);
259 } finally {
260 Blocker.end(comp);
261 }
262 }
263 private native boolean createFileExclusively0(String path) throws IOException;
264
265 @Override
266 public boolean delete(File f) {
267 long comp = Blocker.begin();
268 try {
269 return delete0(f);
270 } finally {
271 Blocker.end(comp);
272 }
273 }
274 private native boolean delete0(File f);
275
276 @Override
277 public String[] list(File f) {
278 long comp = Blocker.begin();
279 try {
280 return list0(f);
281 } finally {
282 Blocker.end(comp);
283 }
284 }
285 private native String[] list0(File f);
286
287 @Override
288 public boolean createDirectory(File f) {
289 long comp = Blocker.begin();
290 try {
291 return createDirectory0(f);
292 } finally {
293 Blocker.end(comp);
294 }
295 }
296 private native boolean createDirectory0(File f);
297
298 @Override
299 public boolean rename(File f1, File f2) {
300 long comp = Blocker.begin();
301 try {
302 return rename0(f1, f2);
303 } finally {
304 Blocker.end(comp);
305 }
306 }
307 private native boolean rename0(File f1, File f2);
308
309 @Override
310 public boolean setLastModifiedTime(File f, long time) {
311 long comp = Blocker.begin();
312 try {
313 return setLastModifiedTime0(f, time);
314 } finally {
315 Blocker.end(comp);
316 }
317 }
318 private native boolean setLastModifiedTime0(File f, long time);
319
320 @Override
321 public boolean setReadOnly(File f) {
322 long comp = Blocker.begin();
323 try {
324 return setReadOnly0(f);
325 } finally {
326 Blocker.end(comp);
327 }
328 }
329 private native boolean setReadOnly0(File f);
330
331 /* -- Filesystem interface -- */
332
333 @Override
334 public File[] listRoots() {
335 try {
336 @SuppressWarnings("removal")
337 SecurityManager security = System.getSecurityManager();
338 if (security != null) {
339 security.checkRead("/");
340 }
341 return new File[] { new File("/") };
342 } catch (SecurityException x) {
343 return new File[0];
344 }
345 }
346
347 /* -- Disk usage -- */
348
349 @Override
350 public long getSpace(File f, int t) {
351 long comp = Blocker.begin();
352 try {
353 return getSpace0(f, t);
354 } finally {
355 Blocker.end(comp);
356 }
357 }
358 private native long getSpace0(File f, int t);
359
360 /* -- Basic infrastructure -- */
361
362 private native long getNameMax0(String path);
363
364 @Override
365 public int getNameMax(String path) {
366 long nameMax = getNameMax0(path);
367 if (nameMax > Integer.MAX_VALUE) {
368 nameMax = Integer.MAX_VALUE;
369 }
370 return (int)nameMax;
371 }
372
373 @Override
374 public int compare(File f1, File f2) {
375 return f1.getPath().compareTo(f2.getPath());
376 }
|
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 java.io;
27
28 import java.util.Properties;
29 import jdk.internal.util.StaticProperty;
30 import sun.security.action.GetPropertyAction;
31
32 final class UnixFileSystem extends FileSystem {
33
34 private final char slash;
35 private final char colon;
36 private final String userDir;
37
38 UnixFileSystem() {
39 Properties props = GetPropertyAction.privilegedGetProperties();
40 slash = props.getProperty("file.separator").charAt(0);
41 colon = props.getProperty("path.separator").charAt(0);
42 userDir = StaticProperty.userDir();
43 }
44
45 /* -- Normalization and construction -- */
46
47 @Override
48 public char getSeparator() {
143 }
144
145 @Override
146 public boolean isInvalid(File f) {
147 return f.getPath().indexOf('\u0000') >= 0;
148 }
149
150 @Override
151 public String resolve(File f) {
152 if (isAbsolute(f)) return f.getPath();
153 @SuppressWarnings("removal")
154 SecurityManager sm = System.getSecurityManager();
155 if (sm != null) {
156 sm.checkPropertyAccess("user.dir");
157 }
158 return resolve(userDir, f.getPath());
159 }
160
161 @Override
162 public String canonicalize(String path) throws IOException {
163 return canonicalize0(path);
164 }
165 private native String canonicalize0(String path) throws IOException;
166
167 /* -- Attribute accessors -- */
168
169 private native int getBooleanAttributes0(File f);
170
171 @Override
172 public int getBooleanAttributes(File f) {
173 int rv = getBooleanAttributes0(f);
174 return rv | isHidden(f);
175 }
176
177 @Override
178 public boolean hasBooleanAttributes(File f, int attributes) {
179 int rv = getBooleanAttributes0(f);
180 if ((attributes & BA_HIDDEN) != 0) {
181 rv |= isHidden(f);
182 }
183 return (rv & attributes) == attributes;
184 }
185
186 private static int isHidden(File f) {
187 return f.getName().startsWith(".") ? BA_HIDDEN : 0;
188 }
189
190 @Override
191 public boolean checkAccess(File f, int access) {
192 return checkAccess0(f, access);
193 }
194 private native boolean checkAccess0(File f, int access);
195
196 @Override
197 public long getLastModifiedTime(File f) {
198 return getLastModifiedTime0(f);
199 }
200 private native long getLastModifiedTime0(File f);
201
202 @Override
203 public long getLength(File f) {
204 return getLength0(f);
205 }
206 private native long getLength0(File f);
207
208 @Override
209 public boolean setPermission(File f, int access, boolean enable, boolean owneronly) {
210 return setPermission0(f, access, enable, owneronly);
211 }
212 private native boolean setPermission0(File f, int access, boolean enable, boolean owneronly);
213
214 /* -- File operations -- */
215
216 @Override
217 public boolean createFileExclusively(String path) throws IOException {
218 return createFileExclusively0(path);
219 }
220 private native boolean createFileExclusively0(String path) throws IOException;
221
222 @Override
223 public boolean delete(File f) {
224 return delete0(f);
225 }
226 private native boolean delete0(File f);
227
228 @Override
229 public String[] list(File f) {
230 return list0(f);
231 }
232 private native String[] list0(File f);
233
234 @Override
235 public boolean createDirectory(File f) {
236 return createDirectory0(f);
237 }
238 private native boolean createDirectory0(File f);
239
240 @Override
241 public boolean rename(File f1, File f2) {
242 return rename0(f1, f2);
243 }
244 private native boolean rename0(File f1, File f2);
245
246 @Override
247 public boolean setLastModifiedTime(File f, long time) {
248 return setLastModifiedTime0(f, time);
249 }
250 private native boolean setLastModifiedTime0(File f, long time);
251
252 @Override
253 public boolean setReadOnly(File f) {
254 return setReadOnly0(f);
255 }
256 private native boolean setReadOnly0(File f);
257
258 /* -- Filesystem interface -- */
259
260 @Override
261 public File[] listRoots() {
262 try {
263 @SuppressWarnings("removal")
264 SecurityManager security = System.getSecurityManager();
265 if (security != null) {
266 security.checkRead("/");
267 }
268 return new File[] { new File("/") };
269 } catch (SecurityException x) {
270 return new File[0];
271 }
272 }
273
274 /* -- Disk usage -- */
275
276 @Override
277 public long getSpace(File f, int t) {
278 return getSpace0(f, t);
279 }
280 private native long getSpace0(File f, int t);
281
282 /* -- Basic infrastructure -- */
283
284 private native long getNameMax0(String path);
285
286 @Override
287 public int getNameMax(String path) {
288 long nameMax = getNameMax0(path);
289 if (nameMax > Integer.MAX_VALUE) {
290 nameMax = Integer.MAX_VALUE;
291 }
292 return (int)nameMax;
293 }
294
295 @Override
296 public int compare(File f1, File f2) {
297 return f1.getPath().compareTo(f2.getPath());
298 }
|