I've read quite a bit on perlmonks about various ways to determine disk usage, a la
df or
du, but examples mostly tally up file sizes under a particular directory (
Merlyn's example), or they depend on
df or
du (
Mr. Leisure's example,
halxd2's example,
Hawson's example). Most of the examples seem geared toward reporting how much size is taken up by a user, for billing purposes.
I want to determine if there is enough room on a volume to write a file, so I need to know not how much space is currently used on the disk, but how much space is left. The examples that come closest to this requirement still use a system call.
The biggest problem with system calls is that you restrict yourself to a single platform. I need this script to run on both Linux and Windows. I also don't want to use very many modules, because often our customers do not allow extra modules to be loaded on their systems (think very large companies with very tight security and concern for software support -- and perhaps a prohibitively inefficient IT group).
My question, then, is, "How do I calculate total blocks on a volume?" I figure that I can use File::Find and lstat to get the blocks used, subtract that value from total blocks, and get blocks available. Perhaps another question should be, "Am I missing an easy way to determine total blocks available?"