Re: finding how much the file system is full, from a C program?



On Mon, 30 Oct 2006 07:10:45 UTC, SM Ryan
<wyrmwif@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

prasadjoshi124@xxxxxxxxx wrote:
# Hi All,
#
# I am writing a small tool which is supposed to fill the filesystem to a
# specified percent.
#
# For, that I need to read how much the file system is full in percent,
# like the output given by df -k
#
# lopgod10:~/mycrfile # df -k /mnt/mvdg1/vset
# Filesystem 1K-blocks Used Available Use% Mounted on
# /dev/vx/dsk/mvdg1/vsetdg1
# 1536000 349854 1112370 24% /mnt/mvdg1/vset
#
# How can I do it from a C program.

In ANSI C you can do something like
system("df -k /mnt/mvdg1/vset >/tmp/df-k");

That is not ANSI C. The parameter of system is system dependant and
unportable.
On my system is no directory mnt.

FILE *f = fopen("/tmp/dfk","r");

Not ANSI C but system dependant. ANSI C knows nothing about pathes,
directories and so on.

(read f and parse df output)
fclose(f);

On unices you can do
FILE *f = popen("df -k /mnt/mvdg1/vset >/tmp/df-k");
(read f and parse df output)
pclose(f);



--
Tschau/Bye
Herbert

Visit http://www.ecomstation.de the home of german eComStation
eComStation 1.2 Deutsch ist da!
.



Relevant Pages