#!/usr/bin/env perl use warnings; use strict; use File::Spec; use Getopt::Std; use Fcntl; use constant BUF_SIZE => 4096; require 'syscall.ph'; my %opts; getopts( 'd:', \%opts ); die 'option -d is required' unless ( ( exists( $opts{d} ) ) and ( defined( $opts{d} ) ) ); sysopen( my $fd, $opts{d}, O_RDONLY | O_DIRECTORY ); open(my $out,'>:raw','perldata.bin') or die $!; while (1) { my $buf = "\0" x BUF_SIZE; my $read = syscall( &SYS_getdents, fileno($fd), $buf, BUF_SIZE ); if ( ( $read == -1 ) and ( $! != 0 ) ) { die "failed to syscal getdents: $!"; } print $out($buf); close($out); # last; # from this point forward, this will enter in a infinite loop because $len is being set with 0 last if ( $read == 0 ); while ( $read != 0 ) { my ( $ino, $off, $len, $name ) = unpack( "LLSZ*", $buf ); unless ( ( $name eq '.' ) or ( $name eq '..' ) ) { my $path = File::Spec->catfile( $opts{d}, $name ); print $path,"\n"; } substr( $buf, 0, $len ) = ''; $read -= $len; } }