From 4c1f7cd0bcf77994d03cacf2f3cbb5d529cc1ff8 Mon Sep 17 00:00:00 2001 From: batt Date: Tue, 5 Feb 2008 13:37:23 +0000 Subject: [PATCH] Pack seqnum with mark MSB to save 1 byte. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1092 38d2e660-2303-0410-9eaa-f027e97ec537 --- fs/battfs.c | 50 +++++++++++++++++++++++++++----------------------- fs/battfs.h | 2 +- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/fs/battfs.c b/fs/battfs.c index 630127f5..8289e91d 100644 --- a/fs/battfs.c +++ b/fs/battfs.c @@ -53,38 +53,42 @@ */ INLINE void battfs_to_disk(struct BattFsPageHeader *hdr, uint8_t *buf) { - STATIC_ASSERT(BATTFS_HEADER_LEN == 13); + STATIC_ASSERT(BATTFS_HEADER_LEN == 12); buf[0] = hdr->inode; - buf[1] = hdr->seq; + buf[1] = hdr->fill; + buf[2] = hdr->fill >> 8; - buf[2] = hdr->fill; - buf[3] = hdr->fill >> 8; - - buf[4] = hdr->pgoff; - buf[5] = hdr->pgoff >> 8; + buf[3] = hdr->pgoff; + buf[4] = hdr->pgoff >> 8; /* * Mark is at least 1 bit longer than page address. * Needed to take care of wraparonds. */ - buf[6] = hdr->mark; - buf[7] = hdr->mark >> 8; - buf[8] = hdr->mark >> 16; + buf[5] = hdr->mark; + buf[6] = hdr->mark >> 8; + + /* + * First bit used by mark, last 2 bits used by seq. + * Since only 2 pages with the same inode and pgoff + * can exist at the same time, 2 bit for seq are enough. + */ + buf[7] = ((hdr->mark >> 16) & 0x01) | (hdr->seq << 6); /* * This field must be the before the last one! */ - buf[9] = hdr->fcs_free; - buf[10] = hdr->fcs_free >> 8; + buf[8] = hdr->fcs_free; + buf[9] = hdr->fcs_free >> 8; /* * This field must be the last one! * This is needed because if the page is only partially * written, we can use this to detect it. */ - buf[11] = hdr->fcs; - buf[12] = hdr->fcs >> 8; + buf[10] = hdr->fcs; + buf[11] = hdr->fcs >> 8; } /** @@ -93,14 +97,14 @@ INLINE void battfs_to_disk(struct BattFsPageHeader *hdr, uint8_t *buf) */ INLINE void disk_to_battfs(uint8_t *buf, struct BattFsPageHeader *hdr) { - STATIC_ASSERT(BATTFS_HEADER_LEN == 13); + STATIC_ASSERT(BATTFS_HEADER_LEN == 12); hdr->inode = buf[0]; - hdr->seq = buf[1]; - hdr->fill = buf[3] << 8 | buf[2]; - hdr->pgoff = buf[5] << 8 | buf[4]; - hdr->mark = (mark_t)buf[8] << 16 | buf[7] << 8 | buf[6]; - hdr->fcs_free = buf[10] << 8 | buf[9]; - hdr->fcs = buf[12] << 8 | buf[11]; + hdr->fill = buf[2] << 8 | buf[1]; + hdr->pgoff = buf[4] << 8 | buf[3]; + hdr->mark = (mark_t)(buf[7] & 0x01) << 16 | buf[6] << 8 | buf[5]; + hdr->seq = buf[7] >> 6; + hdr->fcs_free = buf[9] << 8 | buf[8]; + hdr->fcs = buf[11] << 8 | buf[10]; } /** @@ -316,7 +320,7 @@ bool battfs_init(struct BattFsSuper *disk) else { minh = MIN(minh, hdr.mark); - maxl = MAX(maxl, hdr.mark); + maxh = MAX(maxh, hdr.mark); } } else @@ -364,7 +368,7 @@ bool battfs_init(struct BattFsSuper *disk) { TRACEMSG("No valid marked free block found\n"); disk->free_start = 0; - disk->free_next = -1; + disk->free_next = -1; //to be incremented ahead } /* free_next should contain the first usable address */ diff --git a/fs/battfs.h b/fs/battfs.h index 6558877f..9235263e 100644 --- a/fs/battfs.h +++ b/fs/battfs.h @@ -92,7 +92,7 @@ typedef struct BattFsPageHeader * \see battfs_to_disk * \see disk_to_battfs */ -#define BATTFS_HEADER_LEN 13 +#define BATTFS_HEADER_LEN 12 /** * Marks for valid pages. -- 2.25.1