diff options
Diffstat (limited to 'main/common/tfsclean3.c')
-rw-r--r-- | main/common/tfsclean3.c | 141 |
1 files changed, 74 insertions, 67 deletions
diff --git a/main/common/tfsclean3.c b/main/common/tfsclean3.c index af095b0..e8e003e 100644 --- a/main/common/tfsclean3.c +++ b/main/common/tfsclean3.c @@ -1,7 +1,7 @@ /************************************************************************** * * Copyright (c) 2013 Alcatel-Lucent - * + * * Alcatel Lucent licenses this file to You under the Apache License, * Version 2.0 (the "License"); you may not use this file except in * compliance with the License. A copy of the License is contained the @@ -20,7 +20,7 @@ * * tfsclean3.c: * - * --- NOT READY YET --- + * --- NOT READY YET --- * * This version of defragmentation is power-hit safe and requires * that there be double the amount of flash as is needed for use by @@ -39,7 +39,7 @@ * while the background erase is in progress there may be a need to * interact with the flash and most devices don't let you do both at the * same time. - * + * * Note that this "background-erase" is what makes this method the * fastest defrag method. It does require that the erase operation be * interruptible, and it requires that the application will provide the @@ -62,28 +62,28 @@ int tfsfixup(int verbose, int dontquery) { - return(TFSERR_NOTAVAILABLE); + return(TFSERR_NOTAVAILABLE); } #if DEFRAG_TEST_ENABLED int dumpDhdr(DEFRAGHDR *dhp) { - return(TFSERR_NOTAVAILABLE); + return(TFSERR_NOTAVAILABLE); } int dumpDhdrTbl(DEFRAGHDR *dhp, int ftot) { - return(TFSERR_NOTAVAILABLE); + return(TFSERR_NOTAVAILABLE); } #endif /* _tfsclean(): - * This is an alternative to the complicated defragmentation above. - * It simply scans through the file list and copies all valid files - * to RAM; then flash is erased and the RAM is copied back to flash. + * This is an alternative to the complicated defragmentation above. + * It simply scans through the file list and copies all valid files + * to RAM; then flash is erased and the RAM is copied back to flash. * <<< WARNING >>> * THIS FUNCTION SHOULD NOT BE INTERRUPTED AND IT WILL BLOW AWAY * ANY APPLICATION CURRENTLY IN CLIENT RAM SPACE. @@ -91,63 +91,70 @@ dumpDhdrTbl(DEFRAGHDR *dhp, int ftot) int _tfsclean(TDEV *tdp, int notused, int verbose) { - TFILE *tfp; - uchar *tbuf; - ulong appramstart; - int dtot, nfadd, len, err, chkstat; - - if (TfsCleanEnable < 0) - return(TFSERR_CLEANOFF); - - appramstart = getAppRamStart(); - - /* Determine how many "dead" files exist. */ - dtot = 0; - tfp = (TFILE *)tdp->start; - while(validtfshdr(tfp)) { - if (!TFS_FILEEXISTS(tfp)) - dtot++; - tfp = nextfp(tfp,tdp); - } - - if (dtot == 0) - return(TFS_OKAY); - - printf("Reconstructing device %s with %d dead file%s removed...\n", - tdp->prefix, dtot,dtot>1 ? "s":""); - - tbuf = (char *)appramstart; - tfp = (TFILE *)(tdp->start); - nfadd = tdp->start; - while(validtfshdr(tfp)) { - if (TFS_FILEEXISTS(tfp)) { - len = TFS_SIZE(tfp) + sizeof(struct tfshdr); - if (len % TFS_FSIZEMOD) - len += TFS_FSIZEMOD - (len % TFS_FSIZEMOD); - nfadd += len; - if (s_memcpy(tbuf,(uchar *)tfp,len,0,0) != 0) - return(TFSERR_MEMFAIL); - - ((struct tfshdr *)tbuf)->next = (struct tfshdr *)nfadd; - tbuf += len; - } - tfp = nextfp(tfp,tdp); - } - - /* Erase the flash device: */ - err = _tfsinit(tdp); - if (err != TFS_OKAY) - return(err); - - /* Copy data placed in RAM back to flash: */ - err = AppFlashWrite((ulong *)(tdp->start),(ulong *)appramstart, - (tbuf-(uchar*)appramstart)); - if (err < 0) - return(TFSERR_FLASHFAILURE); - - /* All defragmentation is done, so verify sanity of files... */ - chkstat = tfscheck(tdp,verbose); - - return(chkstat); + TFILE *tfp; + uchar *tbuf; + ulong appramstart; + int dtot, nfadd, len, err, chkstat; + + if(TfsCleanEnable < 0) { + return(TFSERR_CLEANOFF); + } + + appramstart = getAppRamStart(); + + /* Determine how many "dead" files exist. */ + dtot = 0; + tfp = (TFILE *)tdp->start; + while(validtfshdr(tfp)) { + if(!TFS_FILEEXISTS(tfp)) { + dtot++; + } + tfp = nextfp(tfp,tdp); + } + + if(dtot == 0) { + return(TFS_OKAY); + } + + printf("Reconstructing device %s with %d dead file%s removed...\n", + tdp->prefix, dtot,dtot>1 ? "s":""); + + tbuf = (char *)appramstart; + tfp = (TFILE *)(tdp->start); + nfadd = tdp->start; + while(validtfshdr(tfp)) { + if(TFS_FILEEXISTS(tfp)) { + len = TFS_SIZE(tfp) + sizeof(struct tfshdr); + if(len % TFS_FSIZEMOD) { + len += TFS_FSIZEMOD - (len % TFS_FSIZEMOD); + } + nfadd += len; + if(s_memcpy(tbuf,(uchar *)tfp,len,0,0) != 0) { + return(TFSERR_MEMFAIL); + } + + ((struct tfshdr *)tbuf)->next = (struct tfshdr *)nfadd; + tbuf += len; + } + tfp = nextfp(tfp,tdp); + } + + /* Erase the flash device: */ + err = _tfsinit(tdp); + if(err != TFS_OKAY) { + return(err); + } + + /* Copy data placed in RAM back to flash: */ + err = AppFlashWrite((ulong *)(tdp->start),(ulong *)appramstart, + (tbuf-(uchar *)appramstart)); + if(err < 0) { + return(TFSERR_FLASHFAILURE); + } + + /* All defragmentation is done, so verify sanity of files... */ + chkstat = tfscheck(tdp,verbose); + + return(chkstat); } #endif |