From 41d459b15c8a8675c2c8f81ec4ebb691a886ffd9 Mon Sep 17 00:00:00 2001 From: antona Date: Thu, 4 Aug 2005 08:09:58 +0000 Subject: [PATCH] Improve on decompression fix from Yura. --- libntfs/compress.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/libntfs/compress.c b/libntfs/compress.c index f0cb164c..17d0981c 100644 --- a/libntfs/compress.c +++ b/libntfs/compress.c @@ -254,29 +254,27 @@ static __inline__ BOOL ntfs_is_cb_compressed(ntfs_attr *na, runlist_element *rl, VCN cb_start_vcn, int cb_clusters) { /* - * The simplest case: the run starting at @cb_start_vcn contains + * The simplest case: the run starting at @cb_start_vcn contains * @cb_clusters clusters which are all not sparse, thus the cb is not * compressed. */ - if (rl->length - (cb_start_vcn - rl->vcn) >= cb_clusters) - return FALSE; +restart: cb_clusters -= rl->length - (cb_start_vcn - rl->vcn); - do { + while (cb_clusters > 0) { /* Go to the next run. */ rl++; /* Map the next runlist fragment if it is not mapped. */ if (rl->lcn < LCN_HOLE || !rl->length) { - VCN tvcn; - - tvcn = rl->vcn; - rl = ntfs_attr_find_vcn(na, tvcn); + cb_start_vcn = rl->vcn; + rl = ntfs_attr_find_vcn(na, rl->vcn); if (!rl || rl->lcn < LCN_HOLE || !rl->length) return TRUE; - if (rl->vcn < tvcn) { - /* Runs merged. Need special handling. */ - cb_clusters -= rl->length - (tvcn - rl->vcn); - continue; - } + /* + * If the runs were merged need to deal with the + * resulting partial run so simply restart. + */ + if (rl->vcn < cb_start_vcn) + goto restart; } /* If the current run is sparse, the cb is compressed. */ if (rl->lcn == LCN_HOLE) @@ -285,7 +283,7 @@ static __inline__ BOOL ntfs_is_cb_compressed(ntfs_attr *na, if (rl->length >= cb_clusters) return FALSE; cb_clusters -= rl->length; - } while (cb_clusters > 0); + }; /* All cb_clusters were not sparse thus the cb is not compressed. */ return FALSE; }