tags:

views:

520

answers:

2

Using java, how do you get the amount of free space on a solaris zfs file system?

I have a SunFire x4140 with built-in hdd mounted as /. It also has a connected JBOD with 7.6TB of HDD space, configured as a ZFS file system and mounted as /app.

I use java.io.File.getUsableSpace or java.io.File.getFreeSpace to get the amount of free space on the file system. On / (the on-board) HDD FS it works correctly.

On /app (the zfs partition) File.getFreeSpace, File.getUsableSpace and File.getTotalSpace all return 0 (zero). Does anyone know why? Does java.io.File.getUsableSpace work on ZFS, and if so, how?

The following shows the zfs file system on the machine in question:

/usr/sbin/zfs list

NAME                USED  AVAIL  REFER  MOUNTPOINT
internal            196K  98.4G     1K  none
internal/logs        18K  98.4G    18K  /logs
j4200-1             442G  7.57T  2.44K  none
j4200-1/app         442G  7.57T   153M  /app
j4200-1/app@first   442G      -   442G  -
+1  A: 

I don't know why, but you may be take a look at libzfs, that wraps zfs command in a nice java API

dfa
Want to avoid writing file system specific code. But if our current workaround becomes too clumsy this might be considered.
Craig
As you explicitly ask for ZFS I don't quite get why you dismiss this answer. If you want a non file system specific answer you need to rephrase your question.
lothar
A: 

What does the "df" command report? Is that also not reporting free space on zfs correctly?

extraneon
df works 100%. I'm using a workaround/hack, where I call df via processBuilder and parse the output for the available space. Not pretty.
Craig