diff --git a/src/java.base/unix/native/libnio/ch/UnixFileDispatcherImpl.c b/src/java.base/unix/native/libnio/ch/UnixFileDispatcherImpl.c index 37412e1e5f8..a24f0503e55 100644 --- a/src/java.base/unix/native/libnio/ch/UnixFileDispatcherImpl.c +++ b/src/java.base/unix/native/libnio/ch/UnixFileDispatcherImpl.c @@ -45,6 +45,11 @@ #define fstatvfs64 fstatvfs #endif +#if defined(__linux__) +#include <linux/fs.h> +#include <sys/ioctl.h> +#endif + #include "jni.h" #include "nio.h" #include "nio_util.h" @@ -169,7 +174,7 @@ Java_sun_nio_ch_UnixFileDispatcherImpl_size0(JNIEnv *env, jobject this, jobject if (fstat64(fd, &fbuf) < 0) return handle(env, -1, "Size failed"); -#ifdef BLKGETSIZE64 +#if defined(__linux__) if (S_ISBLK(fbuf.st_mode)) { uint64_t size; if (ioctl(fd, BLKGETSIZE64, &size) < 0) diff --git a/test/jdk/java/nio/channels/FileChannel/BlockDeviceSize.java b/test/jdk/java/nio/channels/FileChannel/BlockDeviceSize.java index 496312256be..db3c042275f 100644 --- a/test/jdk/java/nio/channels/FileChannel/BlockDeviceSize.java +++ b/test/jdk/java/nio/channels/FileChannel/BlockDeviceSize.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2023, 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 @@ -22,9 +22,10 @@ */ /* @test - * @bug 8054029 + * @bug 8054029 8313368 * @requires (os.family == "linux") * @summary Block devices should not report size=0 on Linux + * @run main/manual BlockDeviceSize */ import java.io.RandomAccessFile; @@ -56,8 +57,8 @@ public class BlockDeviceSize { System.err.println("File " + BLK_FNAME + " not found." + " Skipping test"); } catch (AccessDeniedException ade) { - System.err.println("Access to " + BLK_FNAME + " is denied." + - " Run test as root."); + throw new RuntimeException("Access to " + BLK_FNAME + " is denied." + + " Run test as root.", ade); } } }