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

📄 davrecl.c

📁 Flash file system
💻 C
📖 第 1 页 / 共 5 页
字号:
            if(status)
            {
               return status;
            }

            /* Process all the valid OTT table entries one by one and
            call the call back function API, provided by the user 
            application. */
            status = OTTTBL_ReadTable(ReclaimState.OTTTblBaseAddr, 
               ReclaimState.CurrentObject2Modify, 
               &ReclaimState.OTTTblEntry, restart); 
            if(status)
            {
               return status; 
            }

            /* Do the reallocation. */
            do
            {
               if(OTTTBL_IsOTTEntryValid(ReclaimState.OTTTblEntry.status))
               {

                  if(restart)
                  {
                     /* Check if there is a WIP & Backup Complete object */
                     HDR_InitSearchInfo((&BC_SearchInfo), (&SearchHeader));

                     status = GetNextHeader(&BC_SearchInfo, 
                                            HDR_ByNextWriteInProgressObject, 
                                            &compare_info, restart);
                     if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) && 
                     (status != ERR_PARAM))
                     {
                        return(status);
                     }

                     if(!status)
                     {
                        /* Found a WIP oject, now check if it is a Backup Complete object */
                        if(HDR_IsBackupComplete((BC_SearchInfo.HeaderPtr->Attr16)))
                        {
                           /* Found a WIP & Backup Complete object */
                           WIP_BC_obj_found = TRUE;            
                        }
                        else
                        {
                           /* Found a WIP & Backup not Complete object */
                           WIP_obj_found = TRUE;   
                        }         
                     }
                     /* Check if there is a invalid backup object */
                     else 
                     {
                        HDR_InitSearchInfo((&BC_SearchInfo), (&SearchHeader));
                        
                        do
                        {
                           invalid_backup_found = FALSE;
                           status = GetNextHeader(&BC_SearchInfo, 
                                                  HDR_ByNextInvalidPageObject, 
                                                  &compare_info, restart);
                           if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) && 
                               (status != ERR_PARAM))
                           {
                              return(status);
                           }

                           if(!status)
                           {
                              /* Check if this is the backup object */
                              if(BC_SearchInfo.HeaderPtr->ObjectType == 
                                    OTT_SearchInfo.HeaderPtr->ObjectType)
                              {
                                 /* Need to read full header for this type of search */
                                 status = HDR_ReadFullHeader(BC_SearchInfo.CurrObj.HeaderAddress,
                                                    BC_SearchInfo.HeaderPtr, restart); 
                                 if(status)
                                 {
                                     return status;
                                 }                   
                                 if ((BC_SearchInfo.HeaderPtr->NameSize == 
                                        OTT_SearchInfo.HeaderPtr->NameSize))
                                 {
                                    invalid_backup_found = TRUE;
                                    for (name_index = 0; 
                                         name_index < OTT_SearchInfo.HeaderPtr->NameSize;           
                                         name_index++)
                                    {
                                       if (BC_SearchInfo.HeaderPtr->Name[name_index] != 
                                              OTT_SearchInfo.HeaderPtr->Name[name_index])
                                       {
                                          invalid_backup_found = FALSE;
                                          break;
                                       }
                                    
                                    }
                                 }
                                 else
                                 {
                                    invalid_backup_found = FALSE;
                                 }

                              }
                           }
                        } while ((status != ERR_NO_MORE_ENTRIES) && 
                                 (invalid_backup_found == FALSE));
                        
                     }                     
                  }

                  if (!(invalid_backup_found)) /* If the backup object is not invalid */
                  {

                     if(!OTTTBL_IsObjectModified(ReclaimState.OTTTblEntry.status))
                     {

                        /* If power is off during the object is WIP and completed backup,     */
                        /* reclaim in place original object space and copy the backup object */
                        /* back to the original object space. */   
                        if(WIP_BC_obj_found) /* If there is a WIP & Backup Complete object */
                        {
                           if(restart) /* For power loss recovery process only */
                           {
                              /* Read the full header infomation of the WIP & Backup Complete object */
                              status = HDR_ReadFullHeader(BC_SearchInfo.CurrObj.HeaderAddress, 
                                                 BC_SearchInfo.HeaderPtr, restart);
                              if(status)
                              {
                                  return status;
                              }
                              compare_info.NamePtr      = 
                                 (HDR_NamePtr)(BC_SearchInfo.HeaderPtr->Name);
                              compare_info.NameSize     = BC_SearchInfo.HeaderPtr->NameSize;
                              compare_info.CompareValue = BC_SearchInfo.HeaderPtr->ObjectType;

                              /* Check if there is a valid original object */
                              HDR_InitSearchInfo((&old_obj_SearchInfo), (&old_obj_SearchHeader));
                              status = GetNextHeader(&old_obj_SearchInfo, HDR_ByNameType,
                                                     &compare_info, restart);
                              if ((status != ERR_NONE) && (status != ERR_NO_MORE_ENTRIES) && 
                                  (status != ERR_PARAM))
                              {
                                 return(status);
                              }

                              if (old_obj_SearchInfo.CurrObj.HeaderAddress ==
                                  BC_SearchInfo.CurrObj.HeaderAddress)
                              {
                                 /* Original header is the same as the backup header; */
                                 /* that is, a backup but no original object was found */
                                 return(ERR_SYSTEM);
                              }
                              else
                              {
                                 /* Found original object, reclaim in place original object space */
                                 status = RECINPLC_ReclaimObjectInPlace(&old_obj_SearchInfo, FALSE);
                                 if (status != ERR_NONE)
                                 {
                                    return(status);
                                 }

                                 /* Copy the backup object back to the original object space */
                                 status = FLASH_CopyFlash(BC_SearchInfo.CurrObj.ObjectAddress,
                                                          old_obj_SearchInfo.CurrObj.ObjectAddress, 
                                                          old_obj_SearchInfo.CurrObj.ObjectSize);
                                 if (status != ERR_NONE)
                                 {
                                    return(status);
                                 }
                              }      
                           }
                        }

                        /* Call the call back function here. */
                        modify_object_status = 
                                FDI_ModifyObject((BYTE_PTR)current_dest_addr, 
                                            ReclaimState.OTTTblEntry.objsize, 
                                                  (BYTE_PTR)current_src_addr,
                                                 (VOID_PTR_PTR)(&buffer_ptr));

                        /* If the return value is TRUE, then do object reallocate.
                        If the return value is FALSE, go to next state. */
                        if(modify_object_status == TRUE)                         
                        {
                           /* If There is no WIP & Backup Complete object */ 
                           if(!WIP_BC_obj_found) 
                           {

                              /* If There is no WIP backup object */ 
                              if(!WIP_obj_found) 
                              {

                                 /* Copy the obj_info into old_obj_info. */
                                 MemoryMove((BYTE_PTR) &old_obj_info, 
                                            (BYTE_PTR) &obj_info, 
                                            sizeof(FDI_ObjectInfo));

                                 FDI_ReAllocateOverrideFlag = TRUE;
                                 
                                 /* Save the counter for number of page objects in flash */
                                 save_page_object_counter = FDI_PageObjectCounter;

                                 status = AllocateFlash(&obj_info);
                                 
                                 /* Restore the counter for number of page objects in flash */
                                 FDI_PageObjectCounter = save_page_object_counter;

                                 FDI_ReAllocateOverrideFlag = FALSE;
                                 if(status)
                                 {
                                    return status;
                                 }
                              }

                              compare_info.CompareValue = obj_info.ObjectType;
                              compare_info.NamePtr = (HDR_NamePtr)obj_info.Name;
                              compare_info.NameSize = obj_info.NameSize;

                              /* Re-Search for the first one just in case reclaim  */
                              /*  occurred when this object was allocated.         */
                              OTT_SearchInfo.CurrObj.HeaderAddress = 0;
                              OTT_SearchInfo.CurrObj.ConfigEntry.Offset = 0;
                              OTT_SearchInfo.CurrObj.ConfigEntry.Status = 0;

                              status = GetNextHeader(&OTT_SearchInfo, HDR_ByNameType, &compare_info, restart);
                              if(status != ERR_NONE)
                              {
                                 if(status == ERR_NO_MORE_ENTRIES)
                                 {
                                    status = ERR_SYSTEM;
                                 }
                                 FDI_APIUnlock();
                                 return status;
                              }

                              old_obj_info.ObjectAddress = OTT_SearchInfo.CurrObj.ObjectAddress;

                              /* Calculate the address of the new object  */
                              /*  (start search from the last object).    */

                              status = GetNextHeader(&OTT_SearchInfo, HDR_ByNameType, &compare_info, restart);
                              if(status)
                              {
                                 if(status == ERR_NO_MORE_ENTRIES)
                                 {
                                    status = ERR_SYSTEM;
                                 }
                                 FDI_APIUnlock();
                                 return status;
                              }
                              obj_info.ObjectAddress = OTT_SearchInfo.CurrObj.ObjectAddress;

                              /* Copy the old object to the new object, creating backup */
                              status = FLASH_CopyFlash(old_obj_info.ObjectAddress, 
                                                       obj_info.ObjectAddress, 
                                                       PAGE_TO_BYTES(obj_info.ObjectSize));
                              if(status)
                              {
                                 return(status);
                              }

                              /* Mark attributes to Backup Complete */
                              OTT_SearchInfo.HeaderPtr->Attr16 = 
                                 HDR_SetBackupCompleteAttr(OTT_SearchInfo.HeaderPtr->Attr16, 
                                                           HDR_HA_BackupComplete);
                              /* Write new attr to header in flash */
                              status = FLASH_WriteBuffer(OTT_SearchInfo.CurrObj.HeaderAddress + HDR_Attrib16Offset, 
                                                         (MemBufferPtr)&(OTT_SearchInfo.HeaderPtr->Attr16), 
                                                         HDR_Attrib16Size );
                              if(status)
                              {
                                 return(status);
                              }

                           }

                           /* Must re-read the original object             */
                           /*  May of had reclaim for level 0 or 1.        */
                           /*  Also re-finds original for error check above */
                           OTT_SearchInfo.CurrObj.HeaderAddress = 0;
                           OTT_SearchInfo.CurrObj.ConfigEntry.Status = 0;
                           OTT_SearchInfo.CurrObj.ConfigEntry.Offset = 0;

                           status = GetNextHeader(&OTT_SearchInfo, HDR_ByNameType, &compare_info, restart);
                           if(status != ERR_NONE)
                           {
                              if(status == ERR_NO_MORE_ENTRIES)
                              {
                                 /* At this point the original header has already been found once */
                                 status = ERR_SYSTEM;
                              }

                              FDI_APIUnlock();
                              return status;
                           }

                           /* The object should now be allocated and          */
                           /* regardless of any errors, we should lock        */
                           /* allocates out.                                  */
                           /* A WIP object exists, do not allow allocation or */
                           /* reallocation until the object is complete.      */
                           FDI_LockoutObjectAllocation = TRUE;

                           /* Load obj_info with current location of orignal object */
                           HDR_SearchInfo2ObjectInfo(&obj_info, &OTT_SearchInfo);


                           /* Add PLR State Recording Support */
                           RECOVER_MarkDatabaseBusy();

                           /* Erase the space associated with the old object. */
                           status = RECINPLC_ReclaimObjectInPlace(&OTT_SearchInfo, FALSE);
                           if(status)
                           {
                              return status;
                           }

⌨️ 快捷键说明

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