What's new

filefrag command

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

noric

Senior Member
I'd like to use this script to check file fragmentation:

Code:
#!/usr/bin/perl -w

#this script search for frag on a fs
use strict;

#number of files
my $files = 0;
#number of fragment
my $fragments = 0;
#number of fragmented files
my $fragfiles = 0;

my $verbose;

if ($ARGV[0] eq '-v') { shift @ARGV; $verbose++; }

open (REPORT, "find " . $ARGV[0] . " -xdev -type f -print0 | xargs -0 filefrag |");

while (defined (my $res = <REPORT>)) {
        if ($res =~ m/.*:\s+(\d+) extents? found$/) {
                my $fragment = $1;
                $fragments += $fragment;
                if ($fragment > 1) {
                        $fragfiles++;
                }
                $files++;
        } else {
                print ("Failed to parse: $res\n");
        }
}
close (REPORT);

if ($verbose) {
   print "Total files:      $files\n";
   print "Fragmented files: $fragfiles\n";
   print "Fragments:        $fragments\n";
}

sub round($$) {
   my $v = shift; # value
   my $p = shift; # rouding divisor (1 for '123', 10 for '123.4', 100 for '123.45')
   return int($v * $p) / $p;
}
print ( $fragfiles / $files * 100 . "% non contiguous files, " . $fragments / $files . " average fragments.\n");

As you can see it needs the filefrag command, that appears to be missing. I've tried to install e2fsprogs (from entware) but it doesn't include filefrag.
Do you know where can I find it?
Thanks.
 
That's what I thought when I installed e2fsprogs, but it's not there.
Could it be that the entware package of e2fsprogs is different than optware's? This is what I think I understood from a Russian forum using google translate.
 
Now the script runs, but I encounter the following error:
Code:
Failed to parse: /mnt/sda1/Media/<<video1.avi>>: 13 extents found, perfection would be 7 extents

Failed to parse: /mnt/sda1/Media/<<video2.avi>>: 17 extents found, perfection would be 12 extents

...

0% non contiguous files, 1 average fragments.

I see where the error is in the code, but I have no idea what is causing it. :(
 
In case anyone wants to achieve the same as I wanted, I've adopted a simpler solution. I installed e2fsprogs from entware:
Code:
opkg install e2fsprogs
and then I manually use this command:
Code:
filefrag /folder/you/want/to/check/*

Easy as that.
 

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top