From: batt Date: Thu, 1 Jul 2010 17:08:27 +0000 (+0000) Subject: Remove redundant information from BattFS disk descriptor. X-Git-Tag: 2.6.0~327 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=e266533b019dd9750e8b7343a371b360dd7cd60b;p=bertos.git Remove redundant information from BattFS disk descriptor. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@3980 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/fs/battfs.c b/bertos/fs/battfs.c index dbed5781..9eeedb45 100644 --- a/bertos/fs/battfs.c +++ b/bertos/fs/battfs.c @@ -55,7 +55,7 @@ static void dumpPageArray(struct BattFsSuper *disk) { kprintf("Page array dump, free_page_start %d:", disk->free_page_start); - for (pgcnt_t i = 0; i < disk->page_count; i++) + for (pgcnt_t i = 0; i < disk->dev->blk_cnt; i++) { if (!(i % 16)) kputchar('\n'); @@ -199,13 +199,13 @@ static pgcnt_t countPages(pgoff_t *filelen_table, inode_t inode) static void movePages(struct BattFsSuper *disk, pgcnt_t src, int offset) { pgcnt_t dst = src + offset; - LOG_INFO("src %d, offset %d, size %d\n", src, offset, (unsigned int)((disk->page_count - MAX(dst, src)) * sizeof(pgcnt_t))); - memmove(&disk->page_array[dst], &disk->page_array[src], (disk->page_count - MAX(dst, src)) * sizeof(pgcnt_t)); + LOG_INFO("src %d, offset %d, size %d\n", src, offset, (unsigned int)((disk->dev->blk_cnt - MAX(dst, src)) * sizeof(pgcnt_t))); + memmove(&disk->page_array[dst], &disk->page_array[src], (disk->dev->blk_cnt - MAX(dst, src)) * sizeof(pgcnt_t)); if (offset < 0) { /* Fill empty space in array with sentinel */ - for (pgcnt_t page = disk->page_count + offset; page < disk->page_count; page++) + for (pgcnt_t page = disk->dev->blk_cnt + offset; page < disk->dev->blk_cnt; page++) disk->page_array[page] = PAGE_UNSET_SENTINEL; } } @@ -225,7 +225,7 @@ static bool countDiskFilePages(struct BattFsSuper *disk, pgoff_t *filelen_table) disk->free_page_start = 0; /* Count the number of disk page per file */ - for (pgcnt_t page = 0; page < disk->page_count; page++) + for (pgcnt_t page = 0; page < disk->dev->blk_cnt; page++) { if (!readHdr(disk, page, &hdr)) return false; @@ -270,7 +270,7 @@ static bool fillPageArray(struct BattFsSuper *disk, pgoff_t *filelen_table) BattFsPageHeader hdr; pgcnt_t curr_free_page = disk->free_page_start; /* Fill page allocation array */ - for (pgcnt_t page = 0; page < disk->page_count; page++) + for (pgcnt_t page = 0; page < disk->dev->blk_cnt; page++) { if (!readHdr(disk, page, &hdr)) return false; @@ -368,22 +368,20 @@ bool battfs_mount(struct BattFsSuper *disk, struct KBlock *dev, pgcnt_t *page_ar ASSERT(dev); disk->dev = dev; - disk->page_size = dev->blk_size; - disk->page_count = dev->blk_cnt; - ASSERT(disk->page_size > BATTFS_HEADER_LEN); + ASSERT(disk->dev->blk_size > BATTFS_HEADER_LEN); /* Fill page_size with the usable space */ - disk->data_size = disk->page_size - BATTFS_HEADER_LEN; - ASSERT(disk->page_count); - ASSERT(disk->page_count < PAGE_UNSET_SENTINEL - 1); + disk->data_size = disk->dev->blk_size - BATTFS_HEADER_LEN; + ASSERT(disk->dev->blk_cnt); + ASSERT(disk->dev->blk_cnt < PAGE_UNSET_SENTINEL - 1); ASSERT(page_array); disk->page_array = page_array; - ASSERT(array_size >= disk->page_count * sizeof(pgcnt_t)); + ASSERT(array_size >= disk->dev->blk_cnt * sizeof(pgcnt_t)); memset(filelen_table, 0, BATTFS_MAX_FILES * sizeof(pgoff_t)); disk->free_bytes = 0; - disk->disk_size = (disk_size_t)disk->data_size * disk->page_count; + disk->disk_size = (disk_size_t)disk->data_size * disk->dev->blk_cnt; /* Count pages per file */ if (!countDiskFilePages(disk, filelen_table)) @@ -395,7 +393,7 @@ bool battfs_mount(struct BattFsSuper *disk, struct KBlock *dev, pgcnt_t *page_ar /* Once here, we have filelen_table filled with file lengths */ /* Fill page array with sentinel */ - for (pgcnt_t page = 0; page < disk->page_count; page++) + for (pgcnt_t page = 0; page < disk->dev->blk_cnt; page++) disk->page_array[page] = PAGE_UNSET_SENTINEL; /* Fill page allocation array using filelen_table */ @@ -408,7 +406,7 @@ bool battfs_mount(struct BattFsSuper *disk, struct KBlock *dev, pgcnt_t *page_ar dumpPageArray(disk); #endif #if CONFIG_BATTFS_SHUFFLE_FREE_PAGES - SHUFFLE(&disk->page_array[disk->free_page_start], disk->page_count - disk->free_page_start); + SHUFFLE(&disk->page_array[disk->free_page_start], disk->dev->blk_cnt - disk->free_page_start); LOG_INFO("Page array after shuffle:\n"); #if LOG_LEVEL >= LOG_LVL_INFO @@ -428,8 +426,8 @@ bool battfs_fsck(struct BattFsSuper *disk) { #define FSCHECK(cond) do { if(!(cond)) { LOG_ERR("\"" #cond "\"\n"); return false; } } while (0) - FSCHECK(disk->free_page_start <= disk->page_count); - FSCHECK(disk->data_size < disk->page_size); + FSCHECK(disk->free_page_start <= disk->dev->blk_cnt); + FSCHECK(disk->data_size < disk->dev->blk_size); FSCHECK(disk->free_bytes <= disk->disk_size); disk_size_t free_bytes = 0; @@ -442,7 +440,7 @@ bool battfs_fsck(struct BattFsSuper *disk) /* Uneeded, the first time will be overwritten but useful to silence * the warning for uninitialized value */ FSCHECK(readHdr(disk, 0, &prev_hdr)); - for (pgcnt_t page = 0; page < disk->page_count; page++) + for (pgcnt_t page = 0; page < disk->dev->blk_cnt; page++) { FSCHECK(readHdr(disk, disk->page_array[page], &hdr)); free_bytes += disk->data_size; @@ -556,7 +554,7 @@ static pgcnt_t renewPage(struct BattFsSuper *disk, pgcnt_t old_pos) /* Insert previous page in free blocks list */ LOG_INFO("Setting page %d as free\n", old_pos); - disk->page_array[disk->page_count - 1] = old_pos; + disk->page_array[disk->dev->blk_cnt - 1] = old_pos; return new_page; } diff --git a/bertos/fs/battfs.h b/bertos/fs/battfs.h index 93598fe8..921c59da 100644 --- a/bertos/fs/battfs.h +++ b/bertos/fs/battfs.h @@ -107,9 +107,6 @@ typedef struct BattFsPageHeader */ #define BATTFS_MAX_FILES (1 << (CPU_BITS_PER_CHAR * sizeof(inode_t))) -/* Fwd decl */ -struct BattFsSuper; - /** * Sentinel used to keep trace of unset pages in disk->page_array. */ @@ -126,9 +123,6 @@ typedef struct BattFsSuper { KBlock *dev; ///< Block device context (physical disk). - pgaddr_t page_size; ///< Size of a memory page, in bytes. Used by disk low level driver. - pgcnt_t page_count; ///< Number of pages on disk. - pgaddr_t data_size; ///< Size of space usable for data in a disk page, in bytes. The rest is used by the page header. /** * Page allocation array. @@ -155,7 +149,7 @@ typedef struct BattFsSuper /** * True if space on \a disk is over. */ -#define SPACE_OVER(disk) ((disk)->free_page_start >= (disk)->page_count) +#define SPACE_OVER(disk) ((disk)->free_page_start >= (disk)->dev->blk_cnt) typedef uint8_t filemode_t; ///< Type for file open modes. typedef int32_t file_size_t; ///< Type for file sizes. diff --git a/bertos/fs/battfs_test.c b/bertos/fs/battfs_test.c index 33b1f69f..b12d3f8a 100644 --- a/bertos/fs/battfs_test.c +++ b/bertos/fs/battfs_test.c @@ -62,12 +62,12 @@ static void testCheck(BattFsSuper *disk, pgcnt_t *reference) { ASSERT(battfs_fsck(disk)); - for (int i = 0; i < disk->page_count; i++) + for (unsigned i = 0; i < disk->dev->blk_cnt; i++) { if (disk->page_array[i] != reference[i]) { kprintf("Error at addr %d: page_array read", i); - for (pgcnt_t i = 0; i < disk->page_count; i++) + for (pgcnt_t i = 0; i < disk->dev->blk_cnt; i++) { if (!(i % 16)) kputchar('\n'); @@ -75,7 +75,7 @@ static void testCheck(BattFsSuper *disk, pgcnt_t *reference) } kputchar('\n'); kprintf("Expected:"); - for (pgcnt_t i = 0; i < disk->page_count; i++) + for (pgcnt_t i = 0; i < disk->dev->blk_cnt; i++) { if (!(i % 16)) kputchar('\n');