Path: utzoo!mnetor!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!mailrus!ames!hc!beta!unm-la!unmvax!titan!dieter From: dieter@titan.nmt.edu (Dieter Muller) Newsgroups: comp.unix.questions Subject: Re: checking disk space from c program Message-ID: <156@titan.nmt.edu> Date: 11 Apr 88 11:20:02 GMT References: <398@wpg.UUCP> <71@kenobi.UUCP> <3448@csli.STANFORD.EDU> Reply-To: dieter@titan.UUCP (Dieter Muller) Organization: New Mexico Tech, Socorro NM Lines: 67 In article <3448@csli.STANFORD.EDU> gandalf@csli.stanford.edu (Juergen Wagner) writes: >In article <71@kenobi.UUCP> ford@kenobi.UUCP (Mike Ditto) writes: >>... >>Read /etc/mnttab to see what devices are mounted, and use the ustat >>system call to check the status of each.... >>... > >The problem with ustat is that it doesn't exist on BSD systems (even on >Suns), and the problem with stat is that you can't get the whole >information without actually reading the super-block, i.e. without having >root privileges. Normal users have to stick with "df" pipes thru some >filter. If you have a Sun, what's wrong with statfs? True, it isn't on our 4.3BSD Vax, and it doesn't seem real happy with NFS, but it's there and it works (SunOS 3.5). Here's an example: Filesystem: /titan1 Block size: 1024 Num blocks: 490369 Total free: 97943 Avail free: 48906 Total nodes: 96256 Free nodes: 77991 Looks like exactly what was asked for. Yes, I know all the world's not a Sun. The code for this example follows. I didn't run it as root. Dieter Muller ---------------- #include #include #include main () { struct statfs buffer; if (statfs ("/titan1", & buffer) == -1) perror ("/titan1"); else print_statfs ("/titan1", & buffer); exit (0); } print_statfs (name, buffer) char * name; struct statfs * buffer; { printf ("Filesystem: %s\n", name); printf ("Block size: %d\n", buffer -> f_bsize); printf ("Num blocks: %d\n", buffer -> f_blocks); printf ("Total free: %d\n", buffer -> f_bfree); printf ("Avail free: %d\n", buffer -> f_bavail); printf ("Total nodes: %d\n", buffer -> f_files); printf ("Free nodes: %d\n", buffer -> f_ffree); fflush (stdout); return; } -- ...{cmcl2, ihnp4}!lanl!unm-la!unmvax!nmtsun!dieter ...gemini!crunch!unmvax!nmtsun!dieter dieter@nmtsun.nmt.edu