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.
- Normal Java File API getFreeSpace() and getUSableSpace() both gives me free disk space, not the free disk quota.
- Tried using Sigar API but could not find any API in Sigar which gives me this.
- 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).
- Tried quota Linux command and it works but I don't want to use system dependent commands. This can be problematic on some flavors.
- 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?