Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 18 Feb 2008 11:35:36 +0100
From:      Dominic Fandrey <kamikaze@bsdforen.de>
To:        Olivier Nicole <on@cs.ait.ac.th>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Get the empty space on a file system
Message-ID:  <47B95F78.2060604@bsdforen.de>
In-Reply-To: <200802181025.m1IAPdHc060834@banyan.cs.ait.ac.th>
References:  <200802181025.m1IAPdHc060834@banyan.cs.ait.ac.th>

next in thread | previous in thread | raw e-mail | index | archive | help
Olivier Nicole wrote:
> Hi,
> 
> I am writing a C application that would store files in a directory.
> 
> Before it starts storing files, I would like the application to check
> is there is enough space in the file system.
> 
> How to:
> 
> 1) knowing the name of the directory, how toknow the file system it
>    belongs to (not considering symbolic links, I can decide that the
>    directory is always a real path);
> 
> 2) knowing the file system from 1), how to check the remaining space
>    in the file system?
> 
> Thanks in advance,
> 
> olivier

You normally just start writing and deal with the errors that come from full 
file systems when they show up. The C functions set errno accordingly.

The reason is that the system lies about the remainig space. Weather there 
is any space left you may use, depends on the user you're running your 
program as. It would be kinda stupid if your program didn't work because the 
disk was full, even when you're running as root and are permitted to use the 
remaining safety space (8% by default).



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?47B95F78.2060604>