Handle seqnum wraparound.
authorbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 17 Dec 2007 15:49:43 +0000 (15:49 +0000)
committerbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Mon, 17 Dec 2007 15:49:43 +0000 (15:49 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@1039 38d2e660-2303-0410-9eaa-f027e97ec537

fs/battfs.c

index 752ec3c61981a582e581b0ea8a7ecdd1ab33bcb0..1b8bf92336f0f340a8c851765119cb93c5e97968 100644 (file)
@@ -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];