From 4e68d4c2229a8bee23eba70d40a3a9b9b3bb3c71 Mon Sep 17 00:00:00 2001 From: clamsawd Date: Sat, 9 Jan 2016 12:06:24 +0100 Subject: [PATCH] Tool to calculate the fragmentation --- defragfs | 0 fragmentation | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) mode change 100644 => 100755 defragfs create mode 100755 fragmentation diff --git a/defragfs b/defragfs old mode 100644 new mode 100755 diff --git a/fragmentation b/fragmentation new file mode 100755 index 0000000..711baac --- /dev/null +++ b/fragmentation @@ -0,0 +1,35 @@ +#!/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; + +#search fs for all file +open (FILES, "find " . $ARGV[0] . " -xdev -type f -print0 |"); + +$/ = "\0"; + +while (defined (my $file = )) { + open (FRAG, "-|", "filefrag", $file); + my $res = ; + if ($res =~ m/.*:\s+(\d+) extents? found/) { + my $fragment = $1; + $fragments += $fragment; + if ($fragment > 1) { + $fragfiles++; + } + $files++; + } else { + print ("$res : not understand for $file.\n"); + } + close (FRAG); +} +close (FILES); + +print ( $fragfiles / $files * 100 . "% non contiguous files, " . $fragments / $files . " average fragments.\n");