Skip to content

Commit 4ba81f6

Browse files
author
Brian Burkhalter
committed
8313368: (fc) FileChannel.size returns 0 on block special files
Reviewed-by: vtewari, alanb
1 parent c1a3f14 commit 4ba81f6

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/java.base/unix/native/libnio/ch/UnixFileDispatcherImpl.c

+6-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
#define fstatvfs64 fstatvfs
4646
#endif
4747

48+
#if defined(__linux__)
49+
#include <linux/fs.h>
50+
#include <sys/ioctl.h>
51+
#endif
52+
4853
#include "jni.h"
4954
#include "nio.h"
5055
#include "nio_util.h"
@@ -169,7 +174,7 @@ Java_sun_nio_ch_UnixFileDispatcherImpl_size0(JNIEnv *env, jobject this, jobject
169174
if (fstat64(fd, &fbuf) < 0)
170175
return handle(env, -1, "Size failed");
171176

172-
#ifdef BLKGETSIZE64
177+
#if defined(__linux__)
173178
if (S_ISBLK(fbuf.st_mode)) {
174179
uint64_t size;
175180
if (ioctl(fd, BLKGETSIZE64, &size) < 0)

test/jdk/java/nio/channels/FileChannel/BlockDeviceSize.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2014, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -22,9 +22,10 @@
2222
*/
2323

2424
/* @test
25-
* @bug 8054029
25+
* @bug 8054029 8313368
2626
* @requires (os.family == "linux")
2727
* @summary Block devices should not report size=0 on Linux
28+
* @run main/manual BlockDeviceSize
2829
*/
2930

3031
import java.io.RandomAccessFile;
@@ -56,8 +57,8 @@ public static void main(String[] args) throws Throwable {
5657
System.err.println("File " + BLK_FNAME + " not found." +
5758
" Skipping test");
5859
} catch (AccessDeniedException ade) {
59-
System.err.println("Access to " + BLK_FNAME + " is denied." +
60-
" Run test as root.");
60+
throw new RuntimeException("Access to " + BLK_FNAME + " is denied."
61+
+ " Run test as root.", ade);
6162
}
6263
}
6364
}

0 commit comments

Comments
 (0)