What's the difference between getUsableSpace and getUnallocatedSpace of FileStore class

java, nio

Solution

From the FileStore class documentation

getUnallocatedSpace() Returns the number of unallocated bytes in the file store.

getUsableSpace() Returns the number of bytes available to this Java virtual machine on the file store.

So there is possibly more unallocated space than usable space.

You can test it with the following code snippet

import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.FileSystems;

public class TestFileStore {
    public static void main(String[] args) throws IOException {
        for (FileStore fileStore : FileSystems.getDefault().getFileStores()) {
            System.out.println(fileStore.name());
            System.out.println("Unallocated space: " + fileStore.getUnallocatedSpace());
            System.out.println("Unused space: " + fileStore.getUsableSpace());
            System.out.println("************************************");
        }
    }
}

This is an excerpt of my output

************************************
tmpfs
Unallocated space: 206356480
Unused space: 206356480
************************************
/dev/sda6
Unallocated space: 1089933312
Unused space: 790126592
************************************

Problem

I've read the definition in the documentation and performed some searches on the Internet, but it is still not clear to me. What's the difference between `getUsableSpace()` and `getUnallocatedSpace()` in the `FileStore` class?

Original source