@Override protected void doSync(boolean metadata) throws IOException { int fd = fd(); if (metadata) { fsyncFd(fd); } else { fdatasyncFd(fd); } }
@Override protected long doLength() throws IOException { return lseekEndFd(fd(), 0); }
@Override protected void doRead(long pos, long ptr, int length) throws IOException { preadFd(fd(), ptr, length, pos); }
@Override protected void doSync(boolean metadata) throws IOException { mAccessLatch.acquireShared(); try { int fd = fd(); if (metadata) { fsyncFd(fd); } else { fdatasyncFd(fd); } } finally { mAccessLatch.releaseShared(); } }
@Override protected void doSetLength(long length) throws IOException { ftruncateFd(fd(), length); }
@Override protected void doSync(boolean metadata) throws IOException { mAccessLatch.acquireShared(); try { int fd = fd(); if (metadata) { fsyncFd(fd); } else { fdatasyncFd(fd); } } finally { mAccessLatch.releaseShared(); } }
@Override protected void doWrite(long pos, long ptr, int length) throws IOException { pwriteFd(fd(), ptr, length, pos); }
@Override protected void reopen() throws IOException { closeFd(fd()); EnumSet<OpenOption> options = EnumSet.noneOf(OpenOption.class); if (isReadOnly()) { options.add(OpenOption.READ_ONLY); } if ((mReopenOptions & REOPEN_SYNC_IO) != 0) { options.add(OpenOption.SYNC_IO); } if ((mReopenOptions & REOPEN_NON_DURABLE) != 0) { options.add(OpenOption.NON_DURABLE); } if ((mReopenOptions & REOPEN_DIRECT_IO) != 0) { options.add(OpenOption.DIRECT_IO); } mFileDescriptor = openFd(mFile, options); }
@Override protected void doWrite(long pos, long ptr, int length) throws IOException { mAccessLatch.acquireShared(); try { pwriteFd(fd(), ptr, length, pos); } finally { mAccessLatch.releaseShared(); } }
@Override protected void doSetLength(long length) throws IOException { mAccessLatch.acquireShared(); try { ftruncateFd(fd(), length); } finally { mAccessLatch.releaseShared(); } }
@Override protected void doRead(long pos, long ptr, int length) throws IOException { mAccessLatch.acquireShared(); try { preadFd(fd(), ptr, length, pos); } finally { mAccessLatch.releaseShared(); } }
@Override protected long doLength() throws IOException { mAccessLatch.acquireShared(); try { return lseekEndFd(fd(), 0); } finally { mAccessLatch.releaseShared(); } }
@Override protected void doRead(long pos, long ptr, int length) throws IOException { mAccessLatch.acquireShared(); try { preadFd(fd(), ptr, length, pos); } finally { mAccessLatch.releaseShared(); } }
@Override protected void doWrite(long pos, long ptr, int length) throws IOException { mAccessLatch.acquireShared(); try { pwriteFd(fd(), ptr, length, pos); } finally { mAccessLatch.releaseShared(); } }
@Override protected void doSetLength(long length) throws IOException { mAccessLatch.acquireShared(); try { ftruncateFd(fd(), length); } finally { mAccessLatch.releaseShared(); } }
@Override protected long doLength() throws IOException { mAccessLatch.acquireShared(); try { return lseekEndFd(fd(), 0); } finally { mAccessLatch.releaseShared(); } }
@Override protected void reopen() throws IOException { mAccessLatch.acquireShared(); try { closeFd(fd()); EnumSet<OpenOption> options = EnumSet.noneOf(OpenOption.class); if (isReadOnly()) { options.add(OpenOption.READ_ONLY); } if ((mReopenOptions & REOPEN_SYNC_IO) != 0) { options.add(OpenOption.SYNC_IO); } if ((mReopenOptions & REOPEN_NON_DURABLE) != 0) { options.add(OpenOption.NON_DURABLE); } mFileDescriptor = openFd(mFile, options); } finally { mAccessLatch.releaseShared(); } }
@Override protected void reopen() throws IOException { mAccessLatch.acquireShared(); try { closeFd(fd()); EnumSet<OpenOption> options = EnumSet.noneOf(OpenOption.class); if (isReadOnly()) { options.add(OpenOption.READ_ONLY); } if ((mReopenOptions & REOPEN_SYNC_IO) != 0) { options.add(OpenOption.SYNC_IO); } if ((mReopenOptions & REOPEN_NON_DURABLE) != 0) { options.add(OpenOption.NON_DURABLE); } mFileDescriptor = openFd(mFile, options); } finally { mAccessLatch.releaseShared(); } }
@Override protected void preallocate(long pos, long length) throws IOException { if (FallocateHolder.INSTANCE == null) { // Don't have fallocate (or equivalent). Use default non-destructive zero-fill behavior. super.preallocate(pos, length); return; } // Uses posix_fallocate call to quickly allocate blocks and mark them as uninitialized. // If the filesystem supports fallocate then this requires no I/O to the data blocks, // and is much faster than zero-filling the file, which is the fallback behavior. // Since linux 2.6.31 fallocate is supported by at least btrfs, ext4, ocfs2, and // xfs filesystems. Ext4 on Linux 4.2.0 takes ~30 microseconds to fallocate 64MB, // compared to 27 milliseconds to zero-fill that same amount. // // On OSX, uses fcntl with command F_PREALLOCATE. int result = FallocateHolder.INSTANCE.fallocate(fd(), pos, length); if (result != 0) { // Note: the native call above does not set errno. throw new IOException(errorMessage(result)); } }
@Override protected void preallocate(long pos, long length) throws IOException { PlatformIO platform = platform(); if (platform == NullIO.INSTANCE) { // Don't have fallocate (or equivalent). Use default non-destructive zero-fill behavior. super.preallocate(pos, length); return; } // Uses posix_fallocate call to quickly allocate blocks and mark them as uninitialized. // If the filesystem supports fallocate then this requires no I/O to the data blocks, // and is much faster than zero-filling the file, which is the fallback behavior. // Since linux 2.6.31 fallocate is supported by at least btrfs, ext4, ocfs2, and // xfs filesystems. Ext4 on Linux 4.2.0 takes ~30 microseconds to fallocate 64MB, // compared to 27 milliseconds to zero-fill that same amount. // // On OSX, uses fcntl with command F_PREALLOCATE. int result = platform.fallocate(fd(), pos, length); if (result != 0) { // Note: the native call above does not set errno. throw new IOException(errorMessage(result)); } }