From 9563ce4c778bc517a8439000df985271f6967e21 Mon Sep 17 00:00:00 2001 From: batt Date: Mon, 15 Sep 2008 20:16:13 +0000 Subject: [PATCH] Update to new names and API. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1806 38d2e660-2303-0410-9eaa-f027e97ec537 --- bertos/fs/battfs.c | 39 ++++++-------- bertos/fs/battfs.h | 7 ++- bertos/fs/battfs_test.c | 110 ++++++++++++++++++++-------------------- 3 files changed, 73 insertions(+), 83 deletions(-) diff --git a/bertos/fs/battfs.c b/bertos/fs/battfs.c index eb2523ea..db15a3c8 100644 --- a/bertos/fs/battfs.c +++ b/bertos/fs/battfs.c @@ -44,6 +44,7 @@ #include /* MIN, MAX */ #include /* cpu_to_xx */ +#include #include /* memset, memmove */ @@ -425,7 +426,7 @@ static bool fillPageArray(struct BattFsSuper *disk, pgoff_t *filelen_table) * \return the number of old versions of the page or PAGE_ERROR * on disk read errors. */ -static pgcnt_t findLastVersion(pgcnt_t *page_array) +static pgcnt_t findLastVersion(struct BattFsSuper *disk, pgcnt_t *page_array) { pgcnt_t *array_start = page_array; BattFsPageHeader hdr; @@ -447,8 +448,8 @@ static pgcnt_t findLastVersion(pgcnt_t *page_array) /* Temps used to find the sequence number range */ seq_t minl = HALF_SEQ - 1; seq_t maxl = 0; - seq_t minh = FULL_SEQ; - seq_t maxh = HALF_SEQ; + seq_t minh = MAX_SEQ; + seq_t maxh = MAX_SEQ; pgcnt_t lpos = 0, hpos = 0, dup_cnt = 0; /* @@ -477,7 +478,7 @@ static pgcnt_t findLastVersion(pgcnt_t *page_array) */ do { - if (hdr.seq < SEQ_HALF_SIZE) + if (hdr.seq < HALF_SEQ) { minl = MIN(minl, hdr.seq); if (hdr.seq > maxl) @@ -500,7 +501,7 @@ static pgcnt_t findLastVersion(pgcnt_t *page_array) return PAGE_ERROR; dup_cnt++; } - while (curr_inode == hdr.inode && curr_pgoff == hdr.pgoff && hdr.fcs == computeFcs(&hdr)) + 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 */ @@ -519,7 +520,7 @@ static pgcnt_t findLastVersion(pgcnt_t *page_array) { /* Interval starts in upper half and ends in lower */ ASSERT(minl == 0); - ASSERT(maxh == FULL_SEQ); + ASSERT(maxh == MAX_SEQ); last_ver = lpos; } @@ -599,7 +600,7 @@ static bool dropOldPages(struct BattFsSuper *disk) do { - dup_pages = findLastVersion(curr_page); + dup_pages = findLastVersion(disk, curr_page); if (dup_pages == PAGE_ERROR) return false; /* The first page is the last version */ @@ -713,7 +714,7 @@ static int battfs_flush(struct KFile *fd) */ static int battfs_fileclose(struct KFile *fd) { - BattFS *fdb = BATTFSKFILE(fd); + BattFs *fdb = BATTFS_CAST(fd); battfs_flush(fd); REMOVE(&fdb->link); @@ -726,7 +727,7 @@ static int battfs_fileclose(struct KFile *fd) */ static size_t battfs_read(struct KFile *fd, void *_buf, size_t size) { - BattFS *fdb = BATTFSKFILE(fd); + BattFs *fdb = BATTFS_CAST(fd); uint8_t *buf = (uint8_t *)_buf; size_t total_read = 0; @@ -821,7 +822,7 @@ static bool countFileSize(BattFsSuper *disk, pgcnt_t *start, inode_t inode, file * File context is stored in \a fd. * \return true if ok, false otherwise. */ -bool battfs_fileopen(BattFsSuper *disk, BattFS *fd, inode_t inode, filemode_t mode) +bool battfs_fileopen(BattFsSuper *disk, BattFs *fd, inode_t inode, filemode_t mode) { Node *n; @@ -840,8 +841,6 @@ bool battfs_fileopen(BattFsSuper *disk, BattFS *fd, inode_t inode, filemode_t mo hdr.seq = 0; hdr.fill = 0; hdr.pgoff = 0; - hdr.mark = MARK_PAGE_VALID; - hdr.fcs_free = FCS_FREE_VALID; hdr.fcs = computeFcs(&hdr); #warning TODO: get a free block and write on disk! } @@ -856,7 +855,7 @@ bool battfs_fileopen(BattFsSuper *disk, BattFS *fd, inode_t inode, filemode_t mo /* Insert file handle in list, ordered by inode, ascending. */ FOREACH_NODE(n, &disk->file_opened_list) { - BattFS *file = containerof(n, BattFS, link); + BattFs *file = containerof(n, BattFs, link); if (file->inode >= inode) break; } @@ -896,7 +895,7 @@ bool battfs_close(struct BattFsSuper *disk) /* Close all open files */ FOREACH_NODE(n, &disk->file_opened_list) { - BattFS *file = containerof(n, BattFS, link); + BattFs *file = containerof(n, BattFs, link); res += battfs_fileclose(&file->fd); } @@ -904,23 +903,15 @@ bool battfs_close(struct BattFsSuper *disk) return disk->close(disk) && (res == 0); } - -bool battfs_writeTestBlock(struct BattFsSuper *disk, pgcnt_t page, inode_t inode, seq_t seq, fill_t fill, pgoff_t pgoff, mark_t mark) +bool battfs_writeTestBlock(struct BattFsSuper *disk, pgcnt_t page, inode_t inode, seq_t seq, fill_t fill, pgoff_t pgoff) { BattFsPageHeader hdr; hdr.inode = inode; - hdr.seq = seq; hdr.fill = fill; hdr.pgoff = pgoff; - hdr.mark = MARK_PAGE_VALID; - hdr.fcs_free = FCS_FREE_VALID; + hdr.seq = seq; hdr.fcs = computeFcs(&hdr); - if (mark != MARK_PAGE_VALID) - { - hdr.mark = mark; - hdr.fcs_free = computeFcsFree(&hdr); - } if (!battfs_writeHeader(disk, page, &hdr)) { diff --git a/bertos/fs/battfs.h b/bertos/fs/battfs.h index 0422c43a..9c60b9d5 100644 --- a/bertos/fs/battfs.h +++ b/bertos/fs/battfs.h @@ -52,7 +52,7 @@ typedef fill_t pgaddr_t; ///< Type for addressing space inside a page typedef uint16_t pgcnt_t; ///< Type for counting pages on disk typedef pgcnt_t pgoff_t; ///< Type for counting pages inside a file typedef uint8_t inode_t; ///< Type for file inodes -typedef uint8_t seq_t; ///< Type for page seq number +typedef uint32_t seq_t; ///< Type for page seq number typedef rotating_t fcs_t; ///< Type for header FCS. /** @@ -197,7 +197,7 @@ typedef struct BattFsSuper } BattFsSuper; typedef uint8_t filemode_t; ///< Type for file open modes. -typedef uint32_t file_size_t; ///< Type for file sizes. +typedef int32_t file_size_t; ///< Type for file sizes. /** * Modes for battfs_fileopen. @@ -242,6 +242,5 @@ bool battfs_close(struct BattFsSuper *disk); bool battfs_fileExists(BattFsSuper *disk, inode_t inode); bool battfs_fileopen(BattFsSuper *disk, BattFs *fd, inode_t inode, filemode_t mode); - -bool battfs_writeTestBlock(struct BattFsSuper *disk, pgcnt_t page, inode_t inode, seq_t seq, fill_t fill, pgoff_t pgoff, seq_t seq); +bool battfs_writeTestBlock(struct BattFsSuper *disk, pgcnt_t page, inode_t inode, seq_t seq, fill_t fill, pgoff_t pgoff); #endif /* FS_BATTFS_H */ diff --git a/bertos/fs/battfs_test.c b/bertos/fs/battfs_test.c index 5b5c4631..7b5600d5 100644 --- a/bertos/fs/battfs_test.c +++ b/bertos/fs/battfs_test.c @@ -156,7 +156,7 @@ static void test2(BattFsSuper *disk) for (int i = 0; i < PAGE_COUNT; i++) { - battfs_writeTestBlock(disk, i, 0, 0, 0, i, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, i, 0, 0, 0, i); ref[i] = i; } fclose(fp); @@ -176,7 +176,7 @@ static void test3(BattFsSuper *disk) for (int i = 0; i < PAGE_COUNT / 2; i++) { - battfs_writeTestBlock(disk, i, 0, 0, 0, i, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, i, 0, 0, 0, i); ref[i] = i; } fseek(fp, FILE_SIZE / 2, SEEK_SET); @@ -204,12 +204,12 @@ static void test4(BattFsSuper *disk) for (int i = 0; i < PAGE_COUNT / 2; i++) { - battfs_writeTestBlock(disk, i, 0, 0, 0, i, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, i, 0, 0, 0, i); ref[i] = i; } for (int i = PAGE_COUNT / 2; i < PAGE_COUNT; i++) { - battfs_writeTestBlock(disk, i, 0, 0, 0, i, i); + battfs_writeTestBlock(disk, i, 0, 0, 0, i); ref[i] = i; } fclose(fp); @@ -232,12 +232,12 @@ static void test5(BattFsSuper *disk) for (int i = 0; i < PAGE_COUNT / 3; i++) { - battfs_writeTestBlock(disk, i, 0, 0, 0, i, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, i, 0, 0, 0, i); ref[i] = i; } for (int i = PAGE_COUNT / 3; i < 2 * (PAGE_COUNT / 3); i++) { - battfs_writeTestBlock(disk, i, 0, 0, 0, i, i); + battfs_writeTestBlock(disk, i, 0, 0, 0, i); ref[i + PAGE_COUNT / 3 + 1] = i; } fclose(fp); @@ -257,10 +257,10 @@ static void test6(BattFsSuper *disk) fp = fopen(test_filename, "w+"); - battfs_writeTestBlock(disk, 0, 0, 0, 0, 0, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 1, 0, 0, 0, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 2, 0, 1, 0, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 3, 0, 0, 0, 0, 123); + battfs_writeTestBlock(disk, 0, 0, 0, 0, 0); + battfs_writeTestBlock(disk, 1, 0, 0, 0, 1); + battfs_writeTestBlock(disk, 2, 0, 1, 0, 1); + battfs_writeTestBlock(disk, 3, 0, 0, 0, 0); fclose(fp); ref[0] = 0; @@ -280,10 +280,10 @@ static void test7(BattFsSuper *disk) fp = fopen(test_filename, "w+"); - battfs_writeTestBlock(disk, 0, 0, 0, 0, 0, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 1, 0, 1, 0, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 2, 0, 0, 0, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 3, 0, 0, 0, 0, 123); + battfs_writeTestBlock(disk, 0, 0, 0, 0, 0); + battfs_writeTestBlock(disk, 1, 0, 1, 0, 1); + battfs_writeTestBlock(disk, 2, 0, 0, 0, 1); + battfs_writeTestBlock(disk, 3, 0, 0, 0, 0); fclose(fp); ref[0] = 0; @@ -303,10 +303,10 @@ static void test8(BattFsSuper *disk) fp = fopen(test_filename, "w+"); - battfs_writeTestBlock(disk, 0, 0, 0, 0, 0, 1235); - battfs_writeTestBlock(disk, 1, 0, 0, 0, 0, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 2, 0, 1, 0, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 3, 0, 0, 0, 1, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, 0, 0, 0, 0, 0); + battfs_writeTestBlock(disk, 1, 0, 0, 0, 0); + battfs_writeTestBlock(disk, 2, 0, 1, 0, 1); + battfs_writeTestBlock(disk, 3, 0, 0, 0, 1); fclose(fp); @@ -327,14 +327,14 @@ static void test9(BattFsSuper *disk) fp = fopen(test_filename, "w+"); - battfs_writeTestBlock(disk, 0, 0, 0, 0, 0, 1235); - battfs_writeTestBlock(disk, 1, 0, 0, 0, 0, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 2, 0, 3, 0, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 3, 0, 0, 0, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 4, 0, 0, 0, 0, 1236); - battfs_writeTestBlock(disk, 5, 4, 0, 0, 0, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 6, 4, 1, 0, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 7, 4, 0, 0, 1, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, 0, 0, 0, 0, 0); + battfs_writeTestBlock(disk, 1, 0, 0, 0, 0); + battfs_writeTestBlock(disk, 2, 0, 3, 0, 1); + battfs_writeTestBlock(disk, 3, 0, 0, 0, 1); + battfs_writeTestBlock(disk, 4, 0, 0, 0, 0); + battfs_writeTestBlock(disk, 5, 4, 0, 0, 0); + battfs_writeTestBlock(disk, 6, 4, 1, 0, 1); + battfs_writeTestBlock(disk, 7, 4, 0, 0, 1); fclose(fp); @@ -353,26 +353,26 @@ static void test9(BattFsSuper *disk) static void test10(BattFsSuper *disk) { - BattFS fd1; - BattFS fd2; + BattFs fd1; + BattFs fd2; kprintf("Test10: open file test, inode 0 and inode 4\n"); fp = fopen(test_filename, "w+"); - unsigned int PAGE_FILL = 116; + int PAGE_FILL = 116; unsigned int INODE = 0; unsigned int INODE2 = 4; unsigned int INEXISTENT_INODE = 123; unsigned int MODE = 0; - battfs_writeTestBlock(disk, 0, 123, 0, PAGE_FILL, 0, 1235); - battfs_writeTestBlock(disk, 1, INODE, 0, PAGE_FILL, 0, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 2, INODE, 3, PAGE_FILL, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 3, INODE, 0, PAGE_FILL, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 4, INODE2, 0, PAGE_FILL, 0, 1236); - battfs_writeTestBlock(disk, 5, INODE2, 0, PAGE_FILL, 0, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 6, INODE2, 1, PAGE_FILL, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 7, INODE2, 0, PAGE_FILL, 1, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, 0, 123, 0, PAGE_FILL, 0); + battfs_writeTestBlock(disk, 1, INODE, 0, PAGE_FILL, 0); + battfs_writeTestBlock(disk, 2, INODE, 3, PAGE_FILL, 1); + battfs_writeTestBlock(disk, 3, INODE, 0, PAGE_FILL, 1); + battfs_writeTestBlock(disk, 4, INODE2, 0, PAGE_FILL, 0); + battfs_writeTestBlock(disk, 5, INODE2, 0, PAGE_FILL, 0); + battfs_writeTestBlock(disk, 6, INODE2, 1, PAGE_FILL, 1); + battfs_writeTestBlock(disk, 7, INODE2, 0, PAGE_FILL, 1); fclose(fp); @@ -418,7 +418,7 @@ static void test10(BattFsSuper *disk) static void test11(BattFsSuper *disk) { - BattFS fd1; + BattFs fd1; uint8_t buf[16]; kprintf("Test11: read file test\n"); @@ -430,14 +430,14 @@ static void test11(BattFsSuper *disk) unsigned int INODE2 = 4; unsigned int MODE = 0; - battfs_writeTestBlock(disk, 0, 123, 0, PAGE_FILL, 0, 1235); - battfs_writeTestBlock(disk, 1, INODE, 0, PAGE_FILL, 0, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 2, INODE, 3, PAGE_FILL, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 3, INODE, 0, PAGE_FILL, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 4, INODE2, 0, PAGE_FILL, 0, 1236); - battfs_writeTestBlock(disk, 5, INODE2, 0, PAGE_FILL, 0, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 6, INODE2, 1, PAGE_FILL, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 7, INODE2, 0, PAGE_FILL, 1, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, 0, 123, 0, PAGE_FILL, 0); + battfs_writeTestBlock(disk, 1, INODE, 0, PAGE_FILL, 0); + battfs_writeTestBlock(disk, 2, INODE, 3, PAGE_FILL, 1); + battfs_writeTestBlock(disk, 3, INODE, 0, PAGE_FILL, 1); + battfs_writeTestBlock(disk, 4, INODE2, 0, PAGE_FILL, 0); + battfs_writeTestBlock(disk, 5, INODE2, 0, PAGE_FILL, 0); + battfs_writeTestBlock(disk, 6, INODE2, 1, PAGE_FILL, 1); + battfs_writeTestBlock(disk, 7, INODE2, 0, PAGE_FILL, 1); fclose(fp); @@ -456,7 +456,7 @@ static void test11(BattFsSuper *disk) static void test12(BattFsSuper *disk) { - BattFS fd1; + BattFs fd1; kprintf("Test12: read file test across page boundary and seek test\n"); @@ -467,14 +467,14 @@ static void test12(BattFsSuper *disk) unsigned int MODE = 0; uint8_t buf[PAGE_FILL + 10]; - battfs_writeTestBlock(disk, 0, 123, 0, PAGE_FILL, 0, 1235); - battfs_writeTestBlock(disk, 1, INODE, 0, PAGE_FILL, 0, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 2, INODE, 3, PAGE_FILL, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 3, INODE, 0, PAGE_FILL, 1, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 4, INODE, 0, PAGE_FILL, 0, 1236); - battfs_writeTestBlock(disk, 5, INODE, 0, PAGE_FILL, 2, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 6, INODE, 1, PAGE_FILL, 3, MARK_PAGE_VALID); - battfs_writeTestBlock(disk, 7, INODE, 0, PAGE_FILL, 3, MARK_PAGE_VALID); + battfs_writeTestBlock(disk, 0, 123, 0, PAGE_FILL, 0); + battfs_writeTestBlock(disk, 1, INODE, 0, PAGE_FILL, 0); + battfs_writeTestBlock(disk, 2, INODE, 3, PAGE_FILL, 1); + battfs_writeTestBlock(disk, 3, INODE, 0, PAGE_FILL, 1); + battfs_writeTestBlock(disk, 4, INODE, 0, PAGE_FILL, 0); + battfs_writeTestBlock(disk, 5, INODE, 0, PAGE_FILL, 2); + battfs_writeTestBlock(disk, 6, INODE, 1, PAGE_FILL, 3); + battfs_writeTestBlock(disk, 7, INODE, 0, PAGE_FILL, 3); fclose(fp); -- 2.25.1