Skip to contentSkip to conversation

libe2p: Add new function e2p_get_fragscore()

PATCH New Kazuya Mio 1 participant 1 message Nov 14, 2011

lore
Share & tools
lore

Kazuya Mio

author
#0 lore raw

PATCH v3 1/11 libe2p: Add new function e2p_get_fragscore()

This patch adds e2p_get_fragscore() to libe2p. e2p_get_fragscore() returns the fragmentation score. If the number of extents per specified blocks is smaller than 1, the fragmentation score is set to zero that means the file has no fragmentation. On the other hand, if it is bigger than 1,
the fragmentation score is set to more than 1 that means the file has bad fragmentation. The higher fragmentation score means the worse fragmentation.

Fragmentation score treats extents, whose file offset continues and whose status is the same, as one chunk. If the number of extents in chunk is equal to the ideal number of extents, the chunk is not used for the fragmentation score because there is no fragmentation in the chunk. The ideal number of extents is calculated based on @max_chunk_blks.

---
 lib/e2p/Makefile.in      |    6 +-
 lib/e2p/e2p.h            |    3 +
 lib/e2p/fragment_score.c |  133 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 140 insertions(+), 2 deletions(-)
lib/e2p/Makefile.in +4 -2
index e2d0940..b0a1398 100644
@@ -19,7 +19,7 @@ all::	e2p.pc
 OBJS=		feature.o fgetflags.o fsetflags.o fgetversion.o fsetversion.o \
 		getflags.o getversion.o hashstr.o iod.o ls.o mntopts.o \
 		parse_num.o pe.o pf.o ps.o setflags.o setversion.o uuid.o \
-		ostype.o percent.o
+		ostype.o percent.o fragment_score.o
 
 SRCS=		$(srcdir)/feature.c $(srcdir)/fgetflags.c \
 		$(srcdir)/fsetflags.c $(srcdir)/fgetversion.c \
@@ -28,7 +28,7 @@ SRCS=		$(srcdir)/feature.c $(srcdir)/fgetflags.c \
 		$(srcdir)/ls.c $(srcdir)/mntopts.c $(srcdir)/parse_num.c \
 		$(srcdir)/pe.c $(srcdir)/pf.c $(srcdir)/ps.c \
 		$(srcdir)/setflags.c $(srcdir)/setversion.c $(srcdir)/uuid.c \
-		$(srcdir)/ostype.c $(srcdir)/percent.c
+		$(srcdir)/ostype.c $(srcdir)/percent.c $(srcdir)/fragment_score.c
 HFILES= e2p.h
 
 LIBRARY= libe2p
@@ -182,3 +182,5 @@ ostype.o: $(srcdir)/ostype.c $(top_builddir)/lib/config.h \
 percent.o: $(srcdir)/percent.c $(top_builddir)/lib/config.h \
  $(top_builddir)/lib/dirpaths.h $(srcdir)/e2p.h \
  $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h
+fragment_score.o: $(srcdir)/fragment_score.c $(srcdir)/e2p.h \
+ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h
lib/e2p/e2p.h +3 -0
index 4a68dd9..5881256 100644
@@ -72,3 +72,6 @@ char *e2p_os2string(int os_type);
 int e2p_string2os(char *str);
 
 unsigned int e2p_percent(int percent, unsigned int base);
+
+unsigned int e2p_get_fragscore(int fd, unsigned int threshold,
+			unsigned int max_chunk_blks, int *errp);
lib/e2p/fragment_score.c new file +133 -0

133 lines not on this page · raw message