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

📄 davrcvr.c

📁 Flash file system
💻 C
📖 第 1 页 / 共 3 页
字号:
         {
           /* Restart Reallocate */
           status = RECOVER_RestartReAllocate(ht_entry_index, &ht_cfg_entry);
         }
      }
      else
      {
         /* No para reclaim or reallocate is in progress, */ 
         /*  continue on to repair last header.           */
         status = ERR_NONE;
      }
   }
   else
   {
      switch (rb_cfg_status)
      {
         case ConfigEntries:
           /* Check what scan revealed */
           if ((!CFGHDR_IsUnusedConfigurationEntry(rb_cfg_entry)) && 
               (rb_entry_index != 0xFF))
           {
              if (CFGHDR_GetReclaimEntryState(rb_cfg_entry) == 
                                         CFGHDR_STATE_ReclaimInProgress)

              {
                 /* Restart Paragraph Reclaim */
                 status = RECOVER_RestartReclaim(rb_entry_index, 
                                                 &rb_cfg_entry);
              }
              else
              {
                 /* Restart Reallocate */
                 status = RECOVER_RestartReAllocate(rb_entry_index, 
                                                    &rb_cfg_entry);
              }
           }
           else
           {
              /* Not a possible state, with data in rb but no reclaim. */
              status = ERR_SYSTEM; 
           }
         break;
           
         case NoConfigHeader:
           if (ht_cfg_status == NoConfigHeader)
           {
              /* Unformatted Flash Error */
              status = ERR_FORMAT;
              break;
           }   
         /*lint -fallthrough*/
         case NoConfigEntries:
          
           /* Set Global flag for System State */
           SetSystemState(FDI_SystemState, FDI_ST_CfgHdrRecover);

           /* Restart Cfg Header Reclaim */
           status = CFGHDR_ConfigurationHeaderReclaim(TRUE);
         break;  
           
      }
   }

#ifdef ENABLE_RECOVER_TESTS
   EVT_TestEvent(EVT_RECOVER_CheckSystemStatus_End);
#endif

   return (status);
}    

/*#################################################################
  ### RECOVER_CheckConfigurationHeader
  ###
  ### DESCRIPTION:
  ###   This function will check for a configuration header. If
  ###   a config header is found, it will determine the state of
  ###   configuration entries.
  ###
  ### PARAMETERS 
  ###   cfg_header_handle - Handle the the configuration header.
  ###   cfg_entry_ptr     - On return, this will contain the config.
  ###                       entry in use, if one exists.
  ###   entry_index_ptr   - On return, this will contain the config.
  ###                       entry index of the cfg entry in use,
  ###                       if one exists.
  ###
  ### RETURNS:
  ###   This function will return the state of the cfg header pointed
  ###   to by the cfg_header_handle through the cfg_status_ptr.
  ###   also ERR_CODE
  ###*/
ERR_CODE RECOVER_CheckConfigurationHeader(
                               FDI_Handle cfg_header_handle,
                               CFGHDR_ConfigurationEntryPtr cfg_entry_ptr,
                               UINT8_PTR entry_index_ptr, 
                               RECOVER_CfgEntryStatus *cfg_status_ptr, 
                               BOOLEAN restart)
{
   HDR_Header header;
   FDI_Handle unique_id_handle, array_handle;
   HDR_SearchInfo cfg_entry_info;
   UINT16 unique_id;
   ERR_CODE status = ERR_NONE;

#ifdef ENABLE_RECOVER_TESTS
   EVT_TestEvent(EVT_RECOVER_CheckConfigurationHeader_Start);
#endif

      status = HDR_ReadFullHeader(cfg_header_handle, &header, restart);
      if(status)
      {
          return status;
      }      
      cfg_entry_info.HeaderPtr = &header;
      /* Authenticate header */
      if (HDR_AuthenticateHeader(&cfg_entry_info))
      {
         if (header.ObjectType == FDI_HT_ConfigHeader)
         {
            /* Read Unique Id 1 */
            HDR_GetObjectSize(&header, &unique_id_handle);
            
            unique_id_handle = cfg_header_handle - unique_id_handle;

            array_handle = unique_id_handle + CFGHDR_EntryArrayOffset;
            FLASH_ReadBuffer(unique_id_handle, (MemBufferPtr)&unique_id,
                                                        sizeof(unique_id));
            status = UINT16_FixISF_PLR(&unique_id, unique_id_handle, restart);   
            if(status)
            {
                return status;
            }
            /* Check Unique Identifier */
            if (unique_id == CFGHDR_UniqueIdentifierValue)
            {
               /* Read Unique Id 2 */
                unique_id_handle += CFGHDR_UniqueId2Offset;
               FLASH_ReadBuffer(unique_id_handle, (MemBufferPtr)&unique_id,
                                                         sizeof(unique_id));
               status = UINT16_FixISF_PLR(&unique_id, unique_id_handle, restart);                                             
               if(status)
               {
                   return status;
               }
           
               if (unique_id == CFGHDR_UniqueIdentifierValue)
               {
                  /* Check entries for a reclaim or reallocate */
                  status = CFGHDR_ScanConfigurationEntry(entry_index_ptr, 
                                               cfg_entry_ptr, array_handle,
                                               restart);
                  if(status)
                  {
                     return status;
                  }
                  *cfg_status_ptr = ConfigEntries;
                  return ERR_NONE; 
                 
               }
            }
            *cfg_status_ptr = NoConfigEntries;
            return ERR_NONE;   
         }  
      }
      *cfg_status_ptr = NoConfigHeader;
      return ERR_NONE;
}    


/*########################################################################*/
/*### Functions for repairing write in progress objects                   */
/*########################################################################*/


/*#################################################################
  ### RECOVER_RestoreWriteInProgressObjects
  ###
  ### DESCRIPTION:
  ###   This function will scan the header table for Write in Progress
  ###    objects.  If one is found, it will then restore the original
  ###    if one is available.
  ###
  ### PARAMETERS 
  ###   none.
  ###
  ### RETURNS:
  ###   When this function passes with no errors a value of 0 is
  ###   returned otherwise, it returns a status of type ERR_CODE.
  ###*/
ERR_CODE RECOVER_RestoreWriteInProgressObjects(BOOLEAN restart)
{
   HDR_CompareInfo compare_info = Init_HDR_CompareInfo;
   ERR_CODE      status;
   HDR_Header      first_obj_header;
   HDR_SearchInfo  first_obj_info;

#ifdef ENABLE_RECOVER_TESTS
   EVT_TestEvent(EVT_RECOVER_RestoreWriteInProgessObjects_Start);
#endif

   /* must reclaim to cleanup the used reserved page space. */
   status = DAVSRECL_CheckReclaimLevel();
   if (status)
   {
      return status;
   }

   status = ERR_NONE;
   
   /* Scan the entire header table for WIP Objects */
   HDR_InitSearchInfo((&FDI_SearchInfo), (&FDI_SearchHeader)); 
   HDR_InitSearchInfo((&first_obj_info), (&first_obj_header));
   
   while(!status)
   {
      status = GetNextHeader(&FDI_SearchInfo, 
                        HDR_ByNextWriteInProgressObject, 
                                                 &compare_info, restart);
      if (status)
      {
         break;
      }                                              
      
      if (HDR_IsBackupComplete(FDI_SearchInfo.HeaderPtr->Attr16))
      {
         /* Found a backup of an object.                  */
         /* Now need to restore it to the original object */

         /* Search for first header. */
         status = HDR_ReadFullHeader(FDI_SearchInfo.CurrObj.HeaderAddress, 
                                     FDI_SearchInfo.HeaderPtr,
                                     restart);
         if(status)
         {
            return status;
         }                                          
         compare_info.NamePtr      = (HDR_NamePtr)(FDI_SearchInfo.HeaderPtr->Name);
         compare_info.NameSize     = FDI_SearchInfo.HeaderPtr->NameSize;
         compare_info.CompareValue = FDI_SearchInfo.HeaderPtr->ObjectType;
         FDI_GlobalInfo.CurrObj.HeaderAddress = 0;
         FDI_GlobalInfo.CurrObj.ConfigEntry.Offset = 0;
         FDI_GlobalInfo.CurrObj.ConfigEntry.Status = 0;
         status = GetNextHeader(&first_obj_info, HDR_ByNameType,
                                                        &compare_info, restart);
         if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) && 
             (status != ERR_PARAM))
         {
            return(status);
         }
      
         if (first_obj_info.CurrObj.HeaderAddress ==
                                   FDI_SearchInfo.CurrObj.HeaderAddress)
         {
            /* First header is the same as the second.                   */
            /* Header indicates it is a backup but no original was found */
            return(ERR_SYSTEM);
         }
         else
         {
            /* Found orignal, reclaim in place and restore backup */
            /* Reclaim In Place the First Header Object */
            status = RECINPLC_ReclaimObjectInPlace(&first_obj_info, FALSE);
            if (status != ERR_NONE)
            {
               return(status);
            }

            /* Copy the second object to the first object */
            status = FLASH_CopyFlash(FDI_SearchInfo.CurrObj.ObjectAddress,
                              first_obj_info.CurrObj.ObjectAddress, 
                                           first_obj_info.CurrObj.ObjectSize);
            if (status != ERR_NONE)
            {
               return(status);
            }

         }
      } /* End of Backup restoration */
      
      /* Now mark WIP object to Invalid. */
      status = HDR_InvalidateHeader(FDI_SearchInfo.CurrObj.HeaderAddress,
                                    FDI_SearchInfo.HeaderPtr);
      if (status != ERR_NONE)                                                       
      {
         return(status);
      }

      /* must reclaim to cleanup the used reserved page space. */
      status = DAVSRECL_CheckReclaimLevel();

      /* Set Global flag for System State */
      SetSystemState(FDI_SystemState, FDI_ST_RestoreWIP);
   }

#ifdef ENABLE_RECOVER_TESTS
   EVT_TestEvent(EVT_RECOVER_RestoreWriteInProgessObjects_End);
#endif

   if (status == ERR_NO_MORE_ENTRIES)
   {
      status = ERR_NONE;
   }

   return(status);
}   

/*########################################################################*/
/*### Functions for checking if an invalid page object exists                   */
/*########################################################################*/


/*#################################################################
  ### RECOVER_IsInvalidPageObjectFound
  ###
  ### DESCRIPTION:
  ###   This function will scan the header table for an invalid page 
  ###   object.  If one is found, it will return ERR_NONE, otherwise
  ###   will return ERR_NO_MORE_ENTRIES.
  ###
  ### PARAMETERS 
  ###   none.
  ###
  ### RETURNS:
  ###   When this function passes with no errors a value of 0 is
  ###   returned otherwise, it returns a status of type ERR_CODE.
  ###*/
ERR_CODE RECOVER_IsInvalidPageObjectFound(BOOLEAN restart)
{
   HDR_CompareInfo compare_info = Init_HDR_CompareInfo;
   ERR_CODE      status;

   /* must reclaim to cleanup the used reserved page space. */
   status = DAVSRECL_CheckReclaimLevel();
   if (status)
   {
      return status;
   }

   status = ERR_NONE;
   
   /* Scan the entire header table for Invalid page Object */
   HDR_InitSearchInfo((&FDI_SearchInfo), (&FDI_SearchHeader)); 

   status = GetNextHeader(&FDI_SearchInfo, 
                  HDR_ByNextInvalidPageObject, 
                  &compare_info, restart);
                  
   return(status);
}   
#endif /* DIRECT_ACCESS_VOLUME */

⌨️ 快捷键说明

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