History log of /libcore/luni/src/main/java/java/nio/FileChannelImpl.java
Revision Date Author Comments
d9f7e57f5d09b587d8c8d1bd42b895f7de8fbf54 09-Dec-2014 Narayan Kamath <narayan@google.com> Update ByteBuffer positions in Posix.* functions.

Also add tests in libcore.io.OsTest and update (and simplify)
callers that were updating the position themselves.

bug: 18641009

(cherry picked from commit f3b61eaf1931ae8393e54202a717334a4971ebdf)

Change-Id: I8a810b2dfde7c13278807381bdfe7f532a3481a0
f3b61eaf1931ae8393e54202a717334a4971ebdf 09-Dec-2014 Narayan Kamath <narayan@google.com> Update ByteBuffer positions in Posix.* functions.

Also add tests in libcore.io.OsTest and update (and simplify)
callers that were updating the position themselves.

bug: 18641009

Change-Id: Ie0bbde767489eec1a6ef0158f2b14853d4612f18
8add3229ceb13f2aa5d15b84cc59f5ecc6b90214 17-Apr-2014 Neil Fuller <nfuller@google.com> Add interruptibility/wake on close to FileChannel.lock()

There is no obvious way of automated testing given the test
would have to spawn a separate process to lock a file (and
flock is not available on devices). It has been tested
manually with multiple processes on host and a device.

Bug: 13927110
Change-Id: Ie2e565d4965e7aa6392b0eb32e55cdf50d7f61c5
5d930cadc8f62aee5f18e7921296fe66a54f18ab 24-Apr-2014 Elliott Hughes <enh@google.com> Groundwork towards making the Libcore.os functionality public.

Change-Id: Ie700aa16d91fba53fc5eb2555829cb74d84b12ad
f0d40d662d9dfdb04215c718961765837d2cf00c 11-Apr-2014 Neil Fuller <nfuller@google.com> libcore changes to support asynchronous close interruption

Previously AsynchronousSocketCloseMonitor was used to handle
socket interruption on close. To support the same for
FileChannel it has been renamed to AsynchronousCloseMonitor.
The Java class was already called this.

FileInputStream, FileOutputStream, RandomAccessFile will
now throw IOException if a connection is closed by another
thread during read. Thread.interrupt() continues to have no effect
on streams.

FileChannel will now throw AsynchronousCloseException during
reads and writes if the file is closed, per the documentation.

FileChannel will now throw ClosedByInterruptException during
reads and writes if the thread reading/writing is interrupted.

Note: FileChannel.lock() will probably still not not throw
AsynchronousCloseException, though it probably should.

This change also has impact on external/conscrypt and
frameworks/base.

Change-Id: I37de3e7d1a005a73821221e6156d10b95c595d7a
Bug: 13927110
a990ad5c834bd3292f8f4c5e45c7ff117ffae5ec 27-Jan-2014 Neil Fuller <nfuller@google.com> Fixing FileChannel.truncate() / position()

According to the docs, after calling truncate(x), if position() > x, position()
should be made to equal x. Note: It is to be set to x, not to the actual size
of the file, since truncate() doesn't actually grow the file. Subsequent writes
will grow the file to position().

Bug: 12757843
Change-Id: I5df1fbd59f1a8610bc60575dfa7f1396baf3ed47
105a9405b2e059352185f9ca1138cc8480ccb9bc 27-Apr-2013 Elliott Hughes <enh@google.com> Fix various of the harmony nio tests.

Plus one real bug, in FileChannelImpl. The expectation I've removed was for a
test that doesn't seem to exist in either our tests or the harmony tests.

Change-Id: I1ea99042f3f8897f07ba8b4ad8e9a15f30ace79b
fe5da19e0e366286cd4d95f7628fe9442b9062c8 27-Mar-2013 Elliott Hughes <enh@google.com> Simplify the nio Buffer implementations, and fix MappedByteBuffer.

* Fix the reported bug caused by delegation in the MappedByteBuffer
implementation.

* Collapse the three classes (ReadOnly*, ReadWrite*, and *) used
to implement most buffer types into one class each.

* Rename HeapByteBuffer to ByteArrayBuffer to match its companions.

* Remove BaseByteBuffer.

* Give the classes used to implement asXBuffer sane names (their
existing names were backwards).

Bug: https://code.google.com/p/android/issues/detail?id=53637
Change-Id: I2a7ff4f1d502564389615384324afadabccb04f9
385c6f4303341beb9b091b6d252811b7ca3b9f42 20-Dec-2012 Nick Kralevich <nnk@google.com> FileChannelImpl: Ignore ftruncate failures on non-regular files

Truncate only works on regular files. On other files, such as
UNIX character devices, truncate returns EINVAL, which
causes an IOException to be thrown.

With this change, we now have support for creating a MappedByteBuffer
on UNIX character devices such as /dev/zero, if the underlying
device node supports mmap().

Change-Id: I094371d821b187abe3da32edc411ff76a81b047e
126ab1b546c71137a97cef68cc89267e7f7be634 28-Aug-2012 Elliott Hughes <enh@google.com> Improve nio IllegalArgumentException detail messages.

Bug: 7005326
Change-Id: Ibab8b776865dbed5da062cc683f834a79f068b32
e3d7539b3cb1e763f1ed5832120684468e635d94 10-Jun-2011 Elliott Hughes <enh@google.com> Tidy transferFrom a little.

Other than documentation, the only real change here is to stop using direct
buffers, which doesn't gain us anything (and does have a cost).

Bug: 4109660
Change-Id: Iebf3eb9cee6038af68443cd061718d584040010e
e3b6fa2bf357f2712ab2ee9e8487f157595ea0c7 10-Jun-2011 Elliott Hughes <enh@google.com> Expose pread and pwrite.

And fix FileChannel to use them.

Bug: 4183719
Bug: 3107501
Change-Id: I51114a16522b93bf959b5953bec658e6889054c6
9b510df35b57946d843ffc34cf23fdcfc84c5220 28-May-2011 Elliott Hughes <enh@google.com> Make ErrnoException a checked exception.

Bug: 4486011
Change-Id: I1877ce593d441653f75ab14884aa2d85f52652ad
c03e4ba8cd93513aabda061b00d516b54717c5fb 25-May-2011 Elliott Hughes <enh@google.com> Fix a bug in FileChannel.map.

Found by a Harmony test.

Change-Id: I1f2ba191242dd6236549e6ed4ef77021ad7ae628
f1a10948c7e4caf5a6d9d53b4b3ad99580fc1cea 25-May-2011 Elliott Hughes <enh@google.com> Fix a couple of FileChannel bugs.

FileChannel.read's non-readv(2) overload shares java.io's weird
non-Unix "-1 at EOF" behavior. The readv(2) overloads already had
that, but they had a bug where they'd claim to have copied more
into a buffer than they actually had.

No new tests because these were found by existing Harmony unit tests.

Change-Id: Ia267e5834fd360d71becdd7d1bdd838d03ea6532
2cff86c0c10588a35036fe5bbca83b07f53e1b1d 21-May-2011 Elliott Hughes <enh@google.com> Add a missing parameter check to FileChannel.

If we were rewriting this from scratch, we might want to leave these kinds of
checks to the kernel and just rethrow an appropriate exception when the kernel
complains. But for now, let's at least be consistent.

Change-Id: I31c4d13d033c8f46a632622f1a2ce3f44a6c5701
dbde5bd893290c02bb289460fc61e48eda63daa2 20-May-2011 Elliott Hughes <enh@google.com> FileChannelImpl doesn't need to special-case O_APPEND.

...we have an OS kernel for such things.

Bug: 4455730
Change-Id: I23efc0ceaa534bffdc0da9a5ff1426ff9d56547f
8b15dcc5890963edad4dfcf558cc16027c7985e5 29-Mar-2011 Elliott Hughes <enh@google.com> Add sendfile(2).

This patch marks the end of OSFileSystem.

Having to support a Java "long*" for sendfile(2) gave me an opportunity to go
back and improve my ioctl(2) to use a corresponding "int*" equivalent, instead
of its previous special-case hack.

Bug: 3107501
Change-Id: I9fde4777700552263fab4fe9aeb556174163e3dc
bbac92e691de7d570928ddfba639067978e55b06 29-Mar-2011 Elliott Hughes <enh@google.com> Add readv(2)/writev(2).

The old implementation would cheat if it was given non-direct buffers, copying
them into newly-allocated direct buffers. (The network Channel implementations
are worse: they copy all the data into a single buffer, and then read/write
that. I'll get to them eventually.)

Bug: 3107501
Change-Id: I1655bacb042e7ebcde7e5bc5cf2c71e7ce5e30af
78c7cc547101002b9f9043cf3845970719d1bda8 26-Mar-2011 Elliott Hughes <enh@google.com> Add write(2).

Note that this is a functional change, because the old code was wrong: it
assumed that short writes don't happen. I thought we'd (I'd) cleaned this
up just recently, but it looks like I must have only gone through the network
code. Embarrassing.

This also cleans up the previous read change a bit, factoring out a bit more
duplication, and taking advantage of the fact that we now get decent
exceptions thrown from invalid FileDescriptors (meaning we can remove explicit
checks).

Bug: 3107501
Change-Id: I8bd5324836c9d151dceaef5b84ec523a67391b64
26c7025a7a919044771fb89031161bd26fe03032 26-Mar-2011 Elliott Hughes <enh@google.com> Add read(2).

For both byte[]s and ByteBuffers.

Bug: 3107501
Change-Id: I93b781069ade4507371c8fe8c5fda0163fbb2dbb
fc549a0b0388987b26dea524894d75a63d14783b 25-Mar-2011 Elliott Hughes <enh@google.com> Add fcntl(2).

I initially used overloading, but that actually decreases safety in practice
because which overload you need is (uniquely) determined by the specific
command you're issuing. Forcing callers to explicitly state what they're
doing works around this. As it was, I had to use strace(1) to find my bug.

Bug: 3107501
Change-Id: Ia54b72dd6453372922f01b22f382eb93ac91aaa7
7e25eff38a191d9c19e45093f4fde5102fb09d78 19-Mar-2011 Elliott Hughes <enh@google.com> Add mmap(2), msync(2), and munmap(2).

Bug: 3107501
Change-Id: I6a7c4147ec27bab9ded280476bad1157ce03fab8
dedaccdfa07c370a58cba08b096133ad9eec0ec3 18-Mar-2011 Elliott Hughes <enh@google.com> Add lseek(2).

Bug: 3107501
Change-Id: Ie27e2ae1c7d37de5f02b1d81ee2005182339f881
f5333fd2094bdac4d6506177b1964b79afa64d77 18-Mar-2011 Elliott Hughes <enh@google.com> Add ftruncate(2).

The claim that "the port library" modifies the file offset appears to only ever
have been true of Harmony's Win32 implementation. Certainly, this is not the
behavior of ftruncate(2), so we can lose the cruft.

Bug: 3107501
Change-Id: I35092fd986296b78c4847c7215765f9997339f37
6fc1a0e1e68dc2e0d12341548e58fa7f1c5dafc4 18-Mar-2011 Elliott Hughes <enh@google.com> Add sysconf(3).

This gives us a getpagesize(3) replacement right now, and will let us implement
Runtime.availableProcessors here rather than in the VM in a later change.

Bug: 3107501
Change-Id: I6fc1f83d36b026fbe8d37eca525550479677f2de
47cb338d43f75dd998b29caaaa9446c5705217d1 18-Mar-2011 Elliott Hughes <enh@google.com> Add fstat(2), lstat(2), and stat(2).

Bug: 3107501
Change-Id: Ic36f9ffd03446d6e0189470f42abdadde57327df
52724d3ebd4ccaaa4b9f5576e329d4272cde8ea9 17-Mar-2011 Elliott Hughes <enh@google.com> Add fsync(2) and fdatasync(2).

Interesting parts to this change:
* first BlockGuard support (and general delegation support).
* first rethrowing of ErrnoException as IOException.
* switching FileChannelImpl from int to FileDescriptor.

The special case in FileDescriptor.sync has been removed. Testing with the RI
showed that it doesn't treat syncing a FileDescriptor that corresponds to a
socket as a special case --- it throws SyncFailedException just like normal.

Bug: 3107501
Change-Id: I99faf120bd802aec0397a79772ed38c5e1542fed
6ab5999b58777725b4556e4d81bdec56b6d6c182 16-Mar-2011 Elliott Hughes <enh@google.com> Collapse the FileChannel implementations.

This should be an (in)correctness-preserving transformation, with the exception
of tryLock for read-only channels. Previously, that would unconditionally have
been converted to a waiting lock, which seems like a bug.

Bug: 3107501
Change-Id: Ief216c6f9f0a7dbe72f25c2fb63d983ec288f9a5
cdf7a1f942469221bcfd63d9cdf71851b011eaf0 16-Mar-2011 Elliott Hughes <enh@google.com> Expose POSIX constants.

And use them, too. This patch is a little confusing because we already had
constants in Java that were using the POSIX names but that didn't actually
correspond to the constants whose names they'd stolen. Ugh.

Bug: 3107501
Change-Id: Ib64a109c9340b0ecdf80bec91074206c001f455a
fb0ec0e650bf8be35acb0d47da0311a7c446aa33 14-Jan-2011 Elliott Hughes <enh@google.com> Remove useless android-changed comments.

I've changed useful ones to regular comments or TODOs, as appropriate.

I've left ones in code like java.util.concurrent where we really are
tracking an upstream source, making the change markers useful.

I've left a handful of others where I intend to actually investigate
the implied TODOs before deciding how to resolve them.

Change-Id: Iaf71059b818596351cf8ee5a3cf3c85586051fa6
a1603838fe9e865575c87982e32c6343740e464c 11-Dec-2010 Elliott Hughes <enh@google.com> Lots more bounds-checking/exception-throwing consistency.

Overflow-safe checks all round, plus better detail messages. This isn't
quite everything, but it's a large chunk of the work. Most notably, this
is all of io and nio.

There are numerous changes of exception priority here, and the harmony
tests noticed a subset of them in the nio code. I've modified our checked-out
copy of the tests to accept any of the throwable exceptions.

Change-Id: Id185f1228fb9a1d5fc9494e78375b5623fb0fe14
b46dab348e2007bc08abaf7ecae34d89a2474e50 09-Dec-2010 Elliott Hughes <enh@google.com> Rewrite all backwards comparisons.

Strictly, all the ones I could find. This is everything with 0 or null on the
left-hand side.

Note that this touches several incorrect bounds checks, which I haven't fixed:
I'm going to come back and finish that independent cleanup separately.

Change-Id: Ibdb054b53df9aace47c7d2a00ff19122190053e8
5501a3d4b3d7657c183ed5446fe67fa011fbf70b 03-Dec-2010 Elliott Hughes <enh@google.com> Comments/javadoc should be in en_US, not en_CA.

Change-Id: Ie9dde4971e0a6a8dadd14af43d631158fc488cd8
5e23b687ef8b3c696d54d1880b454942875665b7 22-Sep-2010 Elliott Hughes <enh@google.com> Remove custom marker classes for locks.

Just use Object instead.

Bug: 3024308
Change-Id: I83a01020646d95e014743b76e27ca7134c155298
ae704b984c10a63883cc366e823d53902d6ac7a9 21-Sep-2010 Elliott Hughes <enh@google.com> Minor tidy-up.

The nio implementation is still a bit of a mess because Java doesn't have any
kind of "module" concept, nor "friend". But this makes it a little less untidy,
and makes the deliberate access control subversions a little more explicit, and
makes various things less accessible than they were.

Change-Id: I514b1e24000b91f86b768ed408fedae115dc3080