Filesys-Ext2
view release on metacpan or search on metacpan
sub do_files {
my @lines;
my $dir = shift;
my $tot_blocks = 0;
#Pre-lsattr
my @attr = lsattr( map {"$dir/$_"} @_);
for(my $i=0; $i < scalar @_; $i++ ){
my ($blocks, $line) = do_file($dir, $_[$i], $attr[$i]);
$tot_blocks += $blocks;
push @lines, $line;
}
($tot_blocks/2, @lines);
}
sub do_file {
my($dir, $file, $attr) = @_;
my ($dev,undef,$mode,$nlink,$uid,$gid,undef,$size,
undef,$mtime,undef,undef,$blocks) = lstat "$dir/$file";
unless (defined $dev) {
warn "ls: $_: $!\n";
return;
}
my $name = -l _ ? "$file -> ". readlink "$dir/$file" : $file;
#-h the size
my $unit=0;
my @unit=('', 'K', 'M', 'G', 'T');
while( $size>1023 && $unit[$unit+1] ){
$size/=1024;
$unit++
}
$size = substr($size, 0, 3);
chop($size) if index($size, '.') == length($size)-1;
$size = $size . $unit[$unit];
#compress the attr
$attr = defined($attr) ? calcSymMask($attr) : '~~~~~~~~';
$attr =~ y/-//d;
( $blocks,
[$name,
sprintf("%s %3d %-8s %-8s % 4s %s %8s %s\n",
format_mode($mode),
$nlink,
ui($uid, $gid),
$size,
format_time($mtime),
$attr,
$name,
)
]
);
}
sub ui {
($u{$_[0]} ||= getpwuid($_[0]) || $_[0]),
($g{$_[1]} ||= getgrgid($_[1]) || $_[1]);
}
sub format_time {
return $time{$_[0]} if exists $time{$_[0]};
my $timestr;
my($sec, $min, $hour, $day, $mon, $year) = localtime($_[0]);
if( $_[0] < $^T - 180*24*3600 || $_[0] > $^T + 3600 ){
$timestr = sprintf "$mon[$mon] %2d %4d", $day, $year+1900;
}
else{
$timestr = sprintf "$mon[$mon] %2d %02d:%02d", $day, $hour, $min;
}
$time{$_[0]} = $timestr;
}
__END__
=pod
=head1 NAME
ls2.pl - list directory contents with their ext2 and ext3 attributes
=head1 SYNOPSIS
B<ls2.pl> [B<-a>] [F<FILEs>]
=head1 DESCRIPTION
List information about the F<FILEs> (the current directory by default).
Output is in the format of B<ls> -lh merged with the attributes from
B<lsattr> in the second to the last column.
=over
=item -a
Do not hide entries starting with I<.>
=back
=head1 SEE ALSO
L<ls(1)>, L<lsattr(1)>, L<Filesys::Ext2>
=head1 AUTHORS
Jerrad Pierce <jpierce@cpan.org>.
Based upon ls by Mark-Jason Dominus <mjd-perl-lsmode@plover.com>.
Includes portions of Stat::lsStat by
Mark-Jason Dominus <mjd-perl-lsmode@plover.com>.
Human readable size (B<-h>) by James Mastros.
=head1 LICENSE
( run in 1.211 second using v1.01-cache-2.11-cpan-39bf76dae61 )