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

📄 fdi_int.c

📁 FDI Intel开发的FLASH文件系统,功能很强大
💻 C
📖 第 1 页 / 共 5 页
字号:
            {
               continue;
            }
            /* Fillup the last_data_found structure to be returned. */
            FDI_GetDataFound.identifier = (IDTYPE) index;
            FDI_GetDataFound.type_attribute = BYTEMASK(type, BYTEMAX);
         }

         /* unlock the global_sem_cntrl_mutex. */
         SEM_MTX_POST(SEM_LookupTable);
         return ERR_NONE;
      }
      if (command == GET_MATCHED)
      {
          /* if file is being deleted by background, return Write In Progress
           * error. Only do this on a GET_MATCHED request, otherwise return
           * the next available ID */
         if( TEST_LOOKUP_TABLE_DELETE_PENDING(type,index) )
         {
            SEM_MTX_POST(SEM_LookupTable);
            return ERR_WIP;
         }
         break;
      }
   }                                   /* end of for */

   /* unlock the global_sem_cntrl_mutex. */
   SEM_MTX_POST(SEM_LookupTable);

   return ERR_NOTEXISTS;
}                                      /* END DataFind */


/*
 *############################################################################
 *### GetDataSize
 *###
 *### DESCRIPTION:
 *### Gets the total data size of data in the media. If the priority is
 *### BYTEMAX, then the full queue is scanned for a matching type and
 *### identifier.
 *###
 *### PARAMETERS:
 *###    IN:
 *###       WORD_PTR: data_size_ptr
 *###       IDTYPE: identifier
 *###       BYTE: type
 *###
 *###    OUT:
 *###        *data_size_ptr : total data size
 *###
 *### RETURNS:
 *###        ERR_NONE   ERR_NOTEXISTS
 *###
 */

/* Gets the total data size. */
ERR_CODE
GetDataSize(DWORD_PTR data_size_ptr,
            IDTYPE identifier,
            BYTE type,
            BYTE priority)
{

#if (INCLUDE_FRAGMENTED_DATA == TRUE)
   OPEN_PARAM local_read_info;
#endif
   UNIT_HEADER unit_header_buffer;
   COMMAND *command_ptr = NULL;
   DWORD block_address;
   DWORD unit_address;
   DWORD header_offset;
   WORD q_size = 0;
   WORD index;
   BYTE found = 0;
   BYTE p_index;
   BYTE num_instances;
   /* E.5.0.738 start */
   BYTE mof_index =0;  /*index into FDI_OpenStream, MOF*/
   /* E.5.0.738 end */
   Q_ERROR q_status;
   HW_ERROR hw_status;

   *data_size_ptr = 0;
   /*
    * Peek into the queue to do the following: 1. if an append is pending and
    * if so, add up the size. 2. if a delete is pending reset the size to 0.
    */
   if (priority == BYTEMAX)
   {
      priority = FDI_MIN_PRIORITY;
      found = SCAN_FULL_Q;
   }

   for (p_index = priority; p_index <= FDI_MAX_PRIORITY; p_index++)
   {

      q_status = Q_ERR_NONE;
      command_ptr = NULL;

      while (q_status == Q_ERR_NONE)
      {

         q_status = Q_Peek(FDI_QueueIdentifier, (void **) &command_ptr,
                           &q_size, p_index);

         if (q_status != Q_ERR_NONE)
            break;
         /*
          * If a append of matching id, and type is pending, add up the
          * data_size
          */
         if ((command_ptr->identifier == identifier) &&
             (command_ptr->type == type))
         {
            if ((command_ptr->sub_command == WRITE_APPEND) ||
#if (PACKET_DATA == TRUE)
                (command_ptr->sub_command == WRITE_RSRVPCKT) ||
#endif /* PACKET_DATA */
                (command_ptr->sub_command == WRITE_RESERVED))
            {

               *data_size_ptr =
                ((q_size - sizeof(COMMAND)) + command_ptr->data_offset);
               /*
                * If this is the 1st append (i.e. create) then check if it can
                * classify as a multi-instance
                */
               if (command_ptr->data_offset == 0)
               {
                  /*
                   * Calculate how many instances of this data parameter could
                   * fit in a multi-instance unit.
                   */
                  num_instances = INSTANCES(TO_BYTES(TO_SIZE(*data_size_ptr,
                     UNIT_GRANULARITY)), *data_size_ptr);
                  /* if ((num_instances % 2) != 0) num_instances--; */
                  /*
                   * If the parameter is too large to be a multi-instance then
                   * round the size up to the nearest granularity
                   */
                  if (num_instances < MIN_INSTANCES)
                  {
                     *data_size_ptr = TO_BYTES(TO_SIZE(*data_size_ptr,
                        UNIT_GRANULARITY));
                  }
               }
               /*
                * Not the 1st append, thus it won't become a multi-instance
                */
               else
               {
                  /* Round the size up to the nearest granularity */
                  *data_size_ptr = TO_BYTES(TO_SIZE(*data_size_ptr,
                     UNIT_GRANULARITY));
               }

               found = APPEND_IN_Q;

            }
            else if (command_ptr->sub_command == WRITE_TRUNCATE)
            {

               *data_size_ptr = command_ptr->data_offset;

                  /* Round the size up to the nearest granularity */
               *data_size_ptr = TO_BYTES(TO_SIZE(*data_size_ptr,
                  UNIT_GRANULARITY));

               found = APPEND_IN_Q;
            }
            /*
             * If a delete of matching id, and type is pending set the flag to
             * true
             */
            else if (command_ptr->sub_command == WRITE_DELETE)
            {
               *data_size_ptr = 0;
               found = DELETE_IN_Q;
            }
            else
               found = REPLACE_IN_Q;
         }
      }
      if (((found & FOUND_IN_Q_MASK) != 0) || (found == NONE_IN_Q))
         break;
   }

   if ((*data_size_ptr != 0) || (found == DELETE_IN_Q))
      return ERR_NONE;


   SEM_MTX_WAIT(SEM_LookupTable);
   
/* E.5.0.629 Begin */
   /* Check if this data is opend, if yes, we could use the FDI_OpenTotalSize */
   mof_index = (BYTE)LOOKUP_TABLE_OSFIELD(type,identifier);

/* E.5.0.656 Begin */
   SEM_MTX_POST(SEM_LookupTable);
/* E.5.0.656 End */

   /*
    * IF this identifier is using the FDI_OpenParam structure
    * THEN get the data's total size from FDI_OpenTotalSize
    */
   if ((BYTE)mof_index != BYTEMAX)
   {
      SEM_MTX_WAIT(SEM_TotalSize);
      *data_size_ptr = FDI_OpenTotalSize[(BYTE)mof_index];
      SEM_MTX_POST(SEM_TotalSize);

/* E.5.0.656 Begin */
/*            SEM_MTX_POST(SEM_LookupTable); */
/* E.5.0.656 End */
      return ERR_NONE;
   }
/* E.5.0.629 End */

   /*
    * Get the physical block address and the header offset from the
    * FDI_DataLookupTable.
    */
   hw_status = LookupToHeader(&block_address, &unit_address,
                              &header_offset,
                              &unit_header_buffer, & index,
                              identifier, type);


   if (hw_status == HW_ERR_NONE)
   {
      /*
       * Calculate the address of the unit that the unit header points to, and
       * read the unit header information into a buffer.
       */
      if (NIBBLE_LOW(unit_header_buffer.type_attribute) ==
          ATTR_SINGL_INST)
      {
         /*
          * If the data attribute is single instance unit, return the unit
          * size in bytes as the total data size.
          */
         *data_size_ptr = unit_header_buffer.g_unit_size * UNIT_GRANULARITY;
      }
      else if (NIBBLE_LOW(unit_header_buffer.type_attribute) ==
               ATTR_MULTI_INST)
      {

         /* Read the multiple instance structure. */
         if (FlashDevRead((BYTE_PTR) & q_size, unit_address, sizeof(WORD)) ==
             HW_ERR_NONE)
         {
            /*
             * If the data attribute is multiple instance unit, return the
             * instance size in bytes as the total data size.
             */
            *data_size_ptr = q_size;
         }
         else
         {
/* E.5.0.656 Begin */
/*            SEM_MTX_POST(SEM_LookupTable); */
/* E.5.0.656 End */
            return ERR_READ;
         }
      }
      else if (NIBBLE_LOW(unit_header_buffer.type_attribute) == ATTR_GRP_TABLE)
      {

#if (INCLUDE_FRAGMENTED_DATA == TRUE)

/* E.5.0.629 Begin */
/*         mof_index = (BYTE)LOOKUP_TABLE_OSFIELD(type,identifier);
*/
         /*
          * IF this identifier is using the FDI_OpenParam structure
          * THEN get the data's total size from FDI_OpenTotalSize
          */
/*         if ((BYTE)mof_index != BYTEMAX)
         {
            SEM_MTX_WAIT(SEM_TotalSize);
            *data_size_ptr = FDI_OpenTotalSize[(BYTE)mof_index];
            SEM_MTX_POST(SEM_TotalSize);
         }
         else
         {
*/         
/* E.5.0.629 End */
            local_read_info.block_addr = block_address;
            local_read_info.identifier = identifier;
            local_read_info.type_attribute = unit_header_buffer.type_attribute;
            /* calculate the unit's address from the unit_offset */
            local_read_info.b_begin_unit_offset = ((FDV_BLOCK_SIZE -
               sizeof(BLOCK_INFO)) -
               TO_BYTES(unit_header_buffer.g_unit_offset_bottom));

            local_read_info.b_grp_table_entry_offset =
               local_read_info.b_begin_unit_offset;
            /*
             * find the total data size by reading all the group and sequence
             * table entries
             */
            if (BKGD_GetTableEntry(&local_read_info,
                                   &index, (BYTE_PTR) & index, &index,
                                  (BYTE_PTR) & index, DWORDMAX,
                                  TO_BYTES(unit_header_buffer.g_unit_size) /
                                  (WORD) sizeof(ENTRY_TABLE)) != HW_ERR_NONE)
            {
/* E.5.0.656 Begin */
/*            SEM_MTX_POST(SEM_LookupTable); */
/* E.5.0.656 End */
               return ERR_SYSTEM;
            }
            *data_size_ptr = local_read_info.b_total_size;
/* E.5.0.629 Begin */
/*         } */
/* E.5.0.629 End */
#else                                  /* !INCLUDE_FRAGMENTED_DATA */
/* E.5.0.656 Begin */
/*            SEM_MTX_POST(SEM_LookupTable); */
/* E.5.0.656 End */
         return ERR_FORMAT;
#endif                                 /* !INCLUDE_FRAGMENTED_DATA */

      }
      else
      {
/* E.5.0.656 Begin */
/*            SEM_MTX_POST(SEM_LookupTable); */
/* E.5.0.656 End */
         return ERR_SYSTEM;
      }

/* E.5.0.656 Begin */
/*            SEM_MTX_POST(SEM_LookupTable); */
/* E.5.0.656 End */
      return ERR_NONE;
   }

/* E.5.0.656 Begin */
/*            SEM_MTX_POST(SEM_LookupTable); */
/* E.5.0.656 End */

   if (hw_status != HW_ERR_EMPTY_LKUP)
   {
      if (hw_status == HW_ERR_PARAM)
         return ERR_PARAM;
      else
         return ERR_SYSTEM;
   }
   return ERR_NONE;
}                                      /* END of GetDataSize */

⌨️ 快捷键说明

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