#!/usr/bin/perl # # ndf -- perl reimplementation of df # # tchrist@mox.perl.com # v1.? require 5.001; # not sure whether this is so # modules used: English, Getopt::Std (standard), dfent (supplied) parse_options(); gen_output(); exit ($errors != 0); ############################################################################ sub parse_options { use Getopt::Std; getopts("5pblait:") || usage("Bad option"); if ($opt_b + $opt_i + $opt_5 + $opt_l + $opt_p > 1) { usage("More than one of -[bi5lp] specified"); } $just_inode = $opt_i; $sys5 = $opt_5; $bsd = $opt_b || 1; $long_form = $opt_l; $parsable = $opt_p; $want_type = $opt_t; $even_boring = $opt_a; use English; ($FORMAT_NAME, $FORMAT_TOP_NAME) = do { if ($long_form) { qw( Long Long_Top ) } elsif ($just_inode) { qw( Inodes Inodes_Top ) } elsif ($sys5) { qw( SysV SysV_Top ) } elsif ($bsd) { qw( BSD BSD_Top ) } else { die " No format?" } }; } ##################################### sub usage { warn "$0: @_\n" if @_; die <blksize() / 1024 . 'k'; next if $want_type && $type !~ /\b\Q$want_type\E\b/o; next ARG unless $kbytes or $even_boring; if ($parsable) { print join('=', $filesystem, $kbytes, $ubytes, $kavail, $kcapacity, $inodes, $iavail, $icapacity, $mountpoint ), "\n"; } else { if (length($filesystem) > 18) { # painful hack print "$filesystem\n"; $filesystem = ''; } write; } } } ################################################################# ### standard format ################### format BSD_Top = Filesystem kbytes used avail capacity Mounted on . format BSD = @<<<<<<<<<<<<<<<<<< @>>>>>>> @>>>>>> @>>>>>> @>>> @* $filesystem, $kbytes, $kused, $kavail, $kcapacity.'%', $mountpoint . ################################################################# ### -i flag #################### format Inodes_Top = Filesystem bsize iused ifree %iused Mounted on . format Inodes = @<<<<<<<<<<<<<<<<<< @>>>> @>>>>>>> @>>>>>> @>>> @* $filesystem, $bsize, $iused, $iavail, $icapacity.'%', $mountpoint . ################################################################# ### -5 flag ################# format SysV_Top = Filesystem bavail iavail btotal itotal Mounted on . format SysV = @<<<<<<<<<<<<<<<<<< @>>>>>>> @>>>>>> @>>>>>> @>>>>>> @* $filesystem, $kavail*2,$iavail,$kbytes*2,$inodes,$mountpoint . ################################################################# ### -l flag ################# format Long_Top = Filesystem kroot kuser kfree k% itotal ifree i% Mounted on . format Long = @<<<<<<<<<<<<<<< @>>>>>>> @>>>>>> @>>>>>> @>>> @>>>>> @>>>>> @>>> @* { $filesystem, $kbytes, $ubytes, $kavail,$kcapacity.'%', $inodes,$iavail,$icapacity.'%', $mountpoint } .