< prev index next >

src/solaris/native/sun/nio/ch/FileDispatcherImpl.c

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 21,30 **** --- 21,34 ---- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ + #if defined(__linux__) + #define _FILE_OFFSET_BITS 64 + #endif + #include "jni.h" #include "jni_util.h" #include "jvm.h" #include "jlong.h" #include "sun_nio_ch_FileDispatcherImpl.h"
*** 176,185 **** --- 180,213 ---- return handle(env, ftruncate64(fdval(env, fdo), size), "Truncation failed"); } + JNIEXPORT jint JNICALL + Java_sun_nio_ch_FileDispatcherImpl_allocate0(JNIEnv *env, jobject this, + jobject fdo, jlong size) + { + #if defined(__linux__) + /* + * On Linux, if the file size is being increased, then ftruncate64() + * will modify the metadata value of the size without actually allocating + * any blocks which can cause a SIGBUS error if the file is subsequently + * memory-mapped. + */ + // Return on success or if errno is neither EOPNOTSUPP nor ENOSYS + int result = posix_fallocate(fdval(env, fdo), 0, size); + if (result == 0) { + return 0; + } else if (errno != EOPNOTSUPP && errno != ENOSYS) { + return handle(env, result, "Allocation failed"); + } + #endif + return handle(env, + ftruncate64(fdval(env, fdo), size), + "Truncation failed"); + } + JNIEXPORT jlong JNICALL Java_sun_nio_ch_FileDispatcherImpl_size0(JNIEnv *env, jobject this, jobject fdo) { jint fd = fdval(env, fdo); struct stat64 fbuf;
< prev index next >