From 6c20782f7b6088ff241e4f486a3afe73de46b32a Mon Sep 17 00:00:00 2001 From: batt Date: Wed, 28 Nov 2007 22:15:46 +0000 Subject: [PATCH] Refactor page header: add marker for free blocks. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1010 38d2e660-2303-0410-9eaa-f027e97ec537 --- fs/battfs.h | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/fs/battfs.h b/fs/battfs.h index d2e3b6fc..3d491cd9 100644 --- a/fs/battfs.h +++ b/fs/battfs.h @@ -42,13 +42,19 @@ #define FS_BATTFS_H #include // uintXX_t; STATIC_ASSERT -#include +#include -typedef uint16_t filled_t; +typedef uint16_t fill_t; typedef uint16_t pgoff_t; +typedef pgoff_t mark_t; typedef uint8_t inode_t; -typedef uint8_t seqnum_t; -typedef rotating_t fsc_t; +typedef uint8_t seq_t; +typedef uint8_t fsc_t; + +/** + * Reserve 2 bits from fill field to allocate seq number. + */ +#define FILLSIZE ((sizeof(filled_t) * CPU_BITS_PER_CHAR) - 2) /** * BattFS page header. @@ -57,39 +63,24 @@ typedef rotating_t fsc_t; */ typedef struct BattFsPageHeader { - inode_t inode; ///< File inode (file identifier). - seqnum_t seqnum; ///< bit[1:0]: Page sequence number; bit[7:2] unused for now, must be set to 1. - filled_t filled; ///< Filled bytes in page. - pgoff_t pgoff; ///< Page offset inside file. - fsc_t fsc; ///< CRC of the page header. + mark_t mark; ///< Marker used to keep trace of free/used pages. + pgoff_t pgoff; ///< Page offset inside file. + fill_t fill:FILLSIZE; ///< Filled bytes in page. + seq_t seq:2; ///< bit[1:0]: Page sequence number; bit[7:2] unused for now, must be set to 1. + inode_t inode; ///< File inode (file identifier). + fsc_t fsc; ///< FSC of the page header. } BattFsPageHeader; /* Ensure structure has no padding added */ -STATIC_ASSERT(sizeof(BattFsPageHeader) == sizeof(filled_t) + sizeof(pgoff_t) - + sizeof(inode_t) + sizeof(seqnum_t) + sizeof(fsc_t)); - -/** - * Reset page sequence number of struct \a m to default value (0xFF). - */ -#define RESET_SEQ(m) ((m).seqnum = 0xFF) - -/** - * Get page sequence number from struct \a m. - */ -#define SEQ(m) ((m).seqnum & 0x03) +STATIC_ASSERT(sizeof(BattFsPageHeader) == 8); -/** - * Set sequence number of struct \a m to \a d. - */ -#define SET_SEQ(m, d) ((m).seqnum = ((m).seqnum & 0xFC) | ((d) & 0x03)) +/* Fwd decl */ +struct BattFsSuper; /** - * Increment sequence number of struct \a m. + * Type for disk page addressing. */ -#define INC_SEQ(m) SET_SEQ((m), SEQ(m) + 1) - -/* Fwd decl */ -struct BattFsSuper; +typedef uint32_t battfs_page_t; /** * Type interface for disk init function. -- 2.25.1