>From the OSX admin mailing list, a little bit of code I wrote...
>>>>> "Andrew" == Andrew Shugg <[EMAIL PROTECTED]> writes:
Andrew> If you grok Perl you could use h2xs(1) against the .h files references
Andrew> in statfs(2) and then write your wrapper in Perl rather than C. (There
Andrew> are so many ways...) OTOH there's nothing wrong with the AppleScript
Andrew> solution already suggested, if you want to do it that way.
Here's a Perl solution using Inline::C (from the CPAN):
#!/usr/bin/perl
use Inline C => <<'END';
#include <sys/param.h>
#include <sys/mount.h>
void get_statfs(SV* sv_path) {
Inline_Stack_Vars;
struct statfs buf;
Inline_Stack_Reset;
if (!statfs(SvPV(sv_path, PL_na), &buf)) {
Inline_Stack_Push(newSViv(buf.f_type));
Inline_Stack_Push(newSViv(buf.f_flags));
Inline_Stack_Push(newSViv(buf.f_bsize));
Inline_Stack_Push(newSViv(buf.f_iosize));
Inline_Stack_Push(newSViv(buf.f_blocks));
Inline_Stack_Push(newSViv(buf.f_bfree));
Inline_Stack_Push(newSViv(buf.f_bavail));
Inline_Stack_Push(newSViv(buf.f_files));
Inline_Stack_Push(newSViv(buf.f_ffree));
/* skipping f_fsid */ Inline_Stack_Push(newSViv(0));
Inline_Stack_Push(newSViv(buf.f_owner));
/* f_spare[4] */
Inline_Stack_Push(newSViv(0));
Inline_Stack_Push(newSViv(0));
Inline_Stack_Push(newSViv(0));
Inline_Stack_Push(newSViv(0));
Inline_Stack_Push(newSVpv(buf.f_fstypename, 0));
Inline_Stack_Push(newSVpv(buf.f_mntonname, 0));
Inline_Stack_Push(newSVpv(buf.f_mntfromname, 0));
}
Inline_Stack_Done;
}
END
for (@ARGV) {
my @s = get_statfs($_) or warn("$_: $!\n"), next;
print "$_: $s[15]\n";
}
It's general, returning the entire statfs buffer. You could simplify
it by ripping everything out of the inside except the one with
fstypename. But I was pleasantly surprised when it worked the first
time it compiled. (I won't tell you how many tries I had to do to get
it to compile. :)
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!