예제 #1
0
BOOL fs_mark_fileMem (IOB *fcb) {
  FALLOC fa;
  U32 i,adr,bl,prev;

  bl = fcb->_fblock;
  for (i = 0; i < fcb->NumSect; i++) {
    /* Search for file blocks identified with identification 'fileID' */
    adr = fs_adr_sig (bl, fcb);
    adr = fs_rd_sig (adr, &fa.end);
    if (fa.end != fcb->InitVal) {
      for (prev = 0; ; prev = fa.end) {
        adr = fs_rd_alloc (adr, &fa);
        if (fa.fileID == fcb->fileID && fa.index == fcb->_fidx) {
          /* Set Current File Block parameters */ 
          fcb->_fblock = bl;
          fcb->_fbot = (prev + 3) & ~3;
          fcb->_ftop = fa.end;
          fcb->_fidx++; 
          return (__TRUE); 
        }
        if (fa.end == fcb->InitVal) break;
      }
    }
    if (++bl == fcb->NumSect) {
      bl = 0;
    }
  }
  return (__FALSE);
}
예제 #2
0
void fs_mark_freeMem (IOB *fcb) {
  FALLOC fa;
  U32 adr,prev;

  adr = fs_adr_sig (fcb->_fblock, fcb) - 8;
  for (prev = 0; ; prev = fa.end) {
    adr = fs_rd_alloc (adr, &fa);
    if (fa.end == fcb->InitVal) break;
  }
  /* All file blocks are 4-byte aligned. */
  fcb->_fbot = (prev + 3) & ~3;
  fcb->_ftop = (adr & ~1) + 8 - ((DEVCONF *)fcb->DevCfg)[fcb->_fblock].bStart;
}
예제 #3
0
U32 __getfsize (IOB *fcb, BOOL set_fidx) {
   /* Low level get file size function. */
   FALLOC fa;
   U32 bl,fidx,adr,prev;
   U32 i,fsize;

   START_LOCK (U32);

   if (fcb->drive == DRV_MCARD) {
      /* This info is available for Flash Card. */
      RETURN (fcb->fsize);
   }
   if ((fcb->flags & _IOAPPEND) && (set_fidx == __FALSE)) {
      /* Size info already set in '__fopen()'. */
      RETURN (fcb->fsize);
   }
   fidx = 0;
   fsize = 0;
   bl = fcb->_fblock;
nextbl:
   for (i = 0; i < fcb->NumSect; i++) {
      /* Search for file blocks identified with identification 'fileID' */
      adr = fs_adr_sig (bl, fcb);
      adr = fs_rd_sig (adr, &fa.end);
      if (fa.end != fcb->InitVal) {
         for (prev = 0; ; prev = fa.end) {
            adr = fs_rd_alloc (adr, &fa);
            if (fa.fileID == fcb->fileID  &&  fa.index == fidx) {
               /* All file blocks are 4-byte aligned. */
               fsize += (fa.end - ((prev + 3) & ~3));
               fidx++;
               goto nextbl;
            }
            if (fa.end == fcb->InitVal) break;
         }
      }
      if (++bl == fcb->NumSect) {
         bl = 0;
      }
   } 
   /* This File Block does not exist so this must be End Of File */
   if (set_fidx == __TRUE) {
      fcb->_fidx = fidx;
   }
   RETURN (fsize);

   END_LOCK;
} /* end of _getfsize */
예제 #4
0
U32 fs_get_freeMem (U32 block, IOB *fcb) {
  FALLOC fa;
  U32 size,adr,prev;

  adr = fs_adr_sig (block, fcb) - 8;
  for (prev = 0; ; prev = fa.end) {
    adr = fs_rd_alloc (adr, &fa);
    if (fa.end == fcb->InitVal) break;
  }
  size = (adr & ~1) + 8 - ((DEVCONF *)fcb->DevCfg)[block].bStart - prev;
  if (size < 256) {
    /* This block is considered to be full. */
    return (0);
  }
  return (size);
}
예제 #5
0
BOOL fs_BlockInvalid (U32 block, IOB *fcb)  {
  FALLOC fa;
  U32 adr;
  U16 invalid;

  invalid = ~fcb->InitVal;
  /* Check if this Flash Block is all invalided */
  adr = fs_adr_sig (block, fcb) - 8;
  for (;;) {
    adr = fs_rd_alloc (adr, &fa);
    if (fa.end == fcb->InitVal) break;
    if (fa.fileID != invalid) {
      /* A valid file block found */
      return (__FALSE);
    }
  }
  return (__TRUE);
}
예제 #6
0
U32 fs_Find_File (const char *fname, IOB *fcb) {
  FALLOC fa;
  U8 buf[32];
  U32 bl,adr,prev,name;
  U32 fid = 0x8000;

  for (bl = 0; bl < fcb->NumSect; bl++) {
    /* Search all allocated File Blocks for a given 'fname */
    adr = fs_adr_sig (bl, fcb);
    adr = fs_rd_sig (adr, &fa.end);
    if (fa.end != fcb->InitVal) {
      for (prev = 0; ; prev = fa.end) {
        adr = fs_rd_alloc (adr, &fa);
        if (fa.fileID > 0x8000 && fa.fileID < 0xFFFF) {
          /* Filename is 4-byte aligned. */
          name = ((DEVCONF *)fcb->DevCfg)[bl].bStart + prev;
          name = (name + 3) & ~3;
          if (adr & 0x01) {
            /* Copy name for SPI Flash Drive. */
            fs_spi_ReadData (name, sizeof (buf), (U8 *)&buf);
          }
          else {
            fs_ReadData (name, sizeof (buf), (U8 *)&buf);
          }
          buf[31] = 0;
          if (fn_cmp (fname, (char *)&buf) == __TRUE) {
            /* File with 'fname' has been found */
            fcb->fileID  = fa.fileID & 0x7FFF;
            fcb->_fblock = bl;
            return (0);
          }
          /* Search for the max fileID in use */
          if (fa.fileID > fid) {
            fid = fa.fileID;
          }
        }
        if (fa.end == fcb->InitVal) break;
      }
    }
  }
  /* 'fid' is a nonzero value here */
  return (fid);
}
예제 #7
0
U16 fs_get_freeID (U32 maxID, IOB *fcb) {
  FALLOC fa;
  U32 bl,fid,adr;

  maxID |= 0x8000;
  for (fid = 0x8001; fid < maxID;  ) {
    for (bl = 0; bl < fcb->NumSect; bl++) {
      adr = fs_adr_sig (bl, fcb) - 8;
      for (;;) {
        adr = fs_rd_alloc (adr, &fa);
        /* If this fileID is used, go and check next one */
        if (fa.fileID == fid) goto nextfid;
        if (fa.end == fcb->InitVal) break;
      }
    }
    return (fid & 0x7FFF);
nextfid:
    fid++;
  }
  return ((maxID + 1) & 0x7FFF);
}