From 6b97f43fee3117f8f49c79830c0771399dba75e1 Mon Sep 17 00:00:00 2001 From: Noctis Ackerman Date: Thu, 6 Dec 2018 23:04:05 +0800 Subject: fs: sdfat: Fix frag_ratio formula When there is no full au in AMAP, if we use the number of non-clean au divides fsi->used_clusters * CLUS_PER_AU(sb), the frag_ratio is always smaller than (or equal with) 100%, which is not right. Actually, frag_ratio should be the the ratio that non-clean aus divides the number of aus if all used_clusters are contiguous. Change-Id: I7c26422f5145c3bd97b9dbfcde133972ce51f1d4 Signed-off-by: Noctis Ackerman --- fs/sdfat/dfr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/sdfat/dfr.c b/fs/sdfat/dfr.c index 2853fe425..abb4710b4 100644 --- a/fs/sdfat/dfr.c +++ b/fs/sdfat/dfr.c @@ -1248,7 +1248,7 @@ defrag_check_defrag_required( frag_ratio = ((amap->n_au - amap->n_clean_au) * 100) / amap->n_full_au; else frag_ratio = ((amap->n_au - amap->n_clean_au) * 100) / - (fsi->used_clusters * CLUS_PER_AU(sb)); + (fsi->used_clusters / CLUS_PER_AU(sb) + 1); /* * Wake-up defrag_daemon: -- cgit v1.2.3