summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXiaogang Cui <xiaogang@codeaurora.org>2014-04-09 19:30:53 +0800
committerAdnan Begovic <adnan@cyngn.com>2015-10-07 17:39:54 -0700
commit53020727b8f86203bb8a1f6a65d8a70f17755bf4 (patch)
tree0dbf21ef72290204ee8af26bba6b6f15d79a02f8
parent4678ebd56997c5bba2a34a1c021c906cd769de45 (diff)
downloadandroid_external_fsck_msdos-53020727b8f86203bb8a1f6a65d8a70f17755bf4.tar.gz
android_external_fsck_msdos-53020727b8f86203bb8a1f6a65d8a70f17755bf4.tar.bz2
android_external_fsck_msdos-53020727b8f86203bb8a1f6a65d8a70f17755bf4.zip
fsck_msdos: set limitation to reduce the time in extreme case
In some particular SD card, Most of the clusters are discrete. It will take a long time to manage the runtime memory and cluster. Set a max limitation here to limit the whole time, otherwise it will take too much time and a bad user experience. Change-Id: I3212f52e19c9b2c888120ada9f9ce46d7ef37d58
-rw-r--r--fatcache.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/fatcache.c b/fatcache.c
index 5b9a73b..b63a13a 100644
--- a/fatcache.c
+++ b/fatcache.c
@@ -357,6 +357,20 @@ re_calc:
/*re-calc Numfree*/
boot->NumFree += (org_chain_len - fat->length);
}
+
+/*
+ * This is a trade-off between time and memory
+ * In order to reduce the runtime memory consumption
+ * We change the whole strategy of cluster chain checking
+ * and managment.
+ * In some extreme cases, most of the clusters in FAT file
+ * system are discrete. that means it will take much time
+ * to manage memory and cluster chain at runtime.
+ * So set a limitation of max memory malloc here.
+ */
+int limit = 0;
+#define FSCK_MSDOS_MAX_CALLOC_TIMES 0x15000
+
struct cluster_chain_descriptor* New_fatentry(void)
{
struct cluster_chain_descriptor *fat;
@@ -366,6 +380,9 @@ struct cluster_chain_descriptor* New_fatentry(void)
return fat;
}
RB_SET(fat, NULL, rb);
+ if (++limit >= FSCK_MSDOS_MAX_CALLOC_TIMES)
+ exit(0);
+
return fat;
}
@@ -375,6 +392,9 @@ struct fatcache* New_fatcache(void)
cache = calloc(1,sizeof(struct fatcache));
if(!cache)
fsck_warn("No space \n");
+ if (++limit >= FSCK_MSDOS_MAX_CALLOC_TIMES)
+ exit(0);
+
return cache;
}