# Disk usage



## balanga (Mar 14, 2017)

Is there any way of determining disk usage of a given disk without having access to the file system? I'm trying to find out how much free space is available on a disk.

I guess I'm looking for something equivalent to `du /dev/ada0`...


----------



## SirDice (Mar 14, 2017)

There's no way to know how much is used if you cannot access the filesystem. It's the filesystem that stores that information.


----------



## balanga (Mar 14, 2017)

I thought there might be some way to read each sector on a disk and determine if it had been written to at some point...


----------



## SirDice (Mar 14, 2017)

Sure, you could theoretically just read some blocks and interpret the data. But it'll be easier just to mount it.


----------



## Beastie (Mar 14, 2017)

balanga said:


> I thought there might be some way to read each sector on a disk and determine if it had been written to at some point...


Considering that, most of the time, removing a file won't zeroize sectors that were once allocated to that file, this method may give you highly erroneous results. For example, if I fill an entire disk with millions of files and then remove them all, analyzing the disk as a raw device and looking for blank sectors will show zero free space.
Only proper analysis of filesystem structures will give you valid results.


----------



## SirDice (Mar 14, 2017)

Beastie said:


> For example, if I fill an entire disk with millions of files and then remove them all, analyzing the disk as a raw device and looking for blank sectors will show zero free space.


You typically read the FAT (File Allocation Table) or BAM (Block Availability Map), not the actual blocks.


----------

