# HG changeset patch # User sla # Date 1391772741 -3600 # Node ID 82881d3b4290d0baad0d24cb46689f0e16d33b9d # Parent 1e7db0e1dc1dd31650621e6148ba36ecae3ea521 imported patch io-events-path diff --git a/src/share/classes/java/io/FileInputStream.java b/src/share/classes/java/io/FileInputStream.java --- a/src/share/classes/java/io/FileInputStream.java +++ b/src/share/classes/java/io/FileInputStream.java @@ -51,6 +51,9 @@ /* File Descriptor - handle to the open file */ private final FileDescriptor fd; + /* The path of the referenced file (null if the stream is created with a file descriptor) */ + private final String path; + private FileChannel channel = null; private final Object closeLock = new Object(); @@ -128,6 +131,7 @@ } fd = new FileDescriptor(); fd.attach(this); + path = name; open(name); } @@ -164,6 +168,7 @@ security.checkRead(fdObj); } fd = fdObj; + path = null; /* * FileDescriptor is being shared by streams. @@ -345,7 +350,7 @@ public FileChannel getChannel() { synchronized (this) { if (channel == null) { - channel = FileChannelImpl.open(fd, true, false, this); + channel = FileChannelImpl.open(fd, path, true, false, this); } return channel; } diff --git a/src/share/classes/java/io/FileOutputStream.java b/src/share/classes/java/io/FileOutputStream.java --- a/src/share/classes/java/io/FileOutputStream.java +++ b/src/share/classes/java/io/FileOutputStream.java @@ -67,6 +67,11 @@ */ private FileChannel channel; + /** + * The path of the referenced file (null if the stream is created with a file descriptor) + */ + private final String path; + private final Object closeLock = new Object(); private volatile boolean closed = false; @@ -202,6 +207,7 @@ this.fd = new FileDescriptor(); fd.attach(this); this.append = append; + this.path = name; open(name, append); } @@ -239,6 +245,7 @@ } this.fd = fdObj; this.append = false; + this.path = null; fd.attach(this); } @@ -376,7 +383,7 @@ public FileChannel getChannel() { synchronized (this) { if (channel == null) { - channel = FileChannelImpl.open(fd, false, true, append, this); + channel = FileChannelImpl.open(fd, path, false, true, append, this); } return channel; } diff --git a/src/share/classes/java/io/RandomAccessFile.java b/src/share/classes/java/io/RandomAccessFile.java --- a/src/share/classes/java/io/RandomAccessFile.java +++ b/src/share/classes/java/io/RandomAccessFile.java @@ -62,6 +62,9 @@ private FileChannel channel = null; private boolean rw; + /* The path of the referenced file (null if the stream is created with a file descriptor) */ + private final String path; + private Object closeLock = new Object(); private volatile boolean closed = false; @@ -233,6 +236,7 @@ } fd = new FileDescriptor(); fd.attach(this); + path = name; open(name, imode); } @@ -272,7 +276,7 @@ public final FileChannel getChannel() { synchronized (this) { if (channel == null) { - channel = FileChannelImpl.open(fd, true, rw, this); + channel = FileChannelImpl.open(fd, path, true, rw, this); } return channel; } diff --git a/src/share/classes/sun/nio/ch/FileChannelImpl.java b/src/share/classes/sun/nio/ch/FileChannelImpl.java --- a/src/share/classes/sun/nio/ch/FileChannelImpl.java +++ b/src/share/classes/sun/nio/ch/FileChannelImpl.java @@ -29,10 +29,20 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; -import java.nio.channels.*; +import java.nio.channels.ClosedByInterruptException; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.FileChannel; +import java.nio.channels.FileLock; +import java.nio.channels.FileLockInterruptionException; +import java.nio.channels.NonReadableChannelException; +import java.nio.channels.NonWritableChannelException; +import java.nio.channels.OverlappingFileLockException; +import java.nio.channels.ReadableByteChannel; +import java.nio.channels.WritableByteChannel; +import java.security.AccessController; import java.util.ArrayList; import java.util.List; -import java.security.AccessController; + import sun.misc.Cleaner; import sun.security.action.GetPropertyAction; @@ -56,13 +66,16 @@ // Required to prevent finalization of creating stream (immutable) private final Object parent; + // The path of the referenced file (null if the parent stream is created with a file descriptor) + private final String path; + // Thread-safe set of IDs of native threads, for signalling private final NativeThreadSet threads = new NativeThreadSet(2); // Lock for operations involving position and size private final Object positionLock = new Object(); - private FileChannelImpl(FileDescriptor fd, boolean readable, + private FileChannelImpl(FileDescriptor fd, String path, boolean readable, boolean writable, boolean append, Object parent) { this.fd = fd; @@ -70,23 +83,24 @@ this.writable = writable; this.append = append; this.parent = parent; + this.path = path; this.nd = new FileDispatcherImpl(append); } // Used by FileInputStream.getChannel() and RandomAccessFile.getChannel() - public static FileChannel open(FileDescriptor fd, + public static FileChannel open(FileDescriptor fd, String path, boolean readable, boolean writable, Object parent) { - return new FileChannelImpl(fd, readable, writable, false, parent); + return new FileChannelImpl(fd, path, readable, writable, false, parent); } // Used by FileOutputStream.getChannel - public static FileChannel open(FileDescriptor fd, + public static FileChannel open(FileDescriptor fd, String path, boolean readable, boolean writable, boolean append, Object parent) { - return new FileChannelImpl(fd, readable, writable, append, parent); + return new FileChannelImpl(fd, path, readable, writable, append, parent); } private void ensureOpen() throws IOException { diff --git a/src/solaris/classes/sun/nio/fs/SolarisUserDefinedFileAttributeView.java b/src/solaris/classes/sun/nio/fs/SolarisUserDefinedFileAttributeView.java --- a/src/solaris/classes/sun/nio/fs/SolarisUserDefinedFileAttributeView.java +++ b/src/solaris/classes/sun/nio/fs/SolarisUserDefinedFileAttributeView.java @@ -149,7 +149,7 @@ int afd = openat(fd, nameAsBytes(file,name), (O_RDONLY|O_XATTR), 0); // wrap with channel - FileChannel fc = UnixChannelFactory.newFileChannel(afd, true, false); + FileChannel fc = UnixChannelFactory.newFileChannel(afd, file.toString(), true, false); // read to EOF (nothing we can do if I/O error occurs) try { @@ -190,7 +190,7 @@ UnixFileModeAttribute.ALL_PERMISSIONS); // wrap with channel - FileChannel fc = UnixChannelFactory.newFileChannel(afd, false, true); + FileChannel fc = UnixChannelFactory.newFileChannel(afd, file.toString(), false, true); // write value (nothing we can do if I/O error occurs) try { diff --git a/src/solaris/classes/sun/nio/fs/UnixChannelFactory.java b/src/solaris/classes/sun/nio/fs/UnixChannelFactory.java --- a/src/solaris/classes/sun/nio/fs/UnixChannelFactory.java +++ b/src/solaris/classes/sun/nio/fs/UnixChannelFactory.java @@ -100,10 +100,10 @@ /** * Constructs a file channel from an existing (open) file descriptor */ - static FileChannel newFileChannel(int fd, boolean reading, boolean writing) { + static FileChannel newFileChannel(int fd, String path, boolean reading, boolean writing) { FileDescriptor fdObj = new FileDescriptor(); fdAccess.set(fdObj, fd); - return FileChannelImpl.open(fdObj, reading, writing, null); + return FileChannelImpl.open(fdObj, path, reading, writing, null); } /** @@ -134,7 +134,7 @@ throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed"); FileDescriptor fdObj = open(dfd, path, pathForPermissionCheck, flags, mode); - return FileChannelImpl.open(fdObj, flags.read, flags.write, flags.append, null); + return FileChannelImpl.open(fdObj, path.toString(), flags.read, flags.write, flags.append, null); } /** diff --git a/src/windows/classes/sun/nio/fs/WindowsChannelFactory.java b/src/windows/classes/sun/nio/fs/WindowsChannelFactory.java --- a/src/windows/classes/sun/nio/fs/WindowsChannelFactory.java +++ b/src/windows/classes/sun/nio/fs/WindowsChannelFactory.java @@ -25,22 +25,41 @@ package sun.nio.fs; -import java.nio.file.*; -import java.nio.channels.*; +import static sun.nio.fs.WindowsConstants.CREATE_NEW; +import static sun.nio.fs.WindowsConstants.FILE_ATTRIBUTE_NORMAL; +import static sun.nio.fs.WindowsConstants.FILE_FLAG_DELETE_ON_CLOSE; +import static sun.nio.fs.WindowsConstants.FILE_FLAG_OPEN_REPARSE_POINT; +import static sun.nio.fs.WindowsConstants.FILE_FLAG_OVERLAPPED; +import static sun.nio.fs.WindowsConstants.FILE_FLAG_WRITE_THROUGH; +import static sun.nio.fs.WindowsConstants.FILE_SHARE_DELETE; +import static sun.nio.fs.WindowsConstants.FILE_SHARE_READ; +import static sun.nio.fs.WindowsConstants.FILE_SHARE_WRITE; +import static sun.nio.fs.WindowsConstants.GENERIC_READ; +import static sun.nio.fs.WindowsConstants.GENERIC_WRITE; +import static sun.nio.fs.WindowsConstants.OPEN_ALWAYS; +import static sun.nio.fs.WindowsConstants.OPEN_EXISTING; +import static sun.nio.fs.WindowsConstants.TRUNCATE_EXISTING; +import static sun.nio.fs.WindowsNativeDispatcher.CloseHandle; +import static sun.nio.fs.WindowsNativeDispatcher.CreateFile; +import static sun.nio.fs.WindowsNativeDispatcher.DeviceIoControlSetSparse; +import static sun.nio.fs.WindowsNativeDispatcher.SetEndOfFile; + import java.io.FileDescriptor; import java.io.IOException; -import java.util.*; +import java.nio.channels.AsynchronousFileChannel; +import java.nio.channels.FileChannel; +import java.nio.file.LinkOption; +import java.nio.file.OpenOption; +import java.nio.file.StandardOpenOption; +import java.util.Set; -import com.sun.nio.file.ExtendedOpenOption; - +import sun.misc.JavaIOFileDescriptorAccess; +import sun.misc.SharedSecrets; import sun.nio.ch.FileChannelImpl; import sun.nio.ch.ThreadPool; import sun.nio.ch.WindowsAsynchronousFileChannelImpl; -import sun.misc.SharedSecrets; -import sun.misc.JavaIOFileDescriptorAccess; -import static sun.nio.fs.WindowsNativeDispatcher.*; -import static sun.nio.fs.WindowsConstants.*; +import com.sun.nio.file.ExtendedOpenOption; /** * Factory to create FileChannels and AsynchronousFileChannels. @@ -157,7 +176,7 @@ throw new IllegalArgumentException("APPEND + TRUNCATE_EXISTING not allowed"); FileDescriptor fdObj = open(pathForWindows, pathToCheck, flags, pSecurityDescriptor); - return FileChannelImpl.open(fdObj, flags.read, flags.write, flags.append, null); + return FileChannelImpl.open(fdObj, pathForWindows, flags.read, flags.write, flags.append, null); } /**