Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8313368

(fc) FileChannel.size returns 0 on block special files

    XMLWordPrintable

Details

    • b17
    • 20
    • b09
    • generic
    • linux

    Backports

      Description

        ADDITIONAL SYSTEM INFORMATION :
        OS Fedora 34
        Java 20.0.1+9 (temurin build) (but issue seems to be relevant for 20.0.2 also)

        A DESCRIPTION OF THE PROBLEM :
        The implementation of FileChannel.size should use ioctl(BLKGETSIZE64) for block special devices.
        For java 20 it's never called (checked with strace)

        Looks like a regression from https://github.com/openjdk/jdk20/commit/48cc15602b62e81bb179ca9570a1e7d8bbf4d6df

        Java 19 (https://github.com/openjdk/jdk19/blob/master/src/java.base/unix/native/libnio/ch/FileDispatcherImpl.c) imports `<linux/fs.h>` which includes definition of `BLKGETSIZE64`
        Java 20 (https://github.com/openjdk/jdk20/blob/master/src/java.base/unix/native/libnio/ch/UnixFileDispatcherImpl.c) doesn't import, so BLKGETSIZE64 is never defined and ioctl is never called

        REGRESSION : Last worked in version 20

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        - create block device with non-empty size
        - check `blockdev --getsize64 /dev/sample.block` has size not 0
        - run `java SizeError.java`

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        Prints size
        ACTUAL -
        Prints zero and "WRONG"

        ---------- BEGIN SOURCE ----------
        import java.io.IOException;
        import java.nio.channels.FileChannel;
        import java.nio.file.Path;

        public class SizeError {
        public static void main(String[] args) throws IOException {
        var ch = FileChannel.open(Path.of("/dev/sample.block"));
        var size = ch.size();
        System.out.println(size);
        if (size == 0L) System.out.println("WRONG");
        }
        }
        ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

                bpb Brian Burkhalter
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: