⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 writesec.c

📁 intel的一个高效率FLASH文件系统。思路很好
💻 C
📖 第 1 页 / 共 2 页
字号:
         {
            ReclaimThresholdOverride = FALSE;
            return (ERR_MEMORY_FULL);
         }
      }
      RetVal=ReclaimVSB( component );      /* yep, try reclaiming discards */

      /* If there isn't any discarded VSBs and autoReclaim enabled
         returns ERR_MEMORY_FULL */
      if(RetVal == ERR_MEMORY_FULL)
      {
         ReclaimThresholdOverride = FALSE;
         return (RetVal);
      }

   }
   else if((ReclaimEnable[component] == 0) &&
           (status_ptr->clean_sectors <= RECLAIM_THRESHOLD))
   {
      ReclaimThresholdOverride = FALSE;

       /* If there are no discarded VSBs and autoReclaim disabled
          returns ERR_MEMORY_FULL */
      if (status_ptr->dirty_sectors == 0)
         return (ERR_MEMORY_FULL);

      /* If there are discarded VSBs and autoReclaim disabled
         returns ERR_SPACE */
      else return (ERR_SPACE);
   }

   if( RetVal == ERR_NONE )               /* so far so good? */
   {
      /* set up current block to write block */
      CurrentBlock[component] = WriteBlock[component];
      RetVal = FindVSB( component, VSB_FREE );     /* look for a free VSB */
      if( RetVal == ERR_NONE )       /* if free sector exist... */
      {
          /* starting to write in a new block? */
         if( CurrentBlock[component] != WriteBlock[component] )
         {
            /* setup physical address of old write block */
            FlashAddr = CalculateFlashAddr( component, WriteBlock[component],
                                            VSB_FB_ATTR );
            if((RetVal = FlashDevRead( FlashAddr,     /* mark block as full */
                                       sizeof( BYTE),
                                       &FlashData )) != ERR_NONE)
               return (RetVal);
            if(FlashData != DEFAULT_BYTE)
            {
               FlashData = VSB_FB_FULL;
#if PLR_TESTING
               if (PowerLossFlags.breakpoint_number == PLR_BP22)
                  PowerLossFlags.current_iteration++;
#endif
               RetVal = FlashDevWrite( FlashAddr,    /* mark block as full */
                                       sizeof( BYTE),
                                       &FlashData );
            }
            if( RetVal == ERR_NONE )
            {
               /* set up new write block */
               WriteBlock[component] = CurrentBlock[component];
               /* get physical address of new block */
               FlashAddr = CalculateFlashAddr( component,
                                               CurrentBlock[component],
                                               VSB_FB_ATTR );
               FlashData = VSB_FB_WRITE;
#if PLR_TESTING
               if (PowerLossFlags.breakpoint_number == PLR_BP23)
                  PowerLossFlags.current_iteration++;
#endif
               RetVal = FlashDevWrite( FlashAddr,   /* mark new write block */
                                       sizeof( BYTE ), &FlashData );

               if( RetVal != ERR_NONE )
                  RetVal = ERR_WRITE;
            }
            else RetVal = ERR_WRITE;
         }

         if( RetVal == ERR_NONE )
         {
#if PLR_TESTING
            if (PowerLossFlags.breakpoint_number == PLR_BP24)
               PowerLossFlags.current_iteration++;
#endif
            RetVal = WriteVATEntry( VSB_ALLOCATING ); /* mark found VSB */

#if PLR_TESTING
            if (PowerLossFlags.breakpoint_number == PLR_BP28)
               PowerLossFlags.current_iteration++;
#endif
            if( RetVal == ERR_NONE )
            {
               VSBToWrite = VSB;       /* setup global variables */
               CurrentByte[component] = 0;
               VSBFound = FALSE;
            }
         }
      }/*end of if free sector exist... */
   }
   if( ReclaimThresholdOverride == TRUE )
      ReclaimThresholdOverride = FALSE;
   if ( RetVal != ERR_NONE )
   {
      return( ERR_NOT_FOUND );
   }
   
   if( ByteCount != 0 )                    /* if no bytes to write */
   {
      /* will write overrun VSB? */
      if( CurrentByte[CurrentComponent] + ByteCount > VSB_SIZE )
      {
         return( ERR_VSB_OVERFLOW );
      }
      /*    copy source data from RAM buffer to flash. */
       SaveCurrentVSB = CurrentVSB[CurrentComponent];
       SaveCurrentBlock = CurrentBlock[CurrentComponent];
       /*Comment-, No need to change this for E2.3.41, uses currentVSB which is changed in FindVSB*/
       FlashAddr=CalculateFlashAddr( CurrentComponent, SaveCurrentBlock,SaveCurrentVSB);
       RetVal = MoveVSB (FlashAddr/*CalculateFlashAddr( CurrentComponent, SaveCurrentBlock,
                         SaveCurrentVSB)*/,MOVE_FLASH,(DWORD)Table,MOVE_RAM,
                         ByteCount);
      if( RetVal != ERR_NONE )
      {
         return( RetVal );
      }
      CurrentByte[CurrentComponent] += ByteCount;     /* update byte count */
   }

   /* is VSB full? */
   if( CurrentByte[CurrentComponent] == ByteCount || ByteCount == 0 )
   {
      /* save new VAT entry */
#if PLR_TESTING
      if (PowerLossFlags.breakpoint_number == PLR_BP25)
         PowerLossFlags.current_iteration++;
#endif
      RetVal = WriteVATEntry( (WORD)(VSBToWrite | VSB_VAT_FLAGS) );
      if( RetVal != ERR_NONE )
      {
         return( RetVal );
      }
      /*Comment-, No need to change this for E2.3.41, uses currentVSB which is changed in FindVSB*/
      RetVal = WriteVATEntry( VSB_ALLOCATED ); /* mark new one as allocated */

      if( RetVal != ERR_NONE )
      {
         return( RetVal );
      }
      if (RewriteFlag == TRUE)
      {
         /* save global variables so we can...*/
         SaveCurrentVSB = CurrentVSB[CurrentComponent];
         SaveCurrentBlock = CurrentBlock[CurrentComponent];
         SaveCurrentIndex = CurrentIndex[CurrentComponent];
         SaveCurrentComponent = CurrentComponent;

         /* search for a VSB with the same ID as we are now using*/
         RetVal = FindVSB( CurrentComponent,
                           VSBToWrite );
         if( RetVal == ERR_NONE )
         {
            /* find a previous one? if so discard it*/
#if PLR_TESTING
            if (PowerLossFlags.breakpoint_number == PLR_BP26)
               PowerLossFlags.current_iteration++;
#endif
            /*Comment-, No need to change this, uses currentVSB which is changed in FindVSB*/
            RetVal = WriteVATEntry( VSB_DISCARDED );
            if( RetVal != ERR_NONE )
            {
               return( RetVal );
            }
         }

         /* restore global variables */
         CurrentComponent = SaveCurrentComponent;
         CurrentVSB[CurrentComponent] = SaveCurrentVSB;
         CurrentBlock[CurrentComponent] = SaveCurrentBlock;
         CurrentIndex[CurrentComponent] = SaveCurrentIndex;

      }

      /* Mark new one as completely valid */
#if PLR_TESTING
      if (PowerLossFlags.breakpoint_number == PLR_BP27)
         PowerLossFlags.current_iteration++;
#endif
      /*Comment-, No need to change this for E2.3.41, uses currentVSB which is changed in FindVSB*/
      RetVal = WriteVATEntry( VSB_VALID );

   }
   return( RetVal );

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -