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

📄 fdi_bkgd.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 5 页
字号:
                  logMsg("Reclaim ENABLED before, needed %d, free %d, "
                         "spare %d\n", needed_space, (int) total_free,
                         FDI_SpareBlock, 0, 0, 0);
#endif

                  /* IF there is not THEN */
                  if (total_free < FDI_THRESHOLD)
                  {
                     SEM_WAIT(RECL_Done);
                     total_free = BKGD_GetTotalSpace(FREE_UNITS);
                     total_dirty = BKGD_GetTotalSpace(DIRTY_UNITS);

                     /*
                      * If the total_dirty is zero and nothing to be reclaimed,
                      * return  flash full error.
                      */
/* E.5.1.776 Begin */
                     if ((total_free == prev_free) &&
                         (total_dirty == 0))
/* E.5.1.776 End */
                     {
#ifdef TEST_MSGS
                        logMsg("FDI_THRESHOLD free = %d, thres = %d\n",
                               (int) total_free, FDI_THRESHOLD, 0, 0, 0, 0);
#endif
                        FDI_HandleError(HW_ERR_FLASH_FULL);
                        BKGD_TaskId = 0;
#ifdef TEST_MSGS
                        logMsg("BKGD Task Bailed!\n", 0, 0, 0, 0, 0, 0);
#endif
                        return;
                     }
                  } 
                  else if (status == HW_ERR_FLASH_FULL)
                  {
#ifdef TEST_MSGS
                     logMsg("Pending on RECL_Done, needed %d, free %d, dirty %d\n",
                            needed_space, (int) total_free, (int) total_dirty, 0,
                            0, 0);
#endif
                     SEM_WAIT(RECL_Done);
                     total_free = BKGD_GetTotalSpace(FREE_UNITS);
                     total_dirty = BKGD_GetTotalSpace(DIRTY_UNITS);

                     /*
                      * If the total_dirty is zero and nothing to be reclaimed,
                      * return  flash full error.
                      */
/* E.5.1.776 Begin */
                     if ((total_free == prev_free) &&
                         (total_dirty == 0))
/* E.5.1.776 End */
                     {
#ifdef TEST_MSGS
                        logMsg("ERR_FLASH_FULL free = %d\n", (int) total_free, 0,
                               0, 0, 0, 0);
#endif
#if (FREE_SPACE_FUNCTIONS == TRUE)
                        status = BKGD_CheckForSpace(cmd_ptr, data_size,
                                                    FALSE,NORMAL_CALCCHK);
#else   /* !FREE_SPACE_FUNCTIONS */
                        status = BKGD_CheckForSpace(cmd_ptr, data_size, FALSE);
#endif   /* FREE_SPACE_FUNCTIONS */
                        FDI_HandleError(HW_ERR_FLASH_FULL);
                        BKGD_TaskId = 0;
#ifdef TEST_MSGS
                        logMsg("BKGD Task Bailed!\n", 0, 0, 0, 0, 0, 0);
#endif
                        return;
                     }
                     status = HW_ERR_NONE;
                  } 
                  else if (status == HW_ERR_NONE)
                  {
                     break;
                  }
                  total_free = BKGD_GetTotalSpace(FREE_UNITS);

                  prev_free = total_free;
#if (FREE_SPACE_FUNCTIONS == TRUE)
                  status = BKGD_CheckForSpace(cmd_ptr, data_size,
                                              FALSE,NORMAL_CALCCHK);
#else   /* !FREE_SPACE_FUNCTIONS */
                  status = BKGD_CheckForSpace(cmd_ptr, data_size, FALSE);
#endif   /* FREE_SPACE_FUNCTIONS */

               }                          /* ENDDO WHILE free <SYSTEM_THRESHOLD */
            }                             /* ENDELSE NOT data streaming */

#else                                  /* !DATA_STREAM */
            prev_free = 0;
            while ((total_free < SYSTEM_THRESHOLD) ||
                   (status == HW_ERR_FLASH_FULL))
            {
#if (PACKET_DATA == TRUE)              /* PACKET_DATA */
               FDI_WAIT_FORRECLM_DONE;    /* for reclaim solution */
#endif /* PACKET_DATA */
               SEM_TRY_WAIT(RECL_Done);   /* reset RECL_Done semaphore */
#if (PACKET_DATA == TRUE)              /* PACKET_DATA */
               FDI_RESET_RECLMSTATE;      /* for reclaim solution */
#endif /* PACKET_DATA */
               SEM_POST(RECL_Enable);     /* enable reclaim to begin */
#ifdef TEST_MSGS
               logMsg("Reclaim ENABLED before, needed %d, free %d, "
                      "spare %d\n", needed_space, (int) total_free,
                      FDI_SpareBlock, 0, 0, 0);
#endif

               /* IF there is not THEN */
               if (total_free < FDI_THRESHOLD)
               {
                  SEM_WAIT(RECL_Done);
                  total_free = BKGD_GetTotalSpace(FREE_UNITS);
                  total_dirty = BKGD_GetTotalSpace(DIRTY_UNITS);

                  /*
                   * If the total_dirty is zero and nothing to be reclaimed,
                   * return  flash full error.
                   */
/* E.5.1.776 Begin */
                  if ((total_free == prev_free) &&
                      (total_dirty == 0))
/* E.5.1.776 End */
                  {
#ifdef TEST_MSGS
                     logMsg("FDI_THRESHOLD free = %d, thres = %d\n",
                            (int) total_free, FDI_THRESHOLD, 0, 0, 0, 0);
#endif
                     FDI_HandleError(HW_ERR_FLASH_FULL);
                     BKGD_TaskId = 0;
#ifdef TEST_MSGS
                     logMsg("BKGD Task Bailed!\n", 0, 0, 0, 0, 0, 0);
#endif
                     return;
                  }
               } 
               else if (status == HW_ERR_FLASH_FULL)
               {
#ifdef TEST_MSGS
                  logMsg("Pending on RECL_Done, needed %d, free %d, dirty %d\n",
                         needed_space, (int) total_free, (int) total_dirty, 0, 0,
                         0);
#endif
                  SEM_WAIT(RECL_Done);
                  total_free = BKGD_GetTotalSpace(FREE_UNITS);
                  total_dirty = BKGD_GetTotalSpace(DIRTY_UNITS);

                  /*
                   * If the total_dirty is zero and nothing to be reclaimed,
                   * return  flash full error.
                   */
/* E.5.1.776 Begin */
                  if ((total_free == prev_free) &&
                      (total_dirty == 0))
/* E.5.1.776 End */
                  {
#ifdef TEST_MSGS
                     logMsg("ERR_FLASH_FULL free = %d\n", (int) total_free, 0, 0,
                            0, 0, 0);
#endif
                     FDI_HandleError(HW_ERR_FLASH_FULL);
                     BKGD_TaskId = 0;
#ifdef TEST_MSGS
                     logMsg("BKGD Task Bailed!\n", 0, 0, 0, 0, 0, 0);
#endif
                     return;
                  }
                  status = HW_ERR_NONE;
               } 
               else if (status == HW_ERR_NONE)
               {
                  break;
               }
               total_free = BKGD_GetTotalSpace(FREE_UNITS);

               prev_free = total_free;
#if( FREE_SPACE_FUNCTIONS == TRUE)
               status = BKGD_CheckForSpace(cmd_ptr, data_size,
                                           FALSE,NORMAL_CALCCHK);
#else    /* !FREE_SPACE_FUNCTIONS */
               status = BKGD_CheckForSpace(cmd_ptr, data_size, FALSE);
#endif   /* FREE_SPACE_FUNCTIONS */

            }                       /* ENDDO WHILE free <SYSTEM_THRESHOLD */
#endif                              /* !DATA_STREAM */
         } 
         /* 
          * For truncate, at most we only need to create a new group table and sequence table, 
          * here we check if there is enough free space for new group table and sequence table  
          */
         else if ( cmd_ptr->sub_command == WRITE_TRUNCATE )
         {
/* E.5.5.993 Start */
             cmd_ptr->gran_needed.frag_needed = MAX_NUM_UNITS_PER_FRAG;
             cmd_ptr->gran_needed.seq_needed = 1;
             cmd_ptr->gran_needed.grp_needed = TO_SIZE(TO_SIZE(cmd_ptr->data_offset, 
                                      UNIT_GRANULARITY), FDI_ONEGRANGRP_MAX_FRAGS);
/* E.5.5.993 End */
             prev_free = 0;
             /*
              * simulate write sub functions to
              * make sure there is enough free space
              */
             status=BKGD_CheckFreeSpace(cmd_ptr);

             /* Reclaim untill there is enought free space to write */
             while ( status != HW_ERR_NONE )
             {
/* E.5.5.992 Start */
                SEM_POST(RECL_Enable);     /* enable reclaim to begin */
/* E.5.5.992 End */
                SEM_WAIT(RECL_Done);
                total_free = BKGD_GetTotalSpace(FREE_UNITS);
                total_dirty = BKGD_GetTotalSpace(DIRTY_UNITS);

                /* Check again thereis enough free space */
                status=BKGD_CheckFreeSpace(cmd_ptr);
                if ( status == HW_ERR_NONE )
                {
                   break;
                }

                /*
                 * If the total_dirty is zero and nothing
                 * to be reclaimed, return  flash full error.
                 */
                if ((total_free == prev_free) &&
                    (total_dirty == 0))
                {
                   FDI_HandleError(HW_ERR_FLASH_FULL);
                   BKGD_TaskId = 0;
                   return;
                }
                prev_free = total_free;
#if (PACKET_DATA == TRUE)              /* PACKET_DATA */
                if ( FDI_Pckt.ID != WORDMAX )
                {
                   FDI_RESET_RECLMSTATE;      /* for reclaim solution */
                }
#endif  /* PACKET_DATA */
/* E.5.5.992 Start */
                /* SEM_POST(RECL_Enable); */     /* enable reclaim to begin */
/* E.5.5.992 End */
             }
         }
         else
         {
            status = HW_ERR_NONE;
         }

         if ((status == HW_ERR_NONE) || (status == HW_ERR_SPACE))
         {
#ifdef TEST_MSGS
#if (DATA_STREAM == FALSE)
            logMsg("WriteData siz %d fre %d dty %d id %d off %d\n",
                   data_size, (int) total_free, (int) total_dirty,
                   (int) cmd_ptr->identifier, (int) cmd_ptr->data_offset, 0);
#else
            logMsg("WriteData siz %d fre %d id %d off %d\n",
                   data_size, (int) total_free, (int) cmd_ptr->identifier,
                   (int) cmd_ptr->data_offset, 0, 0);
#endif
#endif

            /* call WriteData to put data into FDI system */
            /* Take the SEM_AccumSize_Mutex semaphore so that there is no foreground access
               to dirty and free space between the time that the logical block table free
               and dirty space is updated and the time that the item is removed from the
               queue, which is when the accum_dirty and accum_free are updated. This will
               ensure that the dirty space is not counted both in the logical block table
               and the accum_dirty field.
            */
            SEM_MTX_WAIT(SEM_AccumSize_Mutex);
            status = WriteData(data_ptr, cmd_ptr->data_offset,
                               cmd_ptr->identifier, data_size, cmd_ptr->type,
                               cmd_ptr->sub_command);
            if (status != HW_ERR_NONE)
            {
               FDI_HandleError(status);

               if ((status != HW_ERR_FLASH_FULL) && (status != HW_ERR_SPACE))
               {
#ifdef TEST_MSGS
                  logMsg("*Write Failed err %d id %d type %d size %d off %d\n",
                         (int) status, cmd_ptr->identifier, cmd_ptr->type,
                         data_size, (int) cmd_ptr->data_offset, 0);
#endif
                  break;               /* must be a hardware error */
               } 
               else
               {
#ifdef TEST_MSGS
#if (DATA_STREAM == FALSE)
                  if (status == HW_ERR_FLASH_FULL)
                     logMsg("FLASH FULL, need %d, free %d, dirty %d,"
                            " id %d, type %d\n", needed_space,
                            (int) total_free, (int) total_dirty,
                            cmd_ptr->identifier, cmd_ptr->type, 0);
                  else
                     logMsg("FLASH SPACE, need %d, "
                            "free %d, dirty %d, id %d, type %d\n",
                            needed_space, (int) total_free,
                            (int) total_dirty, cmd_ptr->identifier,
                            cmd_ptr->type, 0);
#else
                  if (status == HW_ERR_FLASH_FULL)
                     logMsg("FLASH FULL, need %d, free %d id %d, type %d\n",
                            needed_space, (int) total_free,
                            cmd_ptr->identifier, cmd_ptr->type, 0, 0);
                  else
                     logMsg("FLASH SPACE, need %d, free %d, id %d, type %d\n",
                            needed_space, (int) total_free,
                            cmd_ptr->identifier, cmd_ptr->type, 0, 0);
#endif
#endif
                  if (status == HW_ERR_FLASH_FULL)
                  {
                     break;
                  }
                  status = HW_ERR_NONE;
               }
            }

            if ((total_free = BKGD_GetTotalSpace(FREE_UNITS)) <
                SYSTEM_THRESHOLD)
            {
#if (PACKET_DATA == TRUE)                 /* PACKET_DATA */
               if ( FDI_Pckt.ID != WORDMAX )
               {
                  FDI_WAIT_FORRECLM_DONE;    /* for reclaim solution */
               }
#endif /* PACKET_DATA */
#if (PACKET_DATA == TRUE)                 /* PACKET_DATA */
               if ( FDI_Pckt.ID != WORDMAX )
               {
                  FDI_RESET_RECLMSTATE;      /* for reclaim solution */
               }
#endif /* PACKET_DATA */
               SEM_POST(RECL_Enable);  /* enable reclaim to begin */
#ifdef TEST_MSGS
               logMsg("Reclaim ENABLED after, need %d, free %d, spare %d\n",
                      needed_space, (int) total_free, FDI_SpareBlock, 0, 0, 0);
#endif
            }

         }                             /* ENDIF status == HW_ERR_NONE */
      }                                /* ENDIF NOT WRITE_DELETE */
      /* ELSE this is WRITE_DELETE access sub_command */
      else
      {
   

⌨️ 快捷键说明

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