equal
deleted
inserted
replaced
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 |
25 |
26 package sun.nio.fs; |
26 package sun.nio.fs; |
27 |
27 |
28 import java.security.AccessController; |
|
29 import java.security.PrivilegedAction; |
|
30 |
|
31 /** |
28 /** |
32 * Unix system and library calls. |
29 * Unix system and library calls. |
33 */ |
30 */ |
34 |
31 |
35 class UnixNativeDispatcher { |
32 class UnixNativeDispatcher { |
36 protected UnixNativeDispatcher() { } |
33 protected UnixNativeDispatcher() { } |
37 |
34 |
38 // returns a NativeBuffer containing the given path |
35 // returns a NativeBuffer containing the given path |
39 private static NativeBuffer copyToNativeBuffer(UnixPath path) { |
36 static NativeBuffer copyToNativeBuffer(UnixPath path) { |
40 byte[] cstr = path.getByteArrayForSysCalls(); |
37 byte[] cstr = path.getByteArrayForSysCalls(); |
41 int size = cstr.length + 1; |
38 int size = cstr.length + 1; |
42 NativeBuffer buffer = NativeBuffers.getNativeBufferFromCache(size); |
39 NativeBuffer buffer = NativeBuffers.getNativeBufferFromCache(size); |
43 if (buffer == null) { |
40 if (buffer == null) { |
44 buffer = NativeBuffers.allocNativeBuffer(size); |
41 buffer = NativeBuffers.allocNativeBuffer(size); |
120 * fclose(FILE* stream) |
117 * fclose(FILE* stream) |
121 */ |
118 */ |
122 static native void fclose(long stream) throws UnixException; |
119 static native void fclose(long stream) throws UnixException; |
123 |
120 |
124 /** |
121 /** |
|
122 * void rewind(FILE* stream); |
|
123 */ |
|
124 static native void rewind(long stream) throws UnixException; |
|
125 |
|
126 /** |
|
127 * ssize_t getline(char **lineptr, size_t *n, FILE *stream); |
|
128 */ |
|
129 static native int getlinelen(long stream) throws UnixException; |
|
130 |
|
131 /** |
125 * link(const char* existing, const char* new) |
132 * link(const char* existing, const char* new) |
126 */ |
133 */ |
127 static void link(UnixPath existing, UnixPath newfile) throws UnixException { |
134 static void link(UnixPath existing, UnixPath newfile) throws UnixException { |
128 NativeBuffer existingBuffer = copyToNativeBuffer(existing); |
135 NativeBuffer existingBuffer = copyToNativeBuffer(existing); |
129 NativeBuffer newBuffer = copyToNativeBuffer(newfile); |
136 NativeBuffer newBuffer = copyToNativeBuffer(newfile); |
420 * futimes(int fildes, const struct timeval times[2]) |
427 * futimes(int fildes, const struct timeval times[2]) |
421 */ |
428 */ |
422 static native void futimes(int fd, long times0, long times1) throws UnixException; |
429 static native void futimes(int fd, long times0, long times1) throws UnixException; |
423 |
430 |
424 /** |
431 /** |
|
432 * futimens(int fildes, const struct timespec times[2]) |
|
433 */ |
|
434 static native void futimens(int fd, long times0, long times1) throws UnixException; |
|
435 |
|
436 /** |
425 * lutimes(const char* path, const struct timeval times[2]) |
437 * lutimes(const char* path, const struct timeval times[2]) |
426 */ |
438 */ |
427 static void lutimes(UnixPath path, long times0, long times1) |
439 static void lutimes(UnixPath path, long times0, long times1) |
428 throws UnixException |
440 throws UnixException |
429 { |
441 { |
594 /** |
606 /** |
595 * Capabilities |
607 * Capabilities |
596 */ |
608 */ |
597 private static final int SUPPORTS_OPENAT = 1 << 1; // syscalls |
609 private static final int SUPPORTS_OPENAT = 1 << 1; // syscalls |
598 private static final int SUPPORTS_FUTIMES = 1 << 2; |
610 private static final int SUPPORTS_FUTIMES = 1 << 2; |
599 private static final int SUPPORTS_LUTIMES = 1 << 4; |
611 private static final int SUPPORTS_FUTIMENS = 1 << 4; |
|
612 private static final int SUPPORTS_LUTIMES = 1 << 8; |
600 private static final int SUPPORTS_BIRTHTIME = 1 << 16; // other features |
613 private static final int SUPPORTS_BIRTHTIME = 1 << 16; // other features |
601 private static final int capabilities; |
614 private static final int capabilities; |
602 |
615 |
603 /** |
616 /** |
604 * Supports openat and other *at calls. |
617 * Supports openat and other *at calls. |
613 static boolean futimesSupported() { |
626 static boolean futimesSupported() { |
614 return (capabilities & SUPPORTS_FUTIMES) != 0; |
627 return (capabilities & SUPPORTS_FUTIMES) != 0; |
615 } |
628 } |
616 |
629 |
617 /** |
630 /** |
|
631 * Supports futimens |
|
632 */ |
|
633 static boolean futimensSupported() { |
|
634 return (capabilities & SUPPORTS_FUTIMENS) != 0; |
|
635 } |
|
636 |
|
637 /** |
618 * Supports lutimes |
638 * Supports lutimes |
619 */ |
639 */ |
620 static boolean lutimesSupported() { |
640 static boolean lutimesSupported() { |
621 return (capabilities & SUPPORTS_LUTIMES) != 0; |
641 return (capabilities & SUPPORTS_LUTIMES) != 0; |
622 } |
642 } |
628 return (capabilities & SUPPORTS_BIRTHTIME) != 0; |
648 return (capabilities & SUPPORTS_BIRTHTIME) != 0; |
629 } |
649 } |
630 |
650 |
631 private static native int init(); |
651 private static native int init(); |
632 static { |
652 static { |
633 AccessController.doPrivileged(new PrivilegedAction<>() { |
653 jdk.internal.loader.BootLoader.loadLibrary("nio"); |
634 public Void run() { |
|
635 System.loadLibrary("nio"); |
|
636 return null; |
|
637 }}); |
|
638 capabilities = init(); |
654 capabilities = init(); |
639 } |
655 } |
640 } |
656 } |