libe2p: Add new function e2p_get_fragscore()
PATCH v2 1/12 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 | 132 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+), 2 deletions(-)
lib/e2p/Makefile.in +4 -2
@@ -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
@@ -162,3 +162,5 @@ ostype.o: $(srcdir)/ostype.c $(srcdir)/e2p.h \ $(top_srcdir)/lib/ext2fs/ext2_fs.h $(top_builddir)/lib/ext2fs/ext2_types.h percent.o: $(srcdir)/percent.c $(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
@@ -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 +132 -0
132 lines not on this page · raw message