From: batt Date: Mon, 17 Dec 2007 15:49:43 +0000 (+0000) Subject: Handle seqnum wraparound. X-Git-Tag: 1.0.0~203 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=781d5135a61025caea65ef66b5c6bde2ef950e40;p=bertos.git Handle seqnum wraparound. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1039 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/fs/battfs.c b/fs/battfs.c index 752ec3c6..1b8bf923 100644 --- a/fs/battfs.c +++ b/fs/battfs.c @@ -339,8 +339,9 @@ bool battfs_init(struct BattFsSuper *disk) pgcnt_t new_page, old_page; fill_t old_fill; - #warning fix seq wraparound! - if (hdr.seq > hdr_old.seq) + /* Fancy check to handle seq wraparound */ + #define HALF_SEQ ((1 << (sizeof(seq_t) * CPU_BITS_PER_CHAR)) / 2) + if ((hdr.seq - hdr_old.seq) < HALF_SEQ) { /* Actual header is newer than the previuos one */ old_page = disk->page_array[array_pos];