]> oss.titaniummirror.com Git - tinyos-2.x.git/commitdiff
add @safe(), deputize LogStorageP, fix LogStorageP bug
authoridgay <idgay>
Mon, 23 Jun 2008 21:11:09 +0000 (21:11 +0000)
committeridgay <idgay>
Mon, 23 Jun 2008 21:11:09 +0000 (21:11 +0000)
tos/chips/at45db/At45dbStorageManagerC.nc
tos/chips/at45db/LogStorageP.nc

index 1d857d0d08944a68ab4e995ee98d10f6460991ea..15dfcc4227d89ccc2d32122a1771658bfea0612c 100644 (file)
@@ -14,7 +14,7 @@
  * @author: David Gay <dgay@acm.org>
  */
 
-module At45dbStorageManagerC {
+module At45dbStorageManagerC @safe() {
   provides interface At45dbVolume[volume_id_t volid];
 }
 implementation {
index bf8660ebca4cf4378ce0cf8b64c490b1610d1138..f228e3ffd4537c8b41be91c9f7e700b2d741a403 100644 (file)
@@ -200,13 +200,13 @@ implementation
   uint8_t metaState;
   bool recordsLost;
   at45page_t firstPage, lastPage;
-  storage_len_t len;
+  storage_len_t pos;
   nx_struct pageinfo metadata;
 
   struct {
     /* The latest request made for this client, and it's arguments */
     uint8_t request; 
-    uint8_t *buf;
+    uint8_t *COUNT_NOK(len) buf;
     storage_len_t len;
 
     /* Log r/w positions */
@@ -306,8 +306,8 @@ implementation
   void endRequest(error_t ok) {
     uint8_t c = client;
     uint8_t request = s[c].request;
-    storage_len_t actualLen = s[c].len - len;
-    void *ptr = s[c].buf - actualLen;
+    storage_len_t actualLen = pos;
+    void *ptr = s[c].buf;
     
     client = NO_CLIENT;
     s[c].request = R_IDLE;
@@ -326,7 +326,7 @@ implementation
 
   /* Enqueue request and request the underlying flash */
   error_t newRequest(uint8_t newRequest, uint8_t id,
-                    uint8_t *buf, storage_len_t length) {
+                    uint8_t *COUNT_NOK(length) buf, storage_len_t length) {
     s[id >> 1].circular = id & 1;
     id >>= 1;
 
@@ -334,8 +334,9 @@ implementation
       return EBUSY;
 
     s[id].request = newRequest;
-    s[id].buf = buf;
+    s[id].buf = NULL;
     s[id].len = length;
+    s[id].buf = buf;
     call Resource.request[id]();
 
     return SUCCESS;
@@ -343,12 +344,12 @@ implementation
 
   event void Resource.granted[uint8_t id]() {
     client = id;
-    len = s[client].len;
+    pos = 0;
     startRequest();
   }
 
   command error_t LogWrite.append[uint8_t id](void* buf, storage_len_t length) {
-    if (len > call LogRead.getSize[id]() - PAGE_SIZE)
+    if (length > call LogRead.getSize[id]() - PAGE_SIZE)
       /* Writes greater than the volume size are invalid.
         Writes equal to the volume size could break the log volume
         invariant (see next comment).
@@ -382,7 +383,7 @@ implementation
   }
 
   command error_t LogRead.seek[uint8_t id](storage_cookie_t offset) {
-    return newRequest(R_SEEK, id, (void *)((uint16_t)(offset >> 16)), offset);
+    return newRequest(R_SEEK, id, TCAST(void *COUNT(offset), ((uint16_t)(offset >> 16))), offset);
   }
 
   command storage_len_t LogRead.getSize[uint8_t id]() {
@@ -571,8 +572,9 @@ implementation
   /* ------------------------------------------------------------------ */
 
   void appendContinue() {
-    uint8_t *buf = s[client].buf;
+    uint8_t *buf = s[client].buf + pos;
     at45pageoffset_t offset = s[client].woffset, count;
+    storage_len_t len = s[client].len - pos;
     
     if (len == 0)
       {
@@ -592,10 +594,9 @@ implementation
     else
       count = PAGE_SIZE - offset;
 
-    s[client].buf += count;
     s[client].wpos += count;
     s[client].woffset += count;
-    len -= count;
+    pos += count;
 
     /* We normally lose data at the point we make the first write to a
        page in a log that has circled. */
@@ -624,6 +625,7 @@ implementation
   }
 
   void appendStart() {
+    storage_len_t len = s[client].len - pos;
     storage_len_t vlen = (storage_len_t)npages() * PAGE_SIZE;
 
     recordsLost = FALSE;
@@ -720,9 +722,10 @@ implementation
   /* ------------------------------------------------------------------ */
 
   void readContinue() {
-    uint8_t *buf = s[client].buf;
+    uint8_t *buf = s[client].buf + pos;
     at45pageoffset_t offset = s[client].roffset, count;
     at45pageoffset_t end = s[client].rend;
+    storage_len_t len = s[client].len - pos;
     
     if (len == 0)
       {
@@ -764,8 +767,7 @@ implementation
     else
       count = end - offset;
 
-    s[client].buf += count;
-    len -= count;
+    pos += count;
     s[client].rpos += count;
     s[client].roffset = offset + count;