From bea6a16a692d4912b404a085fe4adff73c55e631 Mon Sep 17 00:00:00 2001
From: batt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Date: Tue, 16 Sep 2008 12:48:18 +0000
Subject: [PATCH] Remove dead code.

git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1810 38d2e660-2303-0410-9eaa-f027e97ec537
---
 bertos/fs/battfs.c | 217 ---------------------------------------------
 1 file changed, 217 deletions(-)

diff --git a/bertos/fs/battfs.c b/bertos/fs/battfs.c
index 73e3536a..42331906 100644
--- a/bertos/fs/battfs.c
+++ b/bertos/fs/battfs.c
@@ -343,223 +343,6 @@ static bool fillPageArray(struct BattFsSuper *disk, pgoff_t *filelen_table)
 	return true;
 }
 
-#if 0
-/**
- * Find the latest version of a page, starting from the
- * page supplied by \a page_array.
- * The pages are read from the disk until a different
- * inode or page offset is found.
- * The lastest version of the page is moved in the first
- * position of \a page_array.
- * \return the number of old versions of the page or PAGE_ERROR
- *         on disk read errors.
- */
-static pgcnt_t findLastVersion(struct BattFsSuper *disk, pgcnt_t *page_array)
-{
-	pgcnt_t *array_start = page_array;
-	BattFsPageHeader hdr;
-	if (!battfs_readHeader(disk, *page_array++, &hdr))
-		return PAGE_ERROR;
-
-	/* Free space: early bailout */
-	if (hdr.fcs != computeFcs(&hdr))
-		return 0;
-
-	/*
-	 * If the first page is valid,
-	 * inode and pg_off in the array are taken
-	 * as the current page markers.
-	 */
-	inode_t curr_inode = hdr.inode;
-	pgoff_t curr_pgoff = hdr.pgoff;
-
-	/* Temps used to find the sequence number range */
-	seq_t minl = HALF_SEQ - 1;
-	seq_t maxl = 0;
-	seq_t minh = MAX_SEQ;
-	seq_t maxh = MAX_SEQ;
-	pgcnt_t lpos = 0, hpos = 0, dup_cnt = 0;
-
-	/*
-	 * Find min and max values for the two
-	 * half of seq_num range.
-	 * With this we can find seqnum wraparounds.
-	 * seq_t is a type that has at least 1 bit more than
-	 * pgaddr_t. So all version of a page blocks can be numbered using
-	 * at most half numbers of a seq_t type.
-	 * The sequence number algorithm increments by 1 the previous seq_num
-	 * every time a page is rewritten. So the sequence is
-	 * guaranteed to be countiguous.
-	 * Only wrap arounds may happen, but due to half size sequence limitation,
-	 * there are only 4 possible situations:
-	 *
-	 * \verbatim
-	 *    |------lower half------|-------upper half-------|
-	 *
-	 * 1) |------minl*****maxl---|------------------------|
-	 * 2) |------minl********maxl|minh******maxh----------|
-	 * 3) |----------------------|----minh*******maxh-----|
-	 * 4) |minl******maxl--------|------------minh****maxh|
-	 * \endverbatim
-	 *
-	 * Situations 1 and 3 are easy to detect, while 2 and 4 require more care.
-	 */
-	do
-	{
-		if (hdr.seq < HALF_SEQ)
-		{
-			minl = MIN(minl, hdr.seq);
-			if (hdr.seq > maxl)
-			{
-				maxl = hdr.seq;
-				lpos = dup_cnt;
-			}
-		}
-		else
-		{
-			minh = MIN(minh, hdr.seq);
-			if (hdr.seq > maxh)
-			{
-				maxh = hdr.seq;
-				hpos = dup_cnt;
-			}
-		}
-
-		if (!battfs_readHeader(disk, *page_array++, &hdr))
-			return PAGE_ERROR;
-		dup_cnt++;
-	}
-	while (curr_inode == hdr.inode && curr_pgoff == hdr.pgoff && hdr.fcs == computeFcs(&hdr));
-
-
-	/* Return early if there is only one version of the current page */
-	if (dup_cnt == 1)
-		return 0;
-
-	/* Find the position in the array of the last version of the page */
-	pgcnt_t last_ver = hpos;
-	if (maxl >= minl)
-	{
-		/* Valid interval found in lower half */
-		if (maxh >= minh)
-		{
-			/* Valid interval also found in upper half */
-			if (maxl != minh - 1)
-			{
-				/* Interval starts in upper half and ends in lower */
-				ASSERT(minl == 0);
-				ASSERT(maxh == MAX_SEQ);
-
-				last_ver = lpos;
-			}
-		}
-		else
-			/*
-			 * Upper interval is invalid.
-			 * Use lower values.
-			 */
-			last_ver = lpos;
-	}
-
-	/* Put last page version at array start position */
-	SWAP(array_start[0], array_start[last_ver]);
-
-	return dup_cnt - 1;
-}
-
-/**
- * Collect old pages, removing empty spaces from \a pg_array, for a maximum len of \a pg_len.
- * Once the collect task is completed, copy \a old_cnt pages from \a old_pages at the
- * end of free space in pg_array.
- */
-void collectOldPages(pgcnt_t *pg_array, pgcnt_t pg_len, pgcnt_t *old_pages, pgcnt_t old_cnt)
-{
-	bool copy = false;
-	pgcnt_t gap = 0;
-
-	for (pgcnt_t curr_page = 0; curr_page < pg_len; curr_page++)
-	{
-		if (!copy)
-		{
-			if (pg_array[curr_page] == PAGE_UNSET_SENTINEL)
-				gap++;
-			else
-			{
-				pg_array[curr_page - gap] = pg_array[curr_page];
-				copy = true;
-			}
-		}
-		else
-		{
-			if (pg_array[curr_page] != PAGE_UNSET_SENTINEL)
-				pg_array[curr_page - gap] = pg_array[curr_page];
-			else
-			{
-				gap++;
-				copy = false;
-			}
-		}
-	}
-	ASSERT(gap == old_cnt);
-	pg_array += pg_len - old_cnt;
-
-	memcpy(pg_array, old_pages, old_cnt * sizeof(pgcnt_t));
-}
-
-/**
- * This function scan the page array of \a disk looking for
- * old versions of the same page.
- *
- * Only the last version is kept as valid, the old ones are inserted
- * in the free blocks heap.
- * \return true if ok, false on disk read errors.
- * \note The whole disk is scanned once.
- */
-static bool dropOldPages(struct BattFsSuper *disk)
-{
-	#define OLD_PAGE_BUFLEN 64
-	pgcnt_t old_pages[OLD_PAGE_BUFLEN];
-	pgcnt_t old_cnt = 0;
-
-	pgcnt_t *curr_page = disk->page_array;
-	pgcnt_t *collect_start = disk->page_array;
-	pgcnt_t collect_len = disk->page_count;
-	pgcnt_t dup_pages;
-
-	do
-	{
-		dup_pages = findLastVersion(disk, curr_page);
-		if (dup_pages == PAGE_ERROR)
-			return false;
-		/* The first page is the last version */
-		curr_page++;
-		while (dup_pages--)
-		{
-			if (old_cnt >= OLD_PAGE_BUFLEN)
-			{
-				collectOldPages(collect_start, collect_len, old_pages, old_cnt);
-				collect_len -= old_cnt;
-				disk->free_bytes += old_cnt * (disk->page_size - BATTFS_HEADER_LEN);
-				disk->free_page_start -= old_cnt;
-				curr_page -= old_cnt;
-				collect_start = curr_page;
-				old_cnt = 0;
-			}
-
-			old_pages[old_cnt++] = *curr_page;
-			*curr_page++ = PAGE_UNSET_SENTINEL;
-		}
-	}
-	while (curr_page < disk->page_array + disk->free_page_start);
-
-	collectOldPages(collect_start, collect_len, old_pages, old_cnt);
-	disk->free_bytes += old_cnt * (disk->page_size - BATTFS_HEADER_LEN);
-	disk->free_page_start -= old_cnt;
-
-	return true;
-}
-#endif
-
 /**
  * Initialize and mount disk described by
  * \a disk.
-- 
2.34.1