1

I have a requirement where I need to get the free user disk quota (not the free disk space) on Linux systems using Java. It is the case where user disk quota can be limited (e.g. 2GB) but the free disk space is quite large (e.g. TB).

Issue is I have some java app running which writes to file system. Before the user disk quota gets fulled, I want to inform user about the same proactively. I tried various solutions but they did not work.

  1. Normal Java File API getFreeSpace() and getUSableSpace() both gives me free disk space, not the free disk quota.
  2. Tried using Sigar API but could not find any API in Sigar which gives me this.
  3. Tried using RandomAccessFile.setLength(SOME_THRESHOLD) to check if SOME_THRESHOLD space is available or not. But it also did not work on Linux system. It creates sparse File which actually gets created of SOME_THRESHOLD length but it does not take actual space (blocks).
  4. Tried quota Linux command and it works but I don't want to use system dependent commands. This can be problematic on some flavors.
  5. One of the way is to actually create SOME_THRESHOLD size file but doing that after every x secs will consume CPU unnecessarily.

My main requirement is there any way which either can give me free user disk quota or allow me to check free space by creating SOME_THRESHOLD size file without being CPU intensive at all.
Please help.

Thanks.

Any help here please?

2
  • 1
    Did you try with File#getUsableSpace()? Returns the number of bytes available to this virtual machine on the partition named by this abstract pathname. When possible, this method checks for write permissions and other operating system restrictions and will therefore usually provide a more accurate estimate of how much new data can actually be written than getFreeSpace(). Commented May 29, 2019 at 11:14
  • Yes, I tried it also and did not work. It does not account for user disk quota. I will add this in my question as well. Commented May 29, 2019 at 11:20

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.