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

StackOverflow https://stackoverflow.com/questions/9034435

  •  20-04-2021
  •  | 
  •  

質問

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  - 
役に立ちましたか?

解決

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

他のヒント

The df -kP command returns the free space, but the most universal way is to use

Apache Commons IO FileSystemUtils.freeSpaceKb("/volume");

it utilize df as well as dir for Windows

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

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top