Beispiel #1
0
void EFile::EeFsFree(uint8_t blk){///free one or more blocks
  uint8_t i = blk;
  while( EeFsGetLink(i)) i = EeFsGetLink(i);
  EeFsSetLink(i,eeFs->freeList);
  eeFs->freeList = blk; //chain in front
  EeFsFlushFreelist();
}
Beispiel #2
0
uint8_t EFile::EeFsAlloc(){ ///alloc one block from freelist
  uint8_t ret=eeFs->freeList;
  if(ret){
    eeFs->freeList = EeFsGetLink(ret);
    EeFsFlushFreelist();
    EeFsSetLink(ret,0);
  }
  return ret;
}
Beispiel #3
0
int8_t EFile::EeFsck()
{
  uint8_t *bufp;
  static uint8_t buffer[BLOCKS];
  bufp = buffer;
  memset(bufp,0,BLOCKS);
  uint8_t blk ;
  int8_t ret=0;
  for(uint8_t i = 0; i <= MAXFILES; i++){
    uint8_t *startP = i==MAXFILES ? &(eeFs->freeList) : &(eeFs->files[i].startBlk);
    uint8_t lastBlk = 0;
    blk = *startP;
      //if(i == MAXFILES) blk = eeFs->freeList;
      //    else              blk = eeFs->files[i].startBlk;
    while(blk){
      //      if(blk <  FIRSTBLK ) goto err_1; //bad blk index
      //      if(blk >= BLOCKS   ) goto err_2; //bad blk index
      //      if(bufp[blk])        goto err_3; //blk double usage
      if( (   blk <  FIRSTBLK ) //goto err_1; //bad blk index
          || (blk >= BLOCKS   ) //goto err_2; //bad blk index
          || (bufp[blk]       ))//goto err_3; //blk double usage
      {
        if(lastBlk){
          EeFsSetLink(lastBlk,0);
        }else{
          *startP = 0; //interrupt chain at startpos
          EeFsFlush();
        }
        blk=0; //abort
      }else{
        bufp[blk] = i+1;
        lastBlk   = blk;
        blk       = EeFsGetLink(blk);
      }
    }
  }
  for(blk = FIRSTBLK; blk < BLOCKS; blk++){
    if(bufp[blk]==0) {       //goto err_4; //unused block
      EeFsSetLink(blk,eeFs->freeList);
      eeFs->freeList = blk; //chain in front
      EeFsFlushFreelist();
    }
  }
  //  if(0){
    //err_4: ret--;
    //err_3: ret--;
    //    err_2: ret--;
    //    err_1: ret--;
  //  }
  return ret;
}
Beispiel #4
0
/// free one or more blocks
static void EeFsFree(blkid_t blk)
{
  blkid_t i = blk;
  blkid_t tmp;

  freeBlocks++;

  while ((tmp=EeFsGetLink(i))) {
    i = tmp;
    freeBlocks++;
  }

  EeFsSetLink(i, eeFs.freeList);
  eeFs.freeList = blk; //chain in front
  EeFsFlushFreelist();
}
Beispiel #5
0
/// free one or more blocks
static void EeFsFree(blkid_t blk)
{
  blkid_t i = blk;
  blkid_t tmp;

#if defined(PCBTARANIS)
  freeBlocks++;
#endif

  while ((tmp=EeFsGetLink(i))) {
    i = tmp;
#if defined(PCBTARANIS)
    freeBlocks++;
#endif
  }

  EeFsSetLink(i, eeFs.freeList);
  eeFs.freeList = blk; //chain in front
  EeFsFlushFreelist();
}
Beispiel #6
0
int8_t EeFsck()
{
  ENABLE_SYNC_WRITE(true);

  uint8_t *bufp = (uint8_t *)&g_model;
  memclear(bufp, BLOCKS);
  blkid_t blk ;

#if defined(PCBTARANIS)
  blkid_t blocksCount;
#endif
  for (uint8_t i=0; i<=MAXFILES; i++) {
#if defined(PCBTARANIS)
    blocksCount = 0;
#endif
    blkid_t *startP = (i==MAXFILES ? &eeFs.freeList : &eeFs.files[i].startBlk);
    blkid_t lastBlk = 0;
    blk = *startP;
    while (blk) {
      if (blk < FIRSTBLK || // bad blk index
          blk >= BLOCKS  || // bad blk indexchan
          bufp[blk])        // blk double usage
      {
        if (lastBlk) {
          EeFsSetLink(lastBlk, 0);
        }
        else {
          *startP = 0; // interrupt chain at startpos
          EeFsFlush();
        }
        blk = 0; // abort
      }
      else {
#if defined(PCBTARANIS)
        blocksCount++;
#endif
        bufp[blk] = i+1;
        lastBlk   = blk;
        blk       = EeFsGetLink(blk);
      }
    }
  }

#if defined(PCBTARANIS)
  freeBlocks = blocksCount;
#endif

  for (blk=FIRSTBLK; blk<BLOCKS; blk++) {
    if (!bufp[blk]) { // unused block
#if defined(PCBTARANIS)
      freeBlocks++;
#endif
      EeFsSetLink(blk, eeFs.freeList);
      eeFs.freeList = blk; // chain in front
      EeFsFlushFreelist();
    }
  }

  ENABLE_SYNC_WRITE(false);

  return 0;
}