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 */
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;
/* 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;
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;
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).
}
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]() {
/* ------------------------------------------------------------------ */
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)
{
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. */
}
void appendStart() {
+ storage_len_t len = s[client].len - pos;
storage_len_t vlen = (storage_len_t)npages() * PAGE_SIZE;
recordsLost = FALSE;
/* ------------------------------------------------------------------ */
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)
{
else
count = end - offset;
- s[client].buf += count;
- len -= count;
+ pos += count;
s[client].rpos += count;
s[client].roffset = offset + count;