From owner-freebsd-questions@FreeBSD.ORG Mon Feb 18 10:35:39 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3861616A41A for ; Mon, 18 Feb 2008 10:35:39 +0000 (UTC) (envelope-from kamikaze@bsdforen.de) Received: from mail.bsdforen.de (bsdforen.de [212.204.60.79]) by mx1.freebsd.org (Postfix) with ESMTP id EB8E513C44B for ; Mon, 18 Feb 2008 10:35:38 +0000 (UTC) (envelope-from kamikaze@bsdforen.de) Received: from mobileKamikaze.norad (nat-wh-1.rz.uni-karlsruhe.de [129.13.72.169]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.bsdforen.de (Postfix) with ESMTP id D46E8405478; Mon, 18 Feb 2008 11:35:37 +0100 (CET) Message-ID: <47B95F78.2060604@bsdforen.de> Date: Mon, 18 Feb 2008 11:35:36 +0100 From: Dominic Fandrey User-Agent: Thunderbird 2.0.0.9 (X11/20080205) MIME-Version: 1.0 To: Olivier Nicole References: <200802181025.m1IAPdHc060834@banyan.cs.ait.ac.th> In-Reply-To: <200802181025.m1IAPdHc060834@banyan.cs.ait.ac.th> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-questions@freebsd.org Subject: Re: Get the empty space on a file system X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Feb 2008 10:35:39 -0000 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).