Skip to content

Commit 69b96f9

Browse files
author
Vyom Tewari
committed
8266610: Method RandomAccessFile#length() returns 0 for block devices on linux.
Reviewed-by: alanb, bpb
1 parent 9b76955 commit 69b96f9

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/java.base/unix/native/libjava/io_util_md.c

+13-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
#if defined(__linux__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
3434
#include <sys/ioctl.h>
35+
#include <linux/fs.h>
36+
#include <sys/stat.h>
3537
#endif
3638

3739
#ifdef MACOSX
@@ -245,9 +247,17 @@ handleGetLength(FD fd)
245247
struct stat64 sb;
246248
int result;
247249
RESTARTABLE(fstat64(fd, &sb), result);
248-
if (result == 0) {
249-
return sb.st_size;
250-
} else {
250+
if (result < 0) {
251251
return -1;
252252
}
253+
#ifdef BLKGETSIZE64
254+
if (S_ISBLK(sb.st_mode)) {
255+
uint64_t size;
256+
if(ioctl(fd, BLKGETSIZE64, &size) < 0) {
257+
return -1;
258+
}
259+
return (jlong)size;
260+
}
261+
#endif
262+
return sb.st_size;
253263
}

0 commit comments

Comments
 (0)