]> oss.titaniummirror.com Git - tinyos-2.x.git/blobdiff - tos/chips/at45db/LogStorageP.nc
Remove bogus 'tab:4' and 'tab:2' markers.
[tinyos-2.x.git] / tos / chips / at45db / LogStorageP.nc
index 3cb8ab96c5f3a19a5c82e1e0deedafd26e852287..8765682960dd1f2b422d157491284ea5fea31aaf 100644 (file)
@@ -1,4 +1,4 @@
-/*                                                                     tab:4
+/*
  * "Copyright (c) 2000-2004 The Regents of the University  of California.  
  * All rights reserved.
  *
@@ -198,6 +198,7 @@ implementation
 
   uint8_t client = NO_CLIENT;
   uint8_t metaState;
+  bool recordsLost;
   at45page_t firstPage, lastPage;
   storage_len_t len;
   nx_struct pageinfo metadata;
@@ -266,6 +267,9 @@ implementation
   void sync() {
     metadata.flags = F_SYNC | F_LASTVALID;
     metadata.lastRecordOffset = s[client].woffset;
+    /* rend is now no longer the end of the page */
+    if (s[client].rpage == s[client].wpage)
+      s[client].rend = s[client].woffset;
     wmetadataStart();
   }
 
@@ -313,7 +317,7 @@ implementation
     switch (request)
       {
       case R_ERASE: signal LogWrite.eraseDone[c](ok); break;
-      case R_APPEND: signal LogWrite.appendDone[c](ptr, actualLen, ok); break;
+      case R_APPEND: signal LogWrite.appendDone[c](ptr, actualLen, recordsLost, ok); break;
       case R_SYNC: signal LogWrite.syncDone[c](ok); break;
       case R_READ: signal LogRead.readDone[c](ptr, actualLen, ok); break;
       case R_SEEK: signal LogRead.seekDone[c](ok); break;
@@ -378,7 +382,7 @@ implementation
   }
 
   command error_t LogRead.seek[uint8_t id](storage_cookie_t offset) {
-    return newRequest(R_SEEK, id, (void *)(offset >> 16), offset);
+    return newRequest(R_SEEK, id, (void *)((uint16_t)(offset >> 16)), offset);
   }
 
   command storage_len_t LogRead.getSize[uint8_t id]() {
@@ -593,6 +597,11 @@ implementation
     s[client].woffset += count;
     len -= count;
 
+    /* We normally lose data at the point we make the first write to a
+       page in a log that has circled. */
+    if (offset == 0 && s[client].circled)
+      recordsLost = TRUE;
+
     call At45db.write(s[client].wpage, offset, buf, count);
   }
   
@@ -617,6 +626,8 @@ implementation
   void appendStart() {
     storage_len_t vlen = (storage_len_t)npages() * PAGE_SIZE;
 
+    recordsLost = FALSE;
+
     /* If request would span the end of the flash, sync, to maintain the
        invariant that the last flash page is synced and that either
        the first or last pages are valid.
@@ -625,7 +636,7 @@ implementation
        would end on the last byte of the last page, as this would mean that
        we would not sync the last page, breaking the log volume
        invariant */
-    if (s[client].wpos % vlen >= vlen - len)
+    if ((s[client].wpos - PAGE_SIZE) % vlen >= vlen - len)
       sync();
     else
       {
@@ -726,7 +737,7 @@ implementation
          s[client].rpage = s[client].wpage;
        else
          {
-           /* resume writing at the beginning of the first page */
+           /* resume reading at the beginning of the first page */
            s[client].rvalid = TRUE;
            s[client].rpage = lastVolumePage() - 1;
          }
@@ -967,7 +978,7 @@ implementation
 
   event void At45db.copyPageDone(error_t error) { }
 
-  default event void LogWrite.appendDone[uint8_t logId](void* buf, storage_len_t l, error_t error) { }
+  default event void LogWrite.appendDone[uint8_t logId](void* buf, storage_len_t l, bool rLost, error_t error) { }
   default event void LogWrite.eraseDone[uint8_t logId](error_t error) { }
   default event void LogWrite.syncDone[uint8_t logId](error_t error) { }
   default event void LogRead.readDone[uint8_t logId](void* buf, storage_len_t l, error_t error) { }
@@ -976,5 +987,5 @@ implementation
   default command at45page_t At45dbVolume.remap[uint8_t logId](at45page_t volumePage) {return 0;}
   default command at45page_t At45dbVolume.volumeSize[uint8_t logId]() {return 0;}
   default async command error_t Resource.request[uint8_t logId]() {return SUCCESS;}
-  default async command void Resource.release[uint8_t logId]() { }
+  default async command error_t Resource.release[uint8_t logId]() { return FAIL; }
 }