Skip to content

Commit

Permalink
8266610: Method RandomAccessFile#length() returns 0 for block devices…
Browse files Browse the repository at this point in the history
… on linux.

Reviewed-by: alanb, bpb
  • Loading branch information
Vyom Tewari committed May 10, 2021
1 parent 9b76955 commit 69b96f9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/java.base/unix/native/libjava/io_util_md.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@

#if defined(__linux__) || defined(_ALLBSD_SOURCE) || defined(_AIX)
#include <sys/ioctl.h>
#include <linux/fs.h>
#include <sys/stat.h>
#endif

#ifdef MACOSX
Expand Down Expand Up @@ -245,9 +247,17 @@ handleGetLength(FD fd)
struct stat64 sb;
int result;
RESTARTABLE(fstat64(fd, &sb), result);
if (result == 0) {
return sb.st_size;
} else {
if (result < 0) {
return -1;
}
#ifdef BLKGETSIZE64
if (S_ISBLK(sb.st_mode)) {
uint64_t size;
if(ioctl(fd, BLKGETSIZE64, &size) < 0) {
return -1;
}
return (jlong)size;
}
#endif
return sb.st_size;
}

1 comment on commit 69b96f9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.