void EFile::rm(uint8_t i_fileId) { blkid_t i = eeFs.files[i_fileId].startBlk; memclear(&eeFs.files[i_fileId], sizeof(eeFs.files[i_fileId])); ENABLE_SYNC_WRITE(true); EeFsFlushDirEnt(i_fileId); if (i) EeFsFree(i); //chain in ENABLE_SYNC_WRITE(false); }
/* * Swap two files in eeprom */ void EFile::swap(uint8_t i_fileId1, uint8_t i_fileId2) { DirEnt tmp = eeFs.files[i_fileId1]; eeFs.files[i_fileId1] = eeFs.files[i_fileId2]; eeFs.files[i_fileId2] = tmp; ENABLE_SYNC_WRITE(true); EeFsFlushDirEnt(i_fileId1); EeFsFlushDirEnt(i_fileId2); ENABLE_SYNC_WRITE(false); }
void EeFsFormat() { ENABLE_SYNC_WRITE(true); memclear(&eeFs, sizeof(eeFs)); eeFs.version = EEFS_VERS; eeFs.mySize = sizeof(eeFs); eeFs.freeList = 0; eeFs.bs = BS; for (blkid_t i=FIRSTBLK; i<BLOCKS-1; i++) { EeFsSetLink(i, i+1); } EeFsSetLink(BLOCKS-1, 0); eeFs.freeList = FIRSTBLK; #if defined(PCBTARANIS) freeBlocks = BLOCKS; #endif EeFsFlush(); ENABLE_SYNC_WRITE(false); }
void EeFsFormat() { ENABLE_SYNC_WRITE(true); memclear(&eeFs, sizeof(eeFs)); eeFs.version = EEFS_VERS; eeFs.mySize = sizeof(eeFs); eeFs.freeList = 0; eeFs.bs = BS; for (blkidL_t i=FIRSTBLK; i<BLOCKS-1 ; i++) { EeFsSetLink(i, i+1) ; wdt_reset() ; } EeFsSetLink(BLOCKS-1, 0); eeFs.freeList = FIRSTBLK; freeBlocks = BLOCKS ; EeFsFlush(); ENABLE_SYNC_WRITE(false); }
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; }