From 53020727b8f86203bb8a1f6a65d8a70f17755bf4 Mon Sep 17 00:00:00 2001 From: Xiaogang Cui Date: Wed, 9 Apr 2014 19:30:53 +0800 Subject: 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 --- fatcache.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) 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; } -- cgit v1.2.3