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

📄 fdi_int.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 5 页
字号:
                           hw_status =
                              FlashDevWrite(&unit_header_buffer.type_attribute,
                                   block_address +
                                   FIRST_HEADER_OFFSET + (unit_index *
                                   sizeof(UNIT_HEADER) +
                                   offsetof(UNIT_HEADER, type_attribute)),
                                   sizeof(unit_header_buffer.type_attribute));
                           if(hw_status != HW_ERR_NONE)
                           {
                              break;
                           }
                        }

                        if ( new_tbl_buff.entry_status != GRP_VALID)
                        {
                           new_tbl_buff.entry_status = GRP_VALID;
                           hw_status =
                              FlashDevWrite(&new_tbl_buff.entry_status,
                                           new_tbl_addr + (tbl_index *
                                      sizeof(ENTRY_TABLE)) +
                                      offsetof(ENTRY_TABLE, entry_status),
                                      sizeof(new_tbl_buff.entry_status));
                        }
                        break;

                     case HDR_ALLOCATED:
                        if (invalidate_flag == FALSE)
                        {

                           if ((new_tbl_hdr_ptr->type_attribute &
                              ATTRIBUTE_MASK) == ATTR_GRP_TABLE)
                           {
                              if ((status =
                                      ScanEntryTables(&unit_header_buffer,
                                         block_address + FIRST_HEADER_OFFSET +
                                         (unit_index * sizeof(UNIT_HEADER)),
                                         current_index, index,
                                         grp_entry_number)) != ERR_NONE)
                              {
                                 break;
                              }
                              grp_entry_number++;
                           }

                           /*
                            * Mark entry to valid before setting corresponding
                            * instance to valid, here is for DLPR issue and for
                            * packet data validation
                            */
                           if (new_tbl_buff.entry_status != GRP_VALID)
                           {
                              /* mark the table entry GRP_VALID */
                              new_tbl_buff.entry_status = GRP_VALID;
                              hw_status =
                                 FlashDevWrite(&new_tbl_buff.entry_status,
                                           new_tbl_addr + (tbl_index *
                                           sizeof(ENTRY_TABLE)) +
                                           offsetof(ENTRY_TABLE, entry_status),
                                           sizeof(new_tbl_buff.entry_status));
                              if(hw_status != HW_ERR_NONE)
                              {
                                 status = ERR_WRITE;
                                 break;
                              }
                           }
                           /*
                            * Validate the unit header marked
                            * HDR_ALLOCATED
                            */
                           status =
                              WriteUnitHeaderStatus(block_address +
                                 (unit_index * sizeof(UNIT_HEADER)) +
                                 FIRST_HEADER_OFFSET, HDR_VALID,
                                 unit_header_buffer.status,
                                 unit_header_buffer.g_unit_size, 1);
                           break;

                        }

                        /* invalidate_flag == TRUE */
                        else
                        {
                           /* mark the table entry GRP_INVALID */
                           /*
                            * do this in 2 steps to avoid dual power loss
                            * problems
                            */
                           new_tbl_buff.entry_status &= INVALIDATE_ENTRY;
                           hw_status =
                              FlashDevWrite(&new_tbl_buff.entry_status,
                                         new_tbl_addr +
                                         (tbl_index * sizeof(ENTRY_TABLE)) +
                                         offsetof(ENTRY_TABLE, entry_status),
                                         sizeof(new_tbl_buff.entry_status));
                           break;
                        }

                     case HDR_ALLOCATING:
                        /* mark the table entry GRP_INVALID */
                        /*
                         * do this in 2 steps to avoid dual power loss
                         * problems
                         */
                        new_tbl_buff.entry_status &= INVALIDATE_ENTRY;
                        hw_status =
                           FlashDevWrite(&new_tbl_buff.entry_status,
                                         new_tbl_addr +
                                        (tbl_index * sizeof(ENTRY_TABLE)) +
                                        offsetof(ENTRY_TABLE, entry_status),
                                        sizeof(new_tbl_buff.entry_status));

                        break;

                     case HDR_VALID_HDR:
                        if (invalidate_flag == FALSE)
                        {
                           /*
                            * for the first new table entry, whose
                            * corresponding unit is HDR_VALID_HDR,
                            * do not invalidate this entry
                            */
                           invalidate_flag = TRUE;
                           break;
                        }

                        /* invalidate_flag = TRUE */
                        else
                        {

                           /* mark the table entry GRP_INVALID */
                           /*
                            * do this in 2 steps to avoid dual
                            * power loss problems
                            */
                           new_tbl_buff.entry_status &= INVALIDATE_ENTRY;
                           hw_status =
                              FlashDevWrite(&new_tbl_buff.entry_status,
                                        new_tbl_addr +
                                        (tbl_index * sizeof(ENTRY_TABLE)) +
                                        offsetof(ENTRY_TABLE, entry_status),
                                        sizeof(new_tbl_buff.entry_status));

                            break;
                        }
                     default:
                        break;
                  }                 /* ENDSWITCH header.status */

                  if (status != ERR_NONE || hw_status != HW_ERR_NONE)
                  {
                     break;
                  }
               }                    /* ENDIF data_instance == 0 */
            }                       /* ENDIF header matches this seq */
            unit_index++;
         } while ((data_instance != 0) &&
                  (!HDR_STATE(HDR_EMPTY, unit_header_buffer.status)));

         mDEBUG_CHECK_ERRCODE(status)
         mDEBUG_CHECK_ERRCODE(hw_status)

         if(status != ERR_NONE || hw_status != HW_ERR_NONE)
            return ERR_SYSTEM;

         if (data_instance != 0)
         {
            /*
             * This entry instance not found so mark the table
             * entry GRP_INVALID
             */
            new_tbl_buff.entry_status &= INVALIDATE_ENTRY;
            hw_status = FlashDevWrite(&new_tbl_buff.entry_status,
                                      new_tbl_addr +
                                     (tbl_index * sizeof(ENTRY_TABLE)) +
                                      offsetof(ENTRY_TABLE, entry_status),
                                      sizeof(new_tbl_buff.entry_status));

            if (hw_status != HW_ERR_NONE)
            {
               break;
            }
         }
      }                             /* ENDIF status == GRP_ALLOCATING */
      else if ((new_tbl_buff.entry_status == GRP_ALLOCATING) ||
              (INVALID_ENTRY(new_tbl_buff.entry_status)))
      {
         /*
          * This unit instance create not begun, so mark the table entry
          * GRP_INVALID
          */
         new_tbl_buff.entry_status &= INVALIDATE_ENTRY;
         hw_status =
                   FlashDevWrite(&new_tbl_buff.entry_status,
                                 new_tbl_addr +
                                (tbl_index * sizeof(ENTRY_TABLE)) +
                                 offsetof(ENTRY_TABLE, entry_status),
                                 sizeof(new_tbl_buff.entry_status));
         if (hw_status != HW_ERR_NONE)
         {
            break;
         }
      }                             /* ENDIF status == GRP_ALLOCATING */

      /* Entry Status is in an intermediate state */
      else if ((entry_state_mask =
               ENTRY_INTERMEDIATE(new_tbl_buff.entry_status)) != 0)
      {
         #ifdef TEST_MSGS
         logMsg("Intermediate entry status found in ScanEntryTables(), 0x%X\n",
            new_tbl_buff.entry_status,0,0,0,0,0);
         #endif

         /* do not increment the entry count so because we need to fix this
            intermediate state */
         bump_seq_addr = FALSE;
         /* Determine mask needed to push out of intermediate state */
         new_tbl_buff.entry_status = ENTRY_FIX_INTERMEDIATE(entry_state_mask,
                                     new_tbl_buff.entry_status);
         hw_status = FlashDevWrite(&new_tbl_buff.entry_status,
                                   new_tbl_addr +
                                   (tbl_index * sizeof(ENTRY_TABLE)) +
                                    offsetof(ENTRY_TABLE, entry_status),
                                   sizeof(new_tbl_buff.entry_status));
         if (hw_status != HW_ERR_NONE)
         {
            break;
         }
      }

      /* Some header corruption occurred */
      else
      {
         bump_seq_addr = TRUE;
#ifdef TESTING
         return ERR_FORMAT;
#endif
      }

      if (bump_seq_addr == TRUE)
      {
         /* skip to next table entry. */
         tbl_index++;
         ENTRY_TABLE_size -= sizeof(ENTRY_TABLE);
      }
   } while (ENTRY_TABLE_size >= sizeof(ENTRY_TABLE));

   if (status == ERR_NONE && hw_status == HW_ERR_NONE)
   {
      if(invalidate_flag == TRUE)
      {
      
/* E.5.1.820 Begin */
         /*
          * the first new table entry with status GRP_VALID_ENTRY
          * will be marked GRP_INVALID
          */
          
         hw_status = FlashDevRead((BYTE_PTR) & new_tbl_buff,
                                  first_seq_tbl_entry_addr,
                                  sizeof(ENTRY_TABLE));
         if (hw_status != HW_ERR_NONE)
         {
            return ERR_READ;
         }
          
         new_tbl_buff.entry_status &= INVALIDATE_ENTRY;
         hw_status =
            FlashDevWrite(&new_tbl_buff.entry_status,
                          first_seq_tbl_entry_addr +
                          offsetof(ENTRY_TABLE, entry_status),
                          sizeof(new_tbl_buff.entry_status));
      }
/* E.5.1.820 End */
   }

   mDEBUG_CHECK_ERRCODE(status)
   mDEBUG_CHECK_ERRCODE(hw_status)

   if(status != ERR_NONE || hw_status != HW_ERR_NONE)
   {
      return ERR_SYSTEM;
   }
   else
   {
      return ERR_NONE;
   }
}                                      /* END ScanEntryTables */

#endif                                 /* INCLUDE_FRAGMENTED_DATA */

/*
 *############################################################################
 *### SearchForIdentifier
 *###
 *### DESCRIPTION:
 *### If the unit_header_status is allocated, scans the entire media
 *### to see if an valid identifier of same type exists, and returns its
 *### address in if it exists, or a DWORDMAX if no valid sequence table unit
 *### header exists. If the unit_header_status is allocating, scans the entire
 *### media to invalidate all the unit headers of matching identifier that are
 *### not marked valid. If the unit_header_status is invalidating, scans the
 *### entire media to invalidate all the unit headers of matching identifier
 *### and type that are not marked invalid except the header that is marked
 *### invalidating. If more than one header is found in invalidating state,
 *### DWORDMAX is returned indicating a format error. Otherwise, the address
 *### of the header that is marked invalidating is returned.
 *###
 *### PARAMETERS:
 *###    IN:
 *###         UNIT_HEADER *new_header_pointer
 *###         DWORD_PTR   invalidating_hdr_addr
 *###
 *###    OUT:
 *###        DWORD: address of the previous valid unit header
 *###
 *### RETURNS:
 *###        ERR_CODE: error code
 *###
 */
/* E.5.0.652 Begin */
ERR_CODE
SearchForIdentifier(UNIT_HEADER * new_header_pointer,
                    DWORD_PTR invalidating_hdr_addr,
/* E.5.3.877 Start */
                    DWORD skip_addr,
/* E.5.3.877 End */
                    WORD current_index,
                    WORD index,
                    BYTE flag,
                    BYTE trunc_flag)
/* E.5.0.652 End */
{
   UNIT_HEADER unit_header_buffer;        /* buffer to store unit header info */
   DWORD       block_address;
   WORD        unit_index;
   WORD        block_index;
   WORD        state_msk;                 /* mask to fix intermediate state */
   BYTE        found = FALSE;
   ERR_CODE    status = ERR_NONE;
   HW_ERROR    hw_status = HW_ERR_NONE;

   *invalidating_hdr_addr = DWORDMAX;

   for (block_index = 0; block_index < MAX_DATA_BLOCKS; block_index++)
   {

      /* If it is called from the background, take the block table sem. */
      if (flag == 0)
      {
         SEM_MTX_WAIT(SEM_BlockTable);
      }

⌨️ 快捷键说明

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